1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

First commit of MeshAgent for MeshCentral

This commit is contained in:
Ylian Saint-Hilaire
2017-10-12 14:28:03 -07:00
commit 75d86eb4c8
349 changed files with 210459 additions and 0 deletions

5
Debug/ChildModuleTest.js Normal file
View File

@@ -0,0 +1,5 @@
var parent = require('ScriptContainer');
var Wireless = require('Wireless');
Wireless.on('Scan', function (ap) { parent.send(ap.toString()); });
Wireless.Scan();

134
Debug/ClientDigest.js Normal file
View File

@@ -0,0 +1,134 @@
var http = require('http');
var agent = require('MeshAgent');
var server = "";
var req = "";
var gtunnel = "";
var digest = require('http-digest').create("bryan", "roe");
agent.on('Connected', function (connectState)
{
console.log("Connection State = " + connectState.toString());
console.log("Connected: " + this.ServerUrl);
//gtunnel = require('global-tunnel');
//gtunnel.initialize({ host: "proxy.jf.intel.com", port: 911 });
//req = http.get({ uri: "http://www.google.com/", proxy: { host: "proxy.jf.intel.com", port: 911 } }, OnGoogle);
//req = http.request({ protocol: "wss:", hostname: "alt.meshcentral.com", port: 443, method: "GET", path: "/agent.ashx", MeshAgent: agent /* proxy: { host: "proxy.jf.intel.com", port: 911 }*/}, OnResponse);
//req.upgrade = OnWebSocket;
//req.on('error', function (msg) { console.log(msg); });
//req.end();
//digest.clientRequest = http.get("http://127.0.0.1:9093/");
//digest.on('response', function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!");})
digest.http = require('http');
//digest.get("http://127.0.0.1:9093/", function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
//digest.request({ protocol: "http:", method: "GET", host: "127.0.0.1", path: "/", port: 9093 }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); }).end();
var req = digest.request({ MeshAgent: agent, protocol: "wss:", method: "GET", host: "127.0.0.1", path: "/", port: 9093, checkServerIdentity:onVerifyServer }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
req.on('upgrade', function (res, sk, h) { console.log("Upgraded to WebSocket!"); });
req.end();
});
function OnAlt(imsg)
{
console.log("OnAlt, StatusCode = " + imsg.statusCode);
}
function OnGoogle(imsg)
{
console.log("Response Code = " + imsg.statusCode);
}
agent.Ready = function()
{
console.log("Starting Digest Test (Agent Connected)");
//server = http.createServer({ "MeshAgent": agent, "requestCert": true, "checkClientIdentity": onVerifyClient }, OnRequest);
server = http.createServer({ "MeshAgent": agent }, OnRequest);
server.listen(9093);
//req = http.request({ "protocol":"ws:", "hostname": "127.0.0.1", "port": 9093, "method": "GET", "path": "/", "MeshAgent": agent }, OnResponse);
//req.upgrade = OnWebSocket;
//req.end();
}
function OnWebSocket(msg, s, head)
{
console.log("WebSocket connected\n");
console.log(JSON.stringify(msg) + "\n");
console.log(JSON.stringify(s) + "\n");
s.end();
}
function OnResponse(msg)
{
if (msg == null)
{
console.log("Receive Error\n");
return;
}
console.log("Status Code = " + msg.statusCode.toString() + "\n");
}
function onVerifyServer(clientName, certs) {
console.log("Server Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerifyClient(clientName, certs)
{
console.log("Client Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerify(serverName, certs)
{
console.log("ServerName = " + serverName + "\n");
for (var i = 0; i < certs.length;++i)
{
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function OnRequest(req, res)
{
console.log("Received Request for: " + req.url);
if (req.NativeSession.Digest_IsAuthenticated("meshcentral.com") == 0)
{
req.NativeSession.Digest_SendUnauthorized("meshcentral.com", "<html>Oops</html>");
}
else
{
var username = req.NativeSession.Digest_GetUsername();
console.log("Username = " + username + "\n");
if(username == "bryan" && req.NativeSession.Digest_ValidatePassword("roe")==1)
{
console.log("Validated!\n");
if (req.NativeSession.WebSocket_GetDataType() == 0xFF)
{
req.NativeSession.WebSocket_Upgrade();
}
else
{
res.statusCode = 200;
res.statusMessage = "OK";
res.write("<HTML>SUCCESS!</HTML>");
res.end();
}
}
else
{
console.log("Nope!\n");
res.end();
}
}
}

115
Debug/DigestTest.js Normal file
View File

@@ -0,0 +1,115 @@
var http = require('http');
var https = require('https');
var agent = require('MeshAgent');
var server = "";
var req = "";
var db = require('SimpleDataStore').Shared();
var signer = require('SHA256Stream_Signer');
var keys = db.Keys;
Microstack_print("Enumerating Keys...\n");
for (var i = 0; i < keys.length; ++i)
{
Microstack_print("DB Key=> " + keys[i] + "\n");
}
Microstack_print("Done...\n");
Microstack_print("[TestKey] = " + db.Get("TestKey") + "\n");
//db.Put("TestKey", "TestValue");
agent.Ready = function()
{
signer.Create(agent);
signer.OnSignature = OnSignature;
server = http.createServer({ "MeshAgent": agent, "requestCert": true, "checkClientIdentity": onVerifyClient }, OnRequest);
server.listen(9093);
//req = https.get("https://127.0.0.1:443/", OnResponse);
//req = https.request({ "hostname": "127.0.0.1", "method": "GET", "path": "/", "checkServerIdentity": onVerify }, OnResponse)
//req = https.request({ "hostname": "127.0.0.1", "port": 9093, "method": "GET", "path": "/", "MeshAgent": agent }, OnResponse);
req = https.request(https.addWebSocketHeadersToOptions({ "hostname": "127.0.0.1", "port": 443, "method": "GET", "path": "/", "MeshAgent": agent }, 4096, null), OnResponse);
req.upgrade = OnWebSocket;
//req.end();
}
function OnSignature(sig)
{
//var test = Buffer.from(sig.toString('base64'), 'base64');
var test = Buffer.from(sig.toString('hex'), 'hex');
Microstack_print("sig Length: " + sig.length.toString() + " test.length = " + test.length.toString() + "\n");
Microstack_print("Signature (base64) = " + sig.toString('base64') + "\n");
Microstack_print("Signature (hex) = " + sig.toString('hex') + "\n");
}
function OnWebSocket(msg, s, head)
{
//Microstack_print("WebSocket connected\n");
//Microstack_print(JSON.stringify(msg) + "\n");
//Microstack_print(JSON.stringify(s) + "\n");
s.end();
}
function OnResponse(msg)
{
if (msg == null)
{
Microstack_print("Receive Error\n");
return;
}
Microstack_print("Status Code = " + msg.statusCode.toString() + "\n");
msg.pipe(signer);
}
function onVerifyClient(clientName, certs)
{
Microstack_print("Client Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
Microstack_print(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerify(serverName, certs)
{
Microstack_print("ServerName = " + serverName + "\n");
for (var i = 0; i < certs.length;++i)
{
Microstack_print(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function OnRequest(req, res)
{
if (req.NativeSession.Digest_IsAuthenticated("meshcentral.com") == 0)
{
req.NativeSession.Digest_SendUnauthorized("meshcentral.com", "<html>Oops</html>");
}
else
{
var username = req.NativeSession.Digest_GetUsername();
Microstack_print("Username = " + username + "\n");
if(username == "bryan" && req.NativeSession.Digest_ValidatePassword("roe")==1)
{
Microstack_print("Validated!\n");
res.statusCode = 200;
res.statusMessage = "OK";
res.write("<HTML>SUCCESS!</HTML>");
res.end();
}
else
{
Microstack_print("Nope!\n");
res.end();
}
}
}

84
Debug/JavaCore.js Normal file
View File

@@ -0,0 +1,84 @@
//var mesh = require('MeshAgent');
//var tmpBuffer = new Buffer(26);
//mesh.AddCommandHandler_Binary(OnBinaryCommand);
//htons(tmpBuffer, 0, 0x01);
//WriteContextGuid(tmpBuffer, 2, "THISISTHECONTEXT");
//htonl(tmpBuffer, 18, 0x40000000);
//htonl(tmpBuffer, 22, 0x00);
//mesh.InjectCommand(tmpBuffer);
//tmpBuffer = new Buffer(25);
//htons(tmpBuffer, 0, 0x10);
//WriteContextGuid(tmpBuffer, 2, "THISISTHECONTEXT");
//WriteString(tmpBuffer, 18, "bar();")
//mesh.InjectCommand(tmpBuffer);
//function WriteString(buffer, offset, val)
//{
// var i;
// for (i = 0; i < val.length; ++i)
// {
// buffer[offset + i] = val.charCodeAt(i);
// }
// buffer[offset + i] = 0;
//}
//function WriteContextGuid(buffer, offset, contextguid)
//{
// var i;
// for(i=0;i<16;++i)
// {
// if (i >= contextguid.length) {
// buffer[offset + i] = 0;
// }
// else
// {
// buffer[offset + i] = contextguid.charCodeAt(i);
// }
// }
//}
//function OnBinaryCommand(cmd)
//{
// var code = ntohs(cmd, 0);
// if (code == 0x01)
// {
// var context = cmd.slice(2, 16).toString('utf-8');
// var flags = ntohl(cmd, 18);
// var etime = ntohl(cmd, 22);
// if (code != 0xFF)
// {
// Microstack_print("Cmd: " + code.toString() + " Context: " + context + " Flags: " + flags.toString() + " ExecTimeout: " + etime.toString() + "\n");
// }
// }
// return(0);
//}
var mesh = require('MeshAgent');
var container = mesh.CreateScriptContainer(0, ContainerPermissions.DEFAULT);
function OnExit(statusCode)
{
Microstack_print("OnExit: " + statusCode.toString() + "\n");
}
function OnError(msg)
{
Microstack_print("OnError: " + msg + "\n");
}
container.Exit = OnExit;
container.Error = OnError;
//container.ExecuteString("foo();");
container.ExecuteString("var agent = require('MeshAgent').db.Get(\"bryan\");", function (status, msg)
{
Microstack_print("Completed First Execution\n");
container.ExecuteString("foo();");
});
//container.ExecuteString("require('MeshAgent').db.Get(\"bryan\");");
//container.ExecuteString("var x = 2+2;");

15
Debug/ModuleTest.js Normal file
View File

@@ -0,0 +1,15 @@
var WiFiScanner = require('WiFiScanner');
var scanner = new WiFiScanner();
scanner.on('accessPoint', function (ap) { console.log("[" + ap.bssid + "] (" + ap.lq + ") " + ap.ssid); });
if (scanner.hasWireless())
{
console.log("This Computer has wireless");
scanner.Scan();
}
else
{
console.log("This Computer DOES NOT have wireless");
}

View File

@@ -0,0 +1,19 @@
var nm = require('NetworkMonitor');
nm.on('change', function () { console.log("Change detected..."); });
nm.on('add', function (addr) { console.log("Address (" + addr + ") added"); });
nm.on('remove', function (addr) { console.log("Address (" + addr + ") removed"); });
console.log("Started Test");
function OnChange()
{
var interfaces = require('os').networkInterfaces();
for(var key in interfaces)
{
for (var i in interfaces[key])
{
console.log("Address ==> " + interfaces[key][i].address);
console.log(" status ==> " + interfaces[key][i].status);
}
}
}

111
Debug/WebRTC_Test.html Normal file
View File

@@ -0,0 +1,111 @@
<html>
<head>
<title>WebRTC Test Application</title>
</head>
<body onload="start()">
<span id="statustext"></span>
<script type="text/javascript">
var configuration = { "iceServers": [] };
var connection = null;
var datachannel = null;
var currentanswer = null;
var wsocket = null;
var decoder = new TextDecoder('utf-8');
var sdp = null;
function start()
{
debug("Connecting relay, for signaling channel...");
wsocket = new WebSocket("wss://alt.meshcentral.com:443/meshrelay.ashx?id='test123'");
wsocket.binaryType = "arraybuffer";
wsocket.onopen = function (evt) { debug("Web Socket Connection established..."); }
wsocket.onmessage = function (evt)
{
if (evt.data[0] == 'c')
{
debug("Tunnel Established...");
}
else
{
var cmd = JSON.parse(decoder.decode(new Uint8Array(evt.data)));
if(cmd.cmd == 'offer')
{
debug("Received WebRTC Offer...");
startWebRTC();
var ax = null;
if (typeof mozRTCSessionDescription !== 'undefined') { ax = new mozRTCSessionDescription({ type: "offer", sdp: cmd.data }) } else { ax = new RTCSessionDescription({ type: "offer", sdp: cmd.data }) }
connection.setRemoteDescription(ax, onSetRemoteDescriptionDone, onError);
}
}
}
}
function onSetRemoteDescriptionDone()
{
connection.createAnswer(onAnswerDone, onError);
}
function onAnswerDone(answer)
{
//wsocket.send(JSON.stringify({ cmd: 'offer', data: answer.sdp }));
sdp = answer.sdp;
connection.setLocalDescription(answer, onSetLocalDescriptionDone, onError);
}
function startWebRTC()
{
if (connection != null) { debug("Error!"); return; }
if (typeof mozRTCPeerConnection !== 'undefined') { connection = new mozRTCPeerConnection(configuration); }
else if (typeof RTCPeerConnection !== 'undefined') { connection = new RTCPeerConnection(configuration); }
else if (typeof webkitRTCPeerConnection !== 'undefined') { connection = new webkitRTCPeerConnection(configuration); }
else return false;
connection.ondatachannel = onDataChannel
connection.onicecandidate = onIceCandidate;
}
function onDataChannel(event)
{
debug("Data Channel ("+ event.channel.label + ") connected");
datachannel = event.channel;
datachannel.binaryType = "arraybuffer";
datachannel.onmessage = function (msg)
{
try
{
datachannel.send(msg.data.byteLength.toString());
}
catch(e)
{
debug(e.toString());
debug(msg.data.toString());
}
};
}
function onIceCandidate(e)
{
if (e.candidate == null) {
if (sdp == null) { debug('error'); return; }
wsocket.send(JSON.stringify({ cmd: 'offer', data: sdp }));
}
else
{
sdp += ("a=" + e.candidate.candidate + "\r\n");
}
}
function onSetLocalDescriptionDone() { }
function onError(e) { if (e.message) debug(e.message); else debug(e); }
function debug(msg) { document.getElementById("statustext").innerHTML += (msg + "\r\n"); }
</script>
</body>
</html>

183
Debug/WebRTC_Test.js Normal file
View File

@@ -0,0 +1,183 @@
var mesh;
var http = require('http');
var relayId = null;
var req;
var proxy;
var relayHost = null;
var relayPort;
var rtc = require('ILibWebRTC');
var peerConnection;
var signalingChannel;
var dc;
var webServer = null;
var processMgr;
var p;
for (var i = 1; i < process.argv.length; ++i)
{
if(process.argv[i] == 'relayId')
{
relayId = process.argv[i + 1];
++i;
}
else if (process.argv[i] == 'proxy')
{
console.log("Using Proxy: " + process.argv[i + 1] + ":" + parseInt(process.argv[i + 2]));
proxy = require('global-tunnel');
try
{
proxy.initialize({ host: process.argv[i + 1], port: parseInt(process.argv[i + 2]) });
}
catch (e)
{
console.log("Unable to bind proxy: " + e);
}
i += 2;
}
else if(process.argv[i] == 'relay')
{
relayHost = process.argv[i + 1];
relayPort = parseInt(argv[i + 2]);
i += 2;
}
else if(process.argv[i] == 'browser')
{
console.log("Local Web Server started on port 8585...");
webServer = http.createServer(OnLocalWebRequest);
webServer.listen(8585);
}
}
try
{
mesh = require('MeshAgent');
mesh.AddConnectHandler(OnMeshConnected)
}
catch(e)
{
mesh = null;
}
if (mesh == null && webServer == null)
{
console.log("Running as Standalone Mode");
var options = { host: relayHost, port: relayPort, path: "/meshrelay.ashx?id='" + relayId + "'", protocol: "wss:" };
req = http.request(options);
req.upgrade = OnTunnelWebSocket;
}
if (mesh == null && webServer != null)
{
processMgr = require('ILibProcessPipe');
p = processMgr.CreateProcess("c:\\windows\\system32\\cmd.exe", "/c", "start", "http://localhost:8585/start.html");
}
function OnLocalWebRequest(request, response)
{
if(request.method == 'GET' && request.url == '/start.html')
{
var fs = require('fs');
try
{
var stream = fs.createReadStream('WebRTC_Test.html');
response.statusCode = 200;
response.statusMessage = "OK";
stream.pipe(response);
}
catch(e)
{
response.statusCode = 404;
response.statusMessage = "Not Found";
response.end();
}
}
else
{
response.statusCode = 404;
response.statusMessage = "Not Found";
response.end();
}
}
function OnMeshConnected()
{
console.log("Mesh Agent Connected: " + mesh.ConnectedServer);
console.log("Attempting to create WebRTC Control Channel using TunnelID: " + relayId);
var options = http.parseUri(mesh.ConnectedServer);
options.path = "/meshrelay.ashx?id='" + relayId + "'";
req = http.request(options);
req.upgrade = OnTunnelWebSocket;
}
function OnTunnelWebSocket(response, sckt, head)
{
console.log("Websocket Connection to RelayServer established");
signalingChannel = sckt;
sckt.on('data', OnTunnelData);
sckt.on('end', function () { console.log("Relay connection closed"); });
}
function OnWebRTC_Connected()
{
console.log("WebRTC Session Established");
if(mesh != null)
{
// Let create a data channel
this.dc = this.createDataChannel("remoteDesktop", OnKVMChannel)
this.tempTimeout = setTimeout(function (dc) { console.log("sending: 'test'"); dc.write("test"); }, 10000, this.dc);
}
}
function OnKVMChannel()
{
console.log("Successfully established Data Channel to test Data throughput");
dc = this;
dc.kvm = mesh.getRemoteDesktopStream();
dc.on('data', function (buffer) { console.log("Peer Received: " + buffer.toString() + " bytes"); });
dc.on('end', function () { this.kvm.end(); console.log("Closing KVM Session"); });
dc.kvm.pipe(dc);
}
function OnWebRTC_DataChannel(dataChannel)
{
console.log("Data Channel (" + dataChannel.name + ") was created");
dc = dataChannel;
dc.on('data', function (buffer) { console.log("Received: " + buffer.length + " bytes"); dc.write(buffer.length.toString());});
}
function OnTunnelData(buffer)
{
if (buffer == 'c')
{
console.log("Tunnel Established");
peerConnection = rtc.createConnection();
peerConnection.on('connected', OnWebRTC_Connected);
peerConnection.on('dataChannel', OnWebRTC_DataChannel);
if(mesh!=null)
{
console.log("Generating WebRTC Offer...");
this.write({ cmd: "offer", data: peerConnection.generateOffer() });
}
}
else
{
ProcessCommand(JSON.parse(buffer.toString()));
}
}
function ProcessCommand(cmd)
{
console.log("Received Command: " + cmd.cmd);
if(cmd.cmd == 'offer')
{
console.log("setting offer...");
console.log(cmd.data);
var counter = peerConnection.setOffer(cmd.data);
if(mesh == null)
{
signalingChannel.write({ cmd: "offer", data: counter });
}
}
if(cmd.cmd == 'candidate')
{
console.log("Received Candidate: " + cmd.data);
}
}

266
Debug/WiFiScanner.js Normal file
View File

@@ -0,0 +1,266 @@
var MemoryStream = require('MemoryStream');
var WindowsWireless = new Buffer([
0x0A, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x5F, 0x53, 0x63, 0x61, 0x6E, 0x28, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x77, 0x6C, 0x61, 0x6E,
0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x45,
0x6E, 0x75, 0x6D, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x77, 0x6C,
0x61, 0x6E, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x63, 0x6F, 0x75, 0x6E, 0x74, 0x20, 0x3D, 0x20,
0x77, 0x6C, 0x61, 0x6E, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20,
0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x20, 0x3D, 0x20, 0x77, 0x6C, 0x61, 0x6E, 0x49, 0x6E, 0x74, 0x65,
0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x2C, 0x20, 0x35, 0x33, 0x32, 0x29, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x61, 0x6D, 0x65, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x31, 0x36, 0x2C, 0x20, 0x35, 0x31, 0x32,
0x29, 0x2E, 0x41, 0x6E, 0x73, 0x69, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3B, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x20, 0x28, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x32, 0x38, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61,
0x6C, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x30, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x4E, 0x4F, 0x54, 0x20, 0x52, 0x45, 0x41, 0x44, 0x59, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x31, 0x3A, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54, 0x45, 0x44, 0x22, 0x3B, 0x0A,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20,
0x32, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x41, 0x44, 0x2D, 0x48, 0x4F, 0x43, 0x22,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73,
0x65, 0x20, 0x33, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x44, 0x49, 0x53, 0x43, 0x4F,
0x4E, 0x4E, 0x45, 0x43, 0x54, 0x49, 0x4E, 0x47, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x34, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65,
0x20, 0x3D, 0x20, 0x22, 0x44, 0x49, 0x53, 0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54, 0x45, 0x44, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62,
0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x35, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x41, 0x53, 0x53, 0x4F, 0x43, 0x49, 0x41, 0x54, 0x49, 0x4E, 0x47, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x36, 0x3A, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x44, 0x49, 0x53, 0x43, 0x4F, 0x56, 0x45, 0x52, 0x49, 0x4E, 0x47, 0x22, 0x3B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65,
0x20, 0x37, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x41, 0x55, 0x54, 0x48, 0x45, 0x4E,
0x54, 0x49, 0x43, 0x41, 0x54, 0x49, 0x4E, 0x47, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6C, 0x74, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74,
0x65, 0x20, 0x3D, 0x20, 0x22, 0x55, 0x4E, 0x4B, 0x4E, 0x4F, 0x57, 0x4E, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65,
0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x31, 0x36, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E,
0x57, 0x6C, 0x61, 0x6E, 0x53, 0x63, 0x61, 0x6E, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x2C, 0x20, 0x30, 0x2C, 0x20,
0x30, 0x2C, 0x20, 0x30, 0x29, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E,
0x20, 0x28, 0x74, 0x72, 0x75, 0x65, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6C, 0x73, 0x65, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x66, 0x61, 0x6C, 0x73, 0x65, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x7D, 0x0A, 0x0A, 0x66,
0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x28, 0x5F, 0x73, 0x73, 0x69, 0x64, 0x2C, 0x20, 0x5F, 0x62, 0x73, 0x73, 0x69,
0x64, 0x2C, 0x20, 0x5F, 0x72, 0x73, 0x73, 0x69, 0x2C, 0x20, 0x5F, 0x6C, 0x71, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D,
0x20, 0x5F, 0x73, 0x73, 0x69, 0x64, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x62, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x5F, 0x62, 0x73, 0x73, 0x69, 0x64, 0x3B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x72, 0x73, 0x73, 0x69, 0x20, 0x3D, 0x20, 0x5F, 0x72, 0x73, 0x73, 0x69, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73,
0x2E, 0x6C, 0x71, 0x20, 0x3D, 0x20, 0x5F, 0x6C, 0x71, 0x3B, 0x0A, 0x7D, 0x0A, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x2E, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x74, 0x79,
0x70, 0x65, 0x2E, 0x74, 0x6F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x3D, 0x20, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x28, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x72,
0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x73, 0x73, 0x69, 0x64, 0x20, 0x2B, 0x20, 0x22, 0x20, 0x5B, 0x22, 0x20, 0x2B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x62,
0x73, 0x73, 0x69, 0x64, 0x20, 0x2B, 0x20, 0x22, 0x5D, 0x3A, 0x20, 0x22, 0x20, 0x2B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x6C, 0x71, 0x29, 0x3B, 0x0A, 0x7D, 0x0A, 0x0A, 0x66, 0x75, 0x6E, 0x63,
0x74, 0x69, 0x6F, 0x6E, 0x20, 0x4F, 0x6E, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x79, 0x28, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x29, 0x0A,
0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x3D, 0x20, 0x4E,
0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x43, 0x6F, 0x64, 0x65, 0x20, 0x3D, 0x20, 0x4E, 0x6F, 0x74, 0x69,
0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x34, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x64, 0x61, 0x74, 0x61, 0x47, 0x75, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74,
0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x2C, 0x20, 0x31, 0x36, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x28, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69,
0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x26, 0x20, 0x30, 0x58, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x29, 0x20, 0x26, 0x26, 0x20, 0x28, 0x4E,
0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x43, 0x6F, 0x64, 0x65, 0x20, 0x3D, 0x3D, 0x20, 0x37, 0x29, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x62, 0x73, 0x73, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68,
0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20,
0x72, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x47, 0x65, 0x74, 0x42,
0x53, 0x53, 0x4C, 0x69, 0x73, 0x74, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x64, 0x61, 0x74, 0x61, 0x47,
0x75, 0x69, 0x64, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x33, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x62, 0x73, 0x73, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69,
0x66, 0x20, 0x28, 0x72, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x74, 0x6F, 0x74, 0x61, 0x6C, 0x53, 0x69, 0x7A, 0x65, 0x20, 0x3D, 0x20, 0x62, 0x73, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28,
0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76,
0x61, 0x72, 0x20, 0x6E, 0x75, 0x6D, 0x49, 0x74, 0x65, 0x6D, 0x73, 0x20, 0x3D, 0x20, 0x62, 0x73, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28,
0x34, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6F, 0x72, 0x20, 0x28, 0x69, 0x20, 0x3D, 0x20,
0x30, 0x3B, 0x20, 0x69, 0x20, 0x3C, 0x20, 0x6E, 0x75, 0x6D, 0x49, 0x74, 0x65, 0x6D, 0x73, 0x3B, 0x20, 0x2B, 0x2B, 0x69, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x74, 0x65, 0x6D, 0x20, 0x3D, 0x20, 0x62,
0x73, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x20, 0x2B, 0x20, 0x28, 0x33, 0x36, 0x30, 0x20, 0x2A, 0x20, 0x69, 0x29, 0x2C, 0x20,
0x33, 0x36, 0x30, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D,
0x20, 0x69, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x34, 0x2C, 0x20, 0x33, 0x32, 0x29, 0x2E, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x2E, 0x74, 0x72, 0x69, 0x6D, 0x28, 0x29,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x62, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x69, 0x74,
0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x34, 0x30, 0x2C, 0x20, 0x36, 0x29, 0x2E, 0x48, 0x65, 0x78, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x32, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x72, 0x73, 0x73, 0x69, 0x20, 0x3D, 0x20, 0x69, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65,
0x66, 0x28, 0x35, 0x36, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61,
0x72, 0x20, 0x6C, 0x71, 0x20, 0x3D, 0x20, 0x69, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x36, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x65, 0x6D, 0x69, 0x74, 0x28,
0x27, 0x53, 0x63, 0x61, 0x6E, 0x27, 0x2C, 0x20, 0x6E, 0x65, 0x77, 0x20, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x28, 0x73, 0x73, 0x69, 0x64, 0x2C, 0x20, 0x62, 0x73,
0x73, 0x69, 0x64, 0x2C, 0x20, 0x72, 0x73, 0x73, 0x69, 0x2C, 0x20, 0x6C, 0x71, 0x29, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x7D, 0x0A, 0x0A, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x57, 0x69, 0x72, 0x65,
0x6C, 0x65, 0x73, 0x73, 0x28, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x65, 0x6D, 0x69, 0x74, 0x74, 0x65, 0x72, 0x55, 0x74, 0x69, 0x6C, 0x73, 0x20, 0x3D, 0x20,
0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x65, 0x76, 0x65, 0x6E, 0x74, 0x73, 0x27, 0x29, 0x2E, 0x69, 0x6E, 0x68, 0x65, 0x72, 0x69, 0x74, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x29,
0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x20, 0x3D, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x5F,
0x47, 0x65, 0x6E, 0x65, 0x72, 0x69, 0x63, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x27, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76,
0x65, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x50, 0x72, 0x6F,
0x78, 0x79, 0x28, 0x22, 0x77, 0x6C, 0x61, 0x6E, 0x61, 0x70, 0x69, 0x2E, 0x64, 0x6C, 0x6C, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69,
0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C, 0x61, 0x6E, 0x4F, 0x70, 0x65, 0x6E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x22,
0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28,
0x22, 0x57, 0x6C, 0x61, 0x6E, 0x47, 0x65, 0x74, 0x4E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x42, 0x73, 0x73, 0x4C, 0x69, 0x73, 0x74, 0x22, 0x2C, 0x20, 0x22, 0x47, 0x65, 0x74, 0x42, 0x53, 0x53,
0x4C, 0x69, 0x73, 0x74, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65,
0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C, 0x61, 0x6E, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x22, 0x29,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22,
0x57, 0x6C, 0x61, 0x6E, 0x45, 0x6E, 0x75, 0x6D, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E,
0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C, 0x61, 0x6E, 0x53, 0x63, 0x61, 0x6E, 0x22, 0x29, 0x3B, 0x0A,
0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C,
0x61, 0x6E, 0x51, 0x75, 0x65, 0x72, 0x79, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x6E, 0x65, 0x67,
0x6F, 0x74, 0x69, 0x61, 0x74, 0x65, 0x64, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69,
0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x68, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C,
0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69,
0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x4F, 0x70, 0x65, 0x6E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x28, 0x32, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x6E, 0x65, 0x67, 0x6F, 0x74, 0x69, 0x61, 0x74,
0x65, 0x64, 0x2C, 0x20, 0x68, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x20, 0x3D, 0x20, 0x68, 0x2E, 0x56, 0x61, 0x6C, 0x3B,
0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46, 0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54, 0x20,
0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x61, 0x6C, 0x6C, 0x62, 0x61, 0x63, 0x6B, 0x50, 0x72, 0x6F,
0x78, 0x79, 0x28, 0x4F, 0x6E, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x79, 0x2C, 0x20, 0x32, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46,
0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x50, 0x72, 0x65, 0x76, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E,
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x20,
0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69,
0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x30, 0x58, 0x30, 0x30, 0x30, 0x30, 0x46, 0x46, 0x46, 0x46, 0x2C, 0x20,
0x30, 0x2C, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46, 0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54, 0x2E, 0x43, 0x61, 0x6C,
0x6C, 0x62, 0x61, 0x63, 0x6B, 0x2C, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46, 0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54,
0x2E, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x50, 0x72, 0x65, 0x76, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6D, 0x69,
0x74, 0x74, 0x65, 0x72, 0x55, 0x74, 0x69, 0x6C, 0x73, 0x2E, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6E, 0x74, 0x28, 0x27, 0x53, 0x63, 0x61, 0x6E, 0x27, 0x29, 0x3B, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x65, 0x6D, 0x69, 0x74, 0x74, 0x65, 0x72, 0x55, 0x74, 0x69, 0x6C, 0x73, 0x2E, 0x61, 0x64, 0x64, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x27, 0x53, 0x63, 0x61, 0x6E, 0x27,
0x2C, 0x20, 0x5F, 0x53, 0x63, 0x61, 0x6E, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x47, 0x65, 0x74, 0x43, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, 0x65, 0x64,
0x4E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x20, 0x3D, 0x20, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x28, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61,
0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73,
0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x45, 0x6E, 0x75, 0x6D, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E,
0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x63, 0x6F, 0x75, 0x6E, 0x74, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E,
0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44,
0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x2C, 0x20, 0x35, 0x33, 0x32, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x61, 0x6D, 0x65, 0x20,
0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x31, 0x36, 0x2C, 0x20, 0x35, 0x31, 0x32, 0x29, 0x2E, 0x41, 0x6E, 0x73, 0x69, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65,
0x66, 0x28, 0x35, 0x32, 0x38, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x49, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x28, 0x69, 0x6E,
0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x32, 0x38, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x49, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x20, 0x3D, 0x3D, 0x20, 0x31, 0x29, 0x20, 0x2F, 0x2F,
0x20, 0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54, 0x45, 0x44, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x76, 0x61, 0x72, 0x20, 0x64, 0x61, 0x74, 0x61, 0x53, 0x69, 0x7A, 0x65, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65,
0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x70, 0x44,
0x61, 0x74, 0x61, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72,
0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x20, 0x3D, 0x20,
0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66,
0x28, 0x30, 0x2C, 0x20, 0x31, 0x36, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x72, 0x65, 0x74, 0x56, 0x61, 0x6C, 0x20,
0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x51, 0x75, 0x65, 0x72, 0x79, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65,
0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x2C, 0x20, 0x37, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x64, 0x61, 0x74, 0x61, 0x53,
0x69, 0x7A, 0x65, 0x2C, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2C, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x72, 0x65, 0x74, 0x56, 0x61, 0x6C, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x61, 0x73, 0x73, 0x6F, 0x63, 0x69, 0x61, 0x74, 0x65,
0x64, 0x53, 0x53, 0x49, 0x44, 0x20, 0x3D, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x32, 0x34, 0x2C,
0x20, 0x33, 0x32, 0x29, 0x2E, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72,
0x20, 0x62, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x36, 0x30,
0x2C, 0x20, 0x36, 0x29, 0x2E, 0x48, 0x65, 0x78, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x76, 0x61, 0x72, 0x20, 0x6C, 0x71, 0x20, 0x3D, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x37, 0x36,
0x2C, 0x20, 0x34, 0x29, 0x2E, 0x49, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65,
0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x6E, 0x65, 0x77, 0x20, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x28, 0x61, 0x73, 0x73, 0x6F, 0x63, 0x69, 0x61, 0x74, 0x65, 0x64,
0x53, 0x53, 0x49, 0x44, 0x2C, 0x20, 0x62, 0x73, 0x73, 0x69, 0x64, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x6C, 0x71, 0x29, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x72, 0x6F, 0x77, 0x20, 0x28, 0x22, 0x47, 0x65,
0x74, 0x43, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, 0x65, 0x64, 0x4E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x73, 0x3A, 0x20, 0x46, 0x41, 0x49, 0x4C, 0x45, 0x44, 0x20, 0x28, 0x6E, 0x6F, 0x74, 0x20,
0x61, 0x73, 0x73, 0x6F, 0x63, 0x69, 0x61, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x61, 0x20, 0x6E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x29, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x7D, 0x3B, 0x0A, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x74, 0x68, 0x69, 0x73, 0x29, 0x3B, 0x0A, 0x7D, 0x0A, 0x0A, 0x6D, 0x6F, 0x64, 0x75, 0x6C,
0x65, 0x2E, 0x65, 0x78, 0x70, 0x6F, 0x72, 0x74, 0x73, 0x20, 0x3D, 0x20, 0x6E, 0x65, 0x77, 0x20, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x28, 0x29, 0x3B, 0x0A]);
var WindowsChildScript = new Buffer([
0x76, 0x61, 0x72, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x20, 0x3D, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x43, 0x6F, 0x6E, 0x74,
0x61, 0x69, 0x6E, 0x65, 0x72, 0x27, 0x29, 0x3B, 0x0D, 0x0A, 0x76, 0x61, 0x72, 0x20, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x20, 0x3D, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65,
0x28, 0x27, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x27, 0x29, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x2E, 0x6F, 0x6E, 0x28, 0x27, 0x53, 0x63,
0x61, 0x6E, 0x27, 0x2C, 0x20, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x28, 0x61, 0x70, 0x29, 0x20, 0x7B, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x73, 0x65, 0x6E, 0x64,
0x28, 0x61, 0x70, 0x29, 0x3B, 0x20, 0x7D, 0x29, 0x3B, 0x0D, 0x0A, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x2E, 0x53, 0x63, 0x61, 0x6E, 0x28, 0x29, 0x3B, 0x0D, 0x0A]);
function AccessPoint(_ssid, _bssid, _lq)
{
this.ssid = _ssid;
this.bssid = _bssid;
this.lq = _lq;
}
AccessPoint.prototype.toString = function ()
{
return (this.ssid + " [" + this.bssid + "]: " + this.lq);
}
function WiFiScanner()
{
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('accessPoint');
this.hasWireless = function ()
{
var retVal = false;
var interfaces = require('os').networkInterfaces();
for (var name in interfaces)
{
if (interfaces[name][0].type == 'wireless') { retVal = true; break; }
}
return (retVal);
};
this.Scan = function ()
{
if (process.platform == 'win32')
{
this.master = require('ScriptContainer').Create(15, ContainerPermissions.DEFAULT);
this.master.parent = this;
this.master.on('data', function (j) { this.parent.emit('accessPoint', new AccessPoint(j.ssid, j.bssid, j.lq)); });
this.master.addModule('Wireless', WindowsWireless.toString());
this.master.ExecuteString(WindowsChildScript.toString());
}
else if (process.platform == 'linux')
{
// Need to get the wireless interface name
var interfaces = require('os').networkInterfaces();
var wlan = null;
for (var i in interfaces)
{
if (interfaces[i][0].type == 'wireless')
{
wlan = i;
break;
}
}
if (wlan != null)
{
this.child = require('ILibProcessPipe').CreateProcess("/sbin/iwlist", "iwlist", wlan, "scan");
this.child.parent = this;
this.child.ms = new MemoryStream();
this.child.ms.parent = this.child;
this.child.on('data', function (buffer) { this.ms.write(buffer); });
this.child.on('end', function () { this.ms.end(); });
this.child.ms.on('end', function ()
{
var str = this.buffer.toString();
tokens = str.split(' - Address: ');
for (var block in tokens)
{
if (block == 0) continue;
var ln = tokens[block].split('\n');
var _bssid = ln[0];
var _lq;
var _ssid;
for (var lnblock in ln)
{
lnblock = ln[lnblock].trim();
lnblock = lnblock.trim();
if (lnblock.startsWith('ESSID:'))
{
_ssid = lnblock.slice(7, lnblock.length - 1);
if (_ssid == '<hidden>') { _ssid = ''; }
}
if (lnblock.startsWith('Signal level='))
{
_lq = lnblock.slice(13,lnblock.length-4);
}
}
this.parent.parent.emit('accessPoint', new AccessPoint(_ssid, _bssid, _lq));
}
});
}
}
}
}
module.exports = WiFiScanner;

157
Debug/WirelessTest.js Normal file
View File

@@ -0,0 +1,157 @@
function _Scan()
{
var wlanInterfaces = this.Marshal.CreatePointer();
this.Native.WlanEnumInterfaces(this.Handle, 0, wlanInterfaces);
var count = wlanInterfaces.Deref().Deref(0, 4).Val;
var info = wlanInterfaces.Deref().Deref(8, 532);
var iname = info.Deref(16, 512).AnsiString;
var istate;
switch (info.Deref(528, 4).Val)
{
case 0:
istate = "NOT READY";
break;
case 1:
istate = "CONNECTED";
break;
case 2:
istate = "AD-HOC";
break;
case 3:
istate = "DISCONNECTING";
break;
case 4:
istate = "DISCONNECTED";
break;
case 5:
istate = "ASSOCIATING";
break;
case 6:
istate = "DISCOVERING";
break;
case 7:
istate = "AUTHENTICATING";
break;
default:
istate = "UNKNOWN";
break;
}
var iguid = info.Deref(0, 16);
if (this.Native.WlanScan(this.Handle, iguid, 0, 0, 0) == 0)
{
return (true);
}
else
{
return (false);
}
}
function AccessPoint(_ssid, _bssid, _rssi, _lq)
{
this.ssid = _ssid;
this.bssid = _bssid;
this.rssi = _rssi;
this.lq = _lq;
}
AccessPoint.prototype.toString = function()
{
return (this.ssid + " [" + this.bssid + "]: " + this.lq);
}
function OnNotify(NotificationData)
{
var NotificationSource = NotificationData.Deref(0, 4).Val;
var NotificationCode = NotificationData.Deref(4, 4).Val;
var dataGuid = NotificationData.Deref(8, 16);
if ((NotificationSource & 0X00000008) && (NotificationCode == 7))
{
var bss = this.Parent.Marshal.CreatePointer();
var result = this.Parent.Native.GetBSSList(this.Parent.Handle, dataGuid, 0, 3, 0, 0, bss);
if (result == 0)
{
var totalSize = bss.Deref().Deref(0, 4).Val;
var numItems = bss.Deref().Deref(4, 4).Val;
for (i = 0; i < numItems; ++i)
{
var item = bss.Deref().Deref(8 + (360 * i), 360);
var ssid = item.Deref(4, 32).String.trim();
var bssid = item.Deref(40, 6).HexString2;
var rssi = item.Deref(56, 4).Val;
var lq = item.Deref(60, 4).Val;
this.Parent.emit('Scan', new AccessPoint(ssid, bssid, rssi, lq));
}
}
}
}
function Wireless()
{
var emitterUtils = require('events').inherits(this);
this.Marshal = require('_GenericMarshal');
this.Native = this.Marshal.CreateNativeProxy("wlanapi.dll");
this.Native.CreateMethod("WlanOpenHandle");
this.Native.CreateMethod("WlanGetNetworkBssList", "GetBSSList");
this.Native.CreateMethod("WlanRegisterNotification");
this.Native.CreateMethod("WlanEnumInterfaces");
this.Native.CreateMethod("WlanScan");
this.Native.CreateMethod("WlanQueryInterface");
var negotiated = this.Marshal.CreatePointer();
var h = this.Marshal.CreatePointer();
this.Native.WlanOpenHandle(2, 0, negotiated, h);
this.Handle = h.Val;
this._NOTIFY_PROXY_OBJECT = this.Marshal.CreateCallbackProxy(OnNotify, 2);
this._NOTIFY_PROXY_OBJECT.Parent = this;
var PrevSource = this.Marshal.CreatePointer();
var result = this.Native.WlanRegisterNotification(this.Handle, 0X0000FFFF, 0, this._NOTIFY_PROXY_OBJECT.Callback, this._NOTIFY_PROXY_OBJECT.State, 0, PrevSource);
emitterUtils.createEvent('Scan');
emitterUtils.addMethod('Scan', _Scan);
this.GetConnectedNetwork = function ()
{
var interfaces = this.Marshal.CreatePointer();
this.Native.WlanEnumInterfaces(this.Handle, 0, interfaces);
var count = interfaces.Deref().Deref(0, 4).Val;
var info = interfaces.Deref().Deref(8, 532);
var iname = info.Deref(16, 512).AnsiString;
var istate = info.Deref(528, 4).IntVal;
if(info.Deref(528, 4).IntVal == 1) // CONNECTED
{
var dataSize = this.Marshal.CreatePointer();
var pData = this.Marshal.CreatePointer();
var valueType = this.Marshal.CreatePointer();
var iguid = info.Deref(0, 16);
var retVal = this.Native.WlanQueryInterface(this.Handle, iguid, 7, 0, dataSize, pData, valueType);
if (retVal == 0)
{
var associatedSSID = pData.Deref().Deref(524, 32).String;
var bssid = pData.Deref().Deref(560, 6).HexString;
var lq = pData.Deref().Deref(576, 4).IntVal;
return (new AccessPoint(associatedSSID, bssid, 0, lq));
}
}
throw ("GetConnectedNetworks: FAILED (not associated to a network)");
};
return (this);
}
module.exports = new Wireless();

88
Debug/dgramtest.js Normal file
View File

@@ -0,0 +1,88 @@
var dgram = require('dgram');
var os = require('os');
var interfaces = os.networkInterfaces();
var broadcastSockets = {};
var multicastSockets = {};
var httpHeaders = require('http-headers');
for (var adapter in interfaces)
{
if (interfaces.hasOwnProperty(adapter))
{
for (var i = 0 ; i < interfaces[adapter].length; ++i)
{
var addr = interfaces[adapter][i];
multicastSockets[i] = dgram.createSocket({ type: (addr.family == "IPv4" ? "udp4" : "udp6") });
//multicastSockets[i].bind({ address: addr.address, port:1900, exclusive:false});
multicastSockets[i].bind({ address: addr.address, exclusive: false });
if(addr.family == "IPv4")
{
//multicastSockets[i].addMembership("239.255.255.250");
//multicastSockets[i].setMulticastLoopback(true);
multicastSockets[i].once('message', OnMulticastMessage);
multicastSockets[i].send("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nST: upnp:rootdevice\r\nMAN: \"ssdp:discover\"\r\nMX: 4\r\nContent-Length: 0\r\n\r\n", 1900, "239.255.255.250");
}
}
}
}
function OnMulticastMessage(msg, rinfo)
{
console.log("Received " + rinfo.size + " bytes from " + rinfo.address + ":" + rinfo.port);
var packet = httpHeaders(msg);
if (packet.hasOwnProperty('statusCode'))
{
console.log("Status (" + packet.statusCode + ") " + packet.statusMessage);
}
else
{
console.log(packet.method + " " + packet.url);
}
for (var header in packet.headers) {
console.log(" " + header + ":" + packet.headers[header]);
}
}
function SendWakeOnLan()
{
var magic = new Buffer(102);
for (var x = 0; x < 6; ++x)
{
magic[x] = 0xFF;
}
for (var x = 1; x <= 16; ++x) {
magic[(x * 6)] = 0xB8;
magic[(x * 6) + 1] = 0xAE;
magic[(x * 6) + 2] = 0xED;
magic[(x * 6) + 3] = 0x74;
magic[(x * 6) + 4] = 0xAB;
magic[(x * 6) + 5] = 0xC3;
}
for (var adapter in interfaces) {
if (interfaces.hasOwnProperty(adapter)) {
console.log(adapter + " => ");
for (var i = 0 ; i < interfaces[adapter].length; ++i) {
var addr = interfaces[adapter][i];
console.log(" " + addr.family + " => " + addr.address + " [" + addr.mac + "]");
if (addr.hasOwnProperty('netmask')) { console.log(" Netmask = " + addr.netmask); }
broadcastSockets[i] = dgram.createSocket({ type: (addr.family == "IPv4" ? "udp4" : "udp6") });
broadcastSockets[i].bind({ address: addr.address });
broadcastSockets[i].setBroadcast(true);
if (addr.family == "IPv4") {
broadcastSockets[i].send(magic, 7, "255.255.255.255");
}
}
}
}
}

38
Debug/linuxwifi.js Normal file
View File

@@ -0,0 +1,38 @@
var manager = require('ILibProcessPipe');
var child = manager.CreateProcess("/sbin/iwlist", "iwlist", "wlan0", "scan");
var MemoryStream = require('MemoryStream');
var ms = new MemoryStream();
ms.on('end', function ()
{
var str = this.buffer.toString();
tokens = str.split(' - Address: ');
for (var block in tokens)
{
var ln = tokens[block].split('\n');
console.log("MAC Address = " + ln[0]);
for(var lnblock in ln)
{
lnblock = ln[lnblock].trim();
lnblock = lnblock.trim();
if(lnblock.startsWith('ESSID:'))
{
console.log("SSID = " + lnblock.slice(6));
}
if(lnblock.startsWith('Signal level='))
{
console.log("Signal Strength = " + lnblock.slice(13));
}
}
console.log("");
}
});
console.log("starting...");
child.on('data', function (buffer) { ms.write(buffer); });
child.on('end', function () { ms.end(); });
//child.write("iwlist wlan0 scan\n");

113
Debug/tunnel.js Normal file
View File

@@ -0,0 +1,113 @@
var proxy;
var i;
var http = require('http');
var net = require('net');
var host = null;
var port = 443;
var id = null;
var req;
var local = 0;
var remoteHost = "";
var remotePort = 0;
process.on("uncaughtException", function (e) { console.log("UncaughtException: " + e); });
process.on("exit", function (code) { console.log("Process Exiting with code: " + code); });
function onWebSocket(response, s, head)
{
console.log("WebSocket connected");
s.data = onWebSocketData;
}
function OnNewConnection(connection)
{
console.log("New Local Connection");
this.parent.pipe(connection);
connection.pipe(this.parent);
}
function OnClientConnection()
{
console.log("New Client Connection Established");
this.parent.pipe(this);
this.pipe(this.parent);
}
function onWebSocketData(buffer)
{
if(buffer == 'c')
{
console.log("tunnel established");
this.pause();
if (local != 0)
{
this.server = net.createServer();
this.server.parent = this;
this.server.on('connection', OnNewConnection);
this.server.listen({ port: local });
}
if(remotePort != 0)
{
this.client = net.createConnection({ port: remotePort, host: remoteHost }, OnClientConnection);
this.client.parent = this;
}
}
}
for (i = 1; i < process.argv.length; ++i)
{
if(process.argv[i] == 'local')
{
console.log("binding local port " + (local = parseInt(process.argv[i + 1])));
++i;
}
else if(process.argv[i] == 'remote')
{
remoteHost = process.argv[i + 1];
remotePort = parseInt(process.argv[i + 2])
console.log("binding remote " + remoteHost + ":" + remotePort);
i += 2;
}
else if(process.argv[i] == 'proxy')
{
console.log("Using Proxy: " + process.argv[i + 1] + ":" + parseInt(process.argv[i + 2]));
proxy = require('global-tunnel');
try
{
proxy.initialize({ host: process.argv[i + 1], port: parseInt(process.argv[i + 2]) });
}
catch(e)
{
console.log("Unable to bind proxy: " + e);
}
i += 2;
}
else if(process.argv[i] == 'relayHost')
{
host = process.argv[i + 1];
++i;
}
else if(process.argv[i] == 'relayId')
{
id = process.argv[i + 1];
++i;
}
else if(process.argv[i] == 'relayPort')
{
port = parseInt(argv[i + 1]);
++i;
}
}
if (host != null && id != null)
{
console.log("using relay: [" + host + ":" + port + "] using id: " + id);
req = http.request({ protocol: "wss:", host: host, port: port, path: "/meshrelay.ashx?id='" + id + "'" });
req.upgrade = onWebSocket;
}

38
MeshAgent.sln Normal file
View File

@@ -0,0 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MeshService", "MeshService\MeshService.vcxproj", "{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MeshConsole", "MeshConsole\MeshConsole.vcxproj", "{E377F156-BAED-4086-B534-3CC43164607A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|x64.ActiveCfg = Debug|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|x64.Build.0 = Debug|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|x86.ActiveCfg = Debug|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|x86.Build.0 = Debug|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|x64.ActiveCfg = Release|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|x64.Build.0 = Release|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|x86.ActiveCfg = Release|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|x86.Build.0 = Release|Win32
{E377F156-BAED-4086-B534-3CC43164607A}.Debug|x64.ActiveCfg = Debug|x64
{E377F156-BAED-4086-B534-3CC43164607A}.Debug|x64.Build.0 = Debug|x64
{E377F156-BAED-4086-B534-3CC43164607A}.Debug|x86.ActiveCfg = Debug|Win32
{E377F156-BAED-4086-B534-3CC43164607A}.Debug|x86.Build.0 = Debug|Win32
{E377F156-BAED-4086-B534-3CC43164607A}.Release|x64.ActiveCfg = Release|x64
{E377F156-BAED-4086-B534-3CC43164607A}.Release|x64.Build.0 = Release|x64
{E377F156-BAED-4086-B534-3CC43164607A}.Release|x86.ActiveCfg = Release|Win32
{E377F156-BAED-4086-B534-3CC43164607A}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

7
clean.bat Normal file
View File

@@ -0,0 +1,7 @@
del /s /q Debug
rmdir /s /q Debug
del /s /q Release
rmdir /s /q Release
del /s /q .vs
rmdir /s /q .vs
del /q MeshAgent.sdf

19
compileall Normal file
View File

@@ -0,0 +1,19 @@
make clean
make linux ARCHID=5
make clean
make linux ARCHID=6
make clean
make linux ARCHID=7
make clean
make linux ARCHID=9
make clean
make linux ARCHID=13
make clean
make linux ARCHID=15
make clean
make linux ARCHID=18
make clean
make linux ARCHID=19
make clean
make linux ARCHID=20
make clean

Binary file not shown.

292
makefile Normal file
View File

@@ -0,0 +1,292 @@
# To build MeshAgent2 on Linux you first got to download the dev libraries to compile the agent, we need x11, txt, ext and jpeg. To install, do this:
#
# sudo apt-get install libx11-dev libxtst-dev libxext-dev libjpeg-dev
#
# To install ARM Cross Compiler for Raspberry PI
# sudo apt-get install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev gcc-arm-linux-gnueabihf
#
# Special builds:
#
# make linux ARCHID=6 WEBLOG=1 KVM=0 # Linux x86 64 bit, with Web Logging, and KVM disabled
# make linux ARCHID=6 DEBUG=1 # Linux x86 64 bit, with debug symbols and automated crash handling
#
# Standard builds
#
# ARCHID=1 # Windows Console x86 32 bit
# ARCHID=2 # Windows Console x86 64 bit
# ARCHID=3 # Windows Service x86 32 bit
# ARCHID=4 # Windows Service x86 64 bit
# make linux ARCHID=5 # Linux x86 32 bit
# make linux ARCHID=6 # Linux x86 64 bit
# make linux ARCHID=7 # Linux MIPS
# make linux ARCHID=9 # Linux ARM 32 bit
# make linux ARCHID=13 # Linux ARM 32 bit PogoPlug
# make linux ARCHID=15 # Linux x86 32 bit POKY
# make linux ARCHID=18 # Linux x86 64 bit POKY
# make linux ARCHID=19 # Linux x86 32 bit NOKVM
# make linux ARCHID=20 # Linux x86 64 bit NOKVM
# make linux ARCHID=25 # Linux ARM 32 bit HardFloat (Raspberry PI2, etc)
#
# Microstack & Microscript
SOURCES = microstack/ILibAsyncServerSocket.c microstack/ILibAsyncSocket.c microstack/ILibAsyncUDPSocket.c microstack/ILibParsers.c microstack/ILibMulticastSocket.c
SOURCES += microstack/ILibRemoteLogging.c microstack/ILibWebClient.c microstack/ILibWebRTC.c microstack/ILibWebServer.c microstack/ILibCrypto.c
SOURCES += microstack/ILibWrapperWebRTC.c microstack/md5.c microstack/sha1.c microstack/ILibSimpleDataStore.c microstack/ILibProcessPipe.c microstack/ILibIPAddressMonitor.c
SOURCES += microscript/duktape.c microscript/ILibAsyncSocket_Duktape.c microscript/ILibDuktape_DuplexStream.c microscript/ILibDuktape_Helpers.c
SOURCES += microscript/ILibDuktape_http.c microscript/ILibDuktape_net.c microscript/ILibDuktape_ReadableStream.c microscript/ILibDuktape_WritableStream.c
SOURCES += microscript/ILibDuktapeModSearch.c microscript/ILibParsers_Duktape.c microscript/ILibWebClient_Duktape.c microscript/ILibDuktape_WebRTC.c
SOURCES += microscript/ILibWebServer_Duktape.c microscript/ILibDuktape_SimpleDataStore.c microscript/ILibDuktape_GenericMarshal.c
SOURCES += microscript/ILibDuktape_ProcessPipe.c microscript/ILibDuktape_fs.c microscript/ILibDuktape_SHA256.c microscript/ILibduktape_EventEmitter.c
SOURCES += microscript/ILibDuktape_EncryptionStream.c microscript/ILibDuktape_Polyfills.c microscript/ILibDuktape_Dgram.c
SOURCES += microscript/ILibDuktape_ScriptContainer.c microscript/ILibDuktape_MemoryStream.c microscript/ILibDuktape_NetworkMonitor.c
# Mesh Agent core
SOURCES += meshcore/agentcore.c meshconsole/main.c meshcore/meshinfo.c
# Mesh Agent settings
MESH_VER = 194
EXENAME = meshagent
# Cross-compiler paths
PATH_MIPS = ../ToolChains/ddwrt/3.4.6-uclibc-0.9.28/bin/
PATH_ARM5 = ../ToolChains/LinuxArm/bin/
PATH_POGO = ../ToolChains/pogoplug-gcc/bin/
PATH_POKY = ../Galileo/arduino-1.5.3/hardware/tools/sysroots/x86_64-pokysdk-linux/usr/bin/i586-poky-linux-uclibc/
PATH_POKY64 = /opt/poky/1.6.1/sysroots/x86_64-pokysdk-linux/usr/bin/x86_64-poky-linux/
OBJECTS = $(patsubst %.c,%.o, $(SOURCES))
# Compiler command name
CC = gcc
STRIP = strip
# Need to be separate for dependency generation
INCDIRS = -I. -Iopenssl/include -Imicrostack -Imicroscript -Imeshcore -Imeshconsole
# Compiler and linker flags
CFLAGS ?= -std=gnu99 -g -Wall -D_POSIX -DMICROSTACK_PROXY $(CWEBLOG) $(CWATCHDOG) -fno-strict-aliasing $(INCDIRS)
LDFLAGS ?= -rdynamic -L. -lpthread -ldl -lutil -lrt -lm
CEXTRA = -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fstack-protector -fno-strict-aliasing
LDEXTRA =
# Official Linux x86 32bit
ifeq ($(ARCHID),5)
ARCHNAME = x86
CC = gcc -m32
KVM = 1
LMS = 1
LDEXTRA += -z noexecstack -z relro -z now
endif
# Official Linux x86 64bit
ifeq ($(ARCHID),6)
ARCHNAME = x86-64
KVM = 1
LMS = 1
LDEXTRA += -z noexecstack -z relro -z now
endif
# Official Linux MIPS
ifeq ($(ARCHID),7)
ARCHNAME = mips
CC = $(PATH_MIPS)mipsel-linux-gcc
STRIP = $(PATH_MIPS)mipsel-linux-strip
CEXTRA = -D_FORTIFY_SOURCE=2 -D_NOILIBSTACKDEBUG -D_NOFSWATCHER -Wformat -Wformat-security -fno-strict-aliasing
KVM = 0
LMS = 0
endif
# Official Linux ARM
ifeq ($(ARCHID),9)
ARCHNAME = arm
CC = $(PATH_ARM5)arm-none-linux-gnueabi-gcc
STRIP = $(PATH_ARM5)arm-none-linux-gnueabi-strip
KVM = 0
LMS = 0
CFLAGS += -D_NOFSWATCHER
CEXTRA = -fno-strict-aliasing
endif
# Official Linux PogoPlug
ifeq ($(ARCHID),13)
ARCHNAME = pogo
CC = $(PATH_POGO)arm-none-linux-gnueabi-gcc
STRIP = $(PATH_POGO)arm-none-linux-gnueabi-strip
KVM = 0
LMS = 0
CEXTRA = -D_FORTIFY_SOURCE=2 -D_NOILIBSTACKDEBUG -D_NOFSWATCHER -Wformat -Wformat-security -fno-strict-aliasing
endif
# Official Linux POKY
ifeq ($(ARCHID),15)
ARCHNAME = poky
CC = $(PATH_POKY)i586-poky-linux-uclibc-gcc --sysroot=../Galileo/arduino-1.5.3/hardware/tools/sysroots/i586-poky-linux-uclibc
STRIP = $(PATH_POKY)i586-poky-linux-uclibc-strip
KVM = 0
LMS = 0
CFLAGS += -D_NOFSWATCHER
CEXTRA = -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-aliasing
endif
# Official Linux POKY64
ifeq ($(ARCHID),18)
ARCHNAME = poky64
CC = $(PATH_POKY64)x86_64-poky-linux-gcc
STRIP = $(PATH_POKY64)x86_64-poky-linux-strip
KVM = 0
LMS = 0
CFLAGS += -D_NOFSWATCHER
#CEXTRA = -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-aliasing
endif
# Official Linux x86 32bit NOKVM
ifeq ($(ARCHID),19)
ARCHNAME = x86
CC = gcc -m32
KVM = 0
LMS = 1
EXENAME2=_nokvm
LDEXTRA += -z noexecstack -z relro -z now
endif
# Official Linux x86 64bit NOKVM
ifeq ($(ARCHID),20)
ARCHNAME = x86-64
KVM = 0
LMS = 1
EXENAME2=_nokvm
LDEXTRA += -z noexecstack -z relro -z now
endif
# Official Linux ARM 32bit HardFloat
ifeq ($(ARCHID),25)
ARCHNAME = armhf
CC = arm-linux-gnueabihf-gcc
STRIP = arm-linux-gnueabihf-strip
KVM = 0
LMS = 0
CFLAGS += -D_NOFSWATCHER
CEXTRA = -fno-strict-aliasing
endif
ifeq ($(WEBLOG),1)
CFLAGS += -D_REMOTELOGGINGSERVER -D_REMOTELOGGING
endif
ifeq ($(KVM),1)
# Mesh Agent KVM, this is only included in builds that have KVM support
SOURCES += meshcore/KVM/Linux/linux_kvm.c meshcore/KVM/Linux/linux_events.c meshcore/KVM/Linux/linux_tile.c meshcore/KVM/Linux/linux_compression.c
CFLAGS += -D_LINKVM
LDFLAGS += -lX11 -lXtst -lXext -ljpeg
endif
ifeq ($(LMS),1)
# MicroLMS, only included in x86 builds
SOURCES += microlms/lms/ILibLMS.c microlms/heci/HECILinux.c microlms/heci/LMEConnection.c microlms/heci/PTHICommand.c
else
CFLAGS += -D_NOHECI
endif
ifneq ($(WatchDog),)
CWATCHDOG := -DILibChain_WATCHDOG_TIMEOUT=$(WatchDog)
endif
ifeq ($(NOSSL),1)
SOURCES += microstack/SHA256.c
CFLAGS += -DMICROSTACK_NOTLS
LINUXSSL =
else
LINUXSSL = -Lopenssl/libstatic/linux/$(ARCHNAME)
CFLAGS += -DMICROSTACK_TLS_DETECT
LDEXTRA += -lssl -lcrypto
endif
ifeq ($(DEBUG),1)
# Debug Build, include Symbols
CFLAGS += -g -rdynamic -D_DEBUG
STRIP = $(NOECHO) $(NOOP)
else
CFLAGS += -Os
STRIP += ./$(EXENAME)_$(ARCHNAME)$(EXENAME2)
endif
.PHONY: all clean
all: $(EXENAME) $(LIBNAME)
$(EXENAME): $(OBJECTS)
$(V)$(CC) $^ $(LDFLAGS) -o $@
sign:
strip ./$(EXENAME)
./agent/signer/signer_linux $(EXENAME) $(shell ./$(EXENAME) -v)
clean:
rm -f meshconsole/*.o
rm -f microstack/*.o
rm -f microscript/*.o
rm -f meshcore/*.o
rm -f meshcore/KVM/Linux/*.o
rm -f microlms/lms/*.o
rm -f microlms/heci/*.o
cleanbin:
rm -f $(EXENAME)_x86
rm -f $(EXENAME)_x86-64
rm -f $(EXENAME)_arm
rm -f $(EXENAME)_mips
depend: $(SOURCES)
$(CC) -M $(CFLAGS) $(SOURCES) $(HEADERS) > depend
run:all
strip ./$(EXENAME)
./agent/signer/signer_linux $(EXENAME) $(shell ./$(EXENAME) -v)
rm -f mtrax
set MALLOC_TRACE=mtrax
export MALLOC_TRACE;
./$(EXENAME)
mtrace ./$(EXENAME) mtrax
vrun:all
# strip ./$(EXENAME)
# ./agent/signer/signer_linux $(EXENAME) $(shell ./$(EXENAME) -v)
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes ./mesh_linux
trace:
mtrace ./$(EXENAME) mtrax
$(LIBNAME): $(OBJECTS) $(SOURCES)
$(CC) $(OBJECTS) -shared -o $(LIBNAME)
# Compile on Raspberry Pi 2/3 with KVM
pi:
$(MAKE) EXENAME="meshagent_pi2" CFLAGS="-std=gnu99 -g -Wall -D_POSIX -DMICROSTACK_PROXY -D_LINKVM $(CWEBLOG) $(CWATCHDOG) -fno-strict-aliasing $(INCDIRS) -DMESH_AGENTID=25 -D_NOFSWATCHER -D_NOHECI" LDFLAGS="-Lopenssl/libstatic/linux/pi2 $(LDFLAGS) $(LDEXTRA)"
strip meshagent_pi2
linux:
$(MAKE) EXENAME="$(EXENAME)_$(ARCHNAME)$(EXENAME2)" CFLAGS="-DMESH_AGENTID=$(ARCHID) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(LINUXSSL) $(LDFLAGS) $(LDEXTRA)"
$(STRIP)
linux-nossl-64-library:
$(MAKE) LIBNAME="$(EXENAME)_x64.so" ADDITIONALSOURCES="$(KVMSOURCES)" CFLAGS="-Os -fPIC -DMICROSTACK_NOTLS $(CFLAGS) $(CEXTRA)" LDFLAGS="-shared $(LDFLAGS) $(LDEXTRA)"
linux-64-library-debug:
$(MAKE) LIBNAME="$(EXENAME)_x64.so" ADDITIONALSOURCES="$(KVMSOURCES)" CFLAGS="-fPIC -D_DEBUG -DMICROSTACK_TLS_DETECT $(CFLAGS) $(CEXTRA)" LDFLAGS="-shared -L../../opentools/MeshManageability/openssl-static/x86-64 -lssl $(LDFLAGS) $(LDEXTRA)"
#mac-nossl-64:
# $(MAKE) $(MAKEFILE) EXENAME="$(EXENAME)_osx64" CFLAGS="-arch x86_64 -mmacosx-version-min=10.5 -framework IOKit -framework ApplicationServices -framework SystemConfiguration -framework CoreFoundation -fconstant-cfstrings -std=gnu99 -Os -Wall -D_AGENTID=16 -D_POSIX -D_NOHECI -D_DAEMON -DMICROSTACK_PROXY -DMICROSTACK_NOTLS -D__APPLE__ $(CWEBLOG) -fno-strict-aliasing $(INCDIRS)" LDFLAGS="-L. -lpthread -ldl -lz -lutil"
# strip ./$(EXENAME)_osx64
#mac-nossl-64-debug:
# $(MAKE) $(MAKEFILE) EXENAME="$(EXENAME)_osx64" CFLAGS="-arch x86_64 -mmacosx-version-min=10.5 -framework IOKit -framework ApplicationServices -framework SystemConfiguration -framework CoreFoundation -fconstant-cfstrings -std=gnu99 -g -Wall -D_AGENTID=16 -D_POSIX -D_NOHECI -D_DAEMON -D_DEBUG -DMICROSTACK_PROXY -DMICROSTACK_NOTLS -D__APPLE__ $(CWEBLOG) -fno-strict-aliasing $(INCDIRS)" LDFLAGS="-L. -lpthread -ldl -lz -lutil"
#mac-64:
# $(MAKE) $(MAKEFILE) EXENAME="$(EXENAME)_osx64" CFLAGS="-arch x86_64 -mmacosx-version-min=10.5 -framework IOKit -framework ApplicationServices -framework SystemConfiguration -framework CoreFoundation -fconstant-cfstrings -Os -std=gnu99 -Wall -D_AGENTID=16 -D_POSIX -D_DAEMON -DMICROSTACK_PROXY -DMICROSTACK_TLS_DETECT -D__APPLE__ $(CWEBLOG) $(CEXTRA) $(INCDIRS)" LDFLAGS="-L../../opentools/MeshManageability/openssl-static/osx64 -L. -lpthread -ldl -lssl -lutil -lcrypto -lm"
# strip ./$(EXENAME)_osx64
#mac-64-debug:
# $(MAKE) $(MAKEFILE) EXENAME="$(EXENAME)_osx64" CFLAGS="-arch x86_64 -mmacosx-version-min=10.5 -framework IOKit -framework ApplicationServices -framework SystemConfiguration -framework CoreFoundation -fconstant-cfstrings -g -std=gnu99 -Wall -D_AGENTID=16 -D_DEBUG -D_POSIX -D_DAEMON -DMICROSTACK_PROXY -DMICROSTACK_TLS_DETECT -D__APPLE__ $(CWEBLOG) $(CEXTRA) $(INCDIRS)" LDFLAGS="-L../../opentools/MeshManageability/openssl-static/osx64 -L. -lpthread -ldl -lssl -lutil -lcrypto -lm"

BIN
meshconsole/MeshConsole.rc Normal file

Binary file not shown.

View File

@@ -0,0 +1,264 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\meshcore\agentcore.c" />
<ClCompile Include="..\meshcore\KVM\Windows\input.c" />
<ClCompile Include="..\meshcore\KVM\Windows\kvm.c" />
<ClCompile Include="..\meshcore\KVM\Windows\tile.cpp" />
<ClCompile Include="..\meshcore\meshinfo.c" />
<ClCompile Include="..\microlms\heci\HECIWin.c" />
<ClCompile Include="..\microlms\heci\LMEConnection.c" />
<ClCompile Include="..\microlms\heci\PTHICommand.c" />
<ClCompile Include="..\microlms\lms\ILibLMS.c" />
<ClCompile Include="..\microscript\duktape.c" />
<ClCompile Include="..\microscript\ILibAsyncSocket_Duktape.c" />
<ClCompile Include="..\microscript\ILibDuktapeModSearch.c" />
<ClCompile Include="..\microscript\ILibDuktape_Debugger.c" />
<ClCompile Include="..\microscript\ILibDuktape_Dgram.c" />
<ClCompile Include="..\microscript\ILibDuktape_DuplexStream.c" />
<ClCompile Include="..\microscript\ILibDuktape_EncryptionStream.c" />
<ClCompile Include="..\microscript\ILibduktape_EventEmitter.c" />
<ClCompile Include="..\microscript\ILibDuktape_fs.c" />
<ClCompile Include="..\microscript\ILibDuktape_GenericMarshal.c" />
<ClCompile Include="..\microscript\ILibDuktape_Helpers.c" />
<ClCompile Include="..\microscript\ILibDuktape_http.c" />
<ClCompile Include="..\microscript\ILibDuktape_MemoryStream.c" />
<ClCompile Include="..\microscript\ILibDuktape_net.c" />
<ClCompile Include="..\microscript\ILibDuktape_NetworkMonitor.c" />
<ClCompile Include="..\microscript\ILibDuktape_Polyfills.c" />
<ClCompile Include="..\microscript\ILibDuktape_ProcessPipe.c" />
<ClCompile Include="..\microscript\ILibDuktape_ReadableStream.c" />
<ClCompile Include="..\microscript\ILibDuktape_ScriptContainer.c" />
<ClCompile Include="..\microscript\ILibDuktape_SHA256.c" />
<ClCompile Include="..\microscript\ILibDuktape_SimpleDataStore.c" />
<ClCompile Include="..\microscript\ILibDuktape_WebRTC.c" />
<ClCompile Include="..\microscript\ILibDuktape_WritableStream.c" />
<ClCompile Include="..\microscript\ILibParsers_Duktape.c" />
<ClCompile Include="..\microscript\ILibWebClient_Duktape.c" />
<ClCompile Include="..\microscript\ILibWebServer_Duktape.c" />
<ClCompile Include="..\microstack\ILibAsyncServerSocket.c" />
<ClCompile Include="..\microstack\ILibAsyncSocket.c" />
<ClCompile Include="..\microstack\ILibAsyncUDPSocket.c" />
<ClCompile Include="..\microstack\ILibCrypto.c" />
<ClCompile Include="..\microstack\ILibIPAddressMonitor.c" />
<ClCompile Include="..\microstack\ILibMulticastSocket.c" />
<ClCompile Include="..\microstack\ILibParsers.c" />
<ClCompile Include="..\microstack\ILibProcessPipe.c" />
<ClCompile Include="..\microstack\ILibRemoteLogging.c" />
<ClCompile Include="..\microstack\ILibSimpleDataStore.c" />
<ClCompile Include="..\microstack\ILibWebClient.c" />
<ClCompile Include="..\microstack\ILibWebRTC.c" />
<ClCompile Include="..\microstack\ILibWebServer.c" />
<ClCompile Include="..\microstack\ILibWrapperWebRTC.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\meshcore\agentcore.h" />
<ClInclude Include="..\meshcore\KVM\Windows\input.h" />
<ClInclude Include="..\meshcore\KVM\Windows\kvm.h" />
<ClInclude Include="..\meshcore\KVM\Windows\tile.h" />
<ClInclude Include="..\meshcore\meshdefines.h" />
<ClInclude Include="..\meshcore\meshinfo.h" />
<ClInclude Include="..\microlms\heci\HECIWin.h" />
<ClInclude Include="..\microlms\heci\HECI_if.h" />
<ClInclude Include="..\microlms\heci\LMEConnection.h" />
<ClInclude Include="..\microlms\heci\LMS_if.h" />
<ClInclude Include="..\microlms\heci\LMS_if_constants.h" />
<ClInclude Include="..\microlms\heci\mei.h" />
<ClInclude Include="..\microlms\heci\PTHICommand.h" />
<ClInclude Include="..\microlms\heci\StatusCodeDefinitions.h" />
<ClInclude Include="..\microlms\lms\ILibLMS-WebSite.h" />
<ClInclude Include="..\microlms\lms\ILibLMS.h" />
<ClInclude Include="..\microscript\duktape.h" />
<ClInclude Include="..\microscript\duk_config.h" />
<ClInclude Include="..\microscript\ILibAsyncSocket_Duktape.h" />
<ClInclude Include="..\microscript\ILibDuktapeModSearch.h" />
<ClInclude Include="..\microscript\ILibDuktape_Debugger.h" />
<ClInclude Include="..\microscript\ILibDuktape_Dgram.h" />
<ClInclude Include="..\microscript\ILibDuktape_DuplexStream.h" />
<ClInclude Include="..\microscript\ILibDuktape_EncryptionStream.h" />
<ClInclude Include="..\microscript\ILibDuktape_EventEmitter.h" />
<ClInclude Include="..\microscript\ILibDuktape_fs.h" />
<ClInclude Include="..\microscript\ILibDuktape_GenericMarshal.h" />
<ClInclude Include="..\microscript\ILibDuktape_Helpers.h" />
<ClInclude Include="..\microscript\ILibDuktape_http.h" />
<ClInclude Include="..\microscript\ILibDuktape_net.h" />
<ClInclude Include="..\microscript\ILibDuktape_NetworkMonitor.h" />
<ClInclude Include="..\microscript\ILibDuktape_Polyfills.h" />
<ClInclude Include="..\microscript\ILibDuktape_ProcessPipe.h" />
<ClInclude Include="..\microscript\ILibDuktape_ReadableStream.h" />
<ClInclude Include="..\microscript\ILibDuktape_ScriptContainer.h" />
<ClInclude Include="..\microscript\ILibDuktape_SHA256.h" />
<ClInclude Include="..\microscript\ILibDuktape_SimpleDataStore.h" />
<ClInclude Include="..\microscript\ILibDuktape_WebRTC.h" />
<ClInclude Include="..\microscript\ILibDuktape_WritableStream.h" />
<ClInclude Include="..\microscript\ILibParsers_Duktape.h" />
<ClInclude Include="..\microscript\ILibWebClient_Duktape.h" />
<ClInclude Include="..\microscript\ILibWebServer_Duktape.h" />
<ClInclude Include="..\microstack\ILibAsyncServerSocket.h" />
<ClInclude Include="..\microstack\ILibAsyncSocket.h" />
<ClInclude Include="..\microstack\ILibAsyncUDPSocket.h" />
<ClInclude Include="..\microstack\ILibCrypto.h" />
<ClInclude Include="..\microstack\ILibIPAddressMonitor.h" />
<ClInclude Include="..\microstack\ILibMulticastSocket.h" />
<ClInclude Include="..\microstack\ILibParsers.h" />
<ClInclude Include="..\microstack\ILibProcessPipe.h" />
<ClInclude Include="..\microstack\ILibRemoteLogging.h" />
<ClInclude Include="..\microstack\ILibSimpleDataStore.h" />
<ClInclude Include="..\microstack\ILibWebClient.h" />
<ClInclude Include="..\microstack\ILibWebRTC.h" />
<ClInclude Include="..\microstack\ILibWebServer.h" />
<ClInclude Include="..\microstack\ILibWrapperWebRTC.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MeshConsole.rc" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E377F156-BAED-4086-B534-3CC43164607A}</ProjectGuid>
<RootNamespace>MicrostackDuktape</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>MESH_AGENTID=1;NOLMSCOMMANDER;_DEBUG;MICROSTACK_PROXY;_LINKVM;DUK_OPT_DEBUGGER_SUPPORT;DUK_OPT_INTERRUPT_COUNTER;WIN32;WINSOCK2;_WINSOCK_DEPRECATED_NO_WARNINGS;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);MICROSTACK_TLS_DETECT;MICROSTACK_NO_STDAFX;_REMOTELOGGING;_REMOTELOGGINGSERVER;ILibChain_WATCHDOG_TIMEOUT=600000;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;Crypt32.lib;DbgHelp.lib;Gdiplus.lib;Iphlpapi.lib;ws2_32.lib;..\openssl\libstatic\libcrypto32MTd.lib;..\openssl\libstatic\libssl32MTd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>MESH_AGENTID=1;NOLMSCOMMANDER;MICROSTACK_PROXY;_LINKVM;WIN32;WINSOCK2;_WINSOCK_DEPRECATED_NO_WARNINGS;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);MICROSTACK_TLS_DETECT;MICROSTACK_NO_STDAFX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\openssl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;Crypt32.lib;DbgHelp.lib;Gdiplus.lib;Iphlpapi.lib;ws2_32.lib;..\openssl\libstatic\libcrypto32MT.lib;..\openssl\libstatic\libssl32MT.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>MESH_AGENTID=2;NOLMSCOMMANDER;MICROSTACK_PROXY;_DEBUG;WIN32;WIN64;WINSOCK2;_WINSOCK_DEPRECATED_NO_WARNINGS;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);MICROSTACK_TLS_DETECT;MICROSTACK_NO_STDAFX;_REMOTELOGGING;_REMOTELOGGINGSERVER;ILibChain_WATCHDOG_TIMEOUT=600000;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;Crypt32.lib;DbgHelp.lib;Gdiplus.lib;Iphlpapi.lib;ws2_32.lib;..\openssl\libstatic\libcrypto64MTd.lib;..\openssl\libstatic\libssl64MTd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>MESH_AGENTID=2;NOLMSCOMMANDER;MICROSTACK_PROXY;_LINKVM;WIN32;WIN64;WINSOCK2;_WINSOCK_DEPRECATED_NO_WARNINGS;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);MICROSTACK_TLS_DETECT;MICROSTACK_NO_STDAFX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;DbgHelp.lib;Gdiplus.lib;Iphlpapi.lib;Crypt32.lib;ws2_32.lib;..\openssl\libstatic\libcrypto64MT.lib;..\openssl\libstatic\libssl64MT.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,344 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Microstack">
<UniqueIdentifier>{597cd7bb-defe-4939-bdc7-541e03f0adbf}</UniqueIdentifier>
</Filter>
<Filter Include="Microscript">
<UniqueIdentifier>{daa120d0-c259-4af3-a157-2c38387a7049}</UniqueIdentifier>
</Filter>
<Filter Include="Meshcore">
<UniqueIdentifier>{1fcb4ac6-fb2a-4a2e-a2e7-5b85a95507c5}</UniqueIdentifier>
</Filter>
<Filter Include="Meshcore\KVM">
<UniqueIdentifier>{ab71a2fa-eafc-44d7-9c35-62f7d60fee6a}</UniqueIdentifier>
</Filter>
<Filter Include="MicroLMS">
<UniqueIdentifier>{aeb98903-4a96-453a-8c67-7a824d947bcc}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\microscript\duk_config.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibAsyncSocket_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Debugger.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_DuplexStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_GenericMarshal.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Helpers.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_http.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_net.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_ReadableStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_SimpleDataStore.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_WritableStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktapeModSearch.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibParsers_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibWebClient_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibWebServer_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibAsyncServerSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibAsyncSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibAsyncUDPSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibParsers.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibProcessPipe.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibRemoteLogging.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibSimpleDataStore.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWebClient.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWebRTC.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWebServer.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWrapperWebRTC.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\agentcore.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\meshdefines.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_ProcessPipe.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_fs.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_SHA256.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_EncryptionStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Dgram.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\KVM\Windows\input.h">
<Filter>Meshcore\KVM</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\KVM\Windows\kvm.h">
<Filter>Meshcore\KVM</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\KVM\Windows\tile.h">
<Filter>Meshcore\KVM</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_EventEmitter.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibCrypto.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Polyfills.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_WebRTC.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microlms\lms\ILibLMS.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\lms\ILibLMS-WebSite.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\HECI_if.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\HECIWin.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\LMEConnection.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\LMS_if.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\LMS_if_constants.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\mei.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\PTHICommand.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\StatusCodeDefinitions.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibMulticastSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="resource.h" />
<ClInclude Include="..\meshcore\meshinfo.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_ScriptContainer.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibIPAddressMonitor.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_NetworkMonitor.h">
<Filter>Microscript</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\microscript\duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibAsyncSocket_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Debugger.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_DuplexStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_GenericMarshal.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Helpers.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_http.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_net.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_ReadableStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_SimpleDataStore.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_WritableStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktapeModSearch.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibParsers_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibWebClient_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibWebServer_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibAsyncServerSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibAsyncSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibAsyncUDPSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibParsers.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibProcessPipe.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibRemoteLogging.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibSimpleDataStore.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWebClient.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWebRTC.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWebServer.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWrapperWebRTC.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\agentcore.c">
<Filter>Meshcore</Filter>
</ClCompile>
<ClCompile Include="main.c" />
<ClCompile Include="..\microscript\ILibDuktape_ProcessPipe.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_fs.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_SHA256.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_EncryptionStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Dgram.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\KVM\Windows\input.c">
<Filter>Meshcore\KVM</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\KVM\Windows\kvm.c">
<Filter>Meshcore\KVM</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\KVM\Windows\tile.cpp">
<Filter>Meshcore\KVM</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibduktape_EventEmitter.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibCrypto.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Polyfills.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_WebRTC.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microlms\lms\ILibLMS.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microlms\heci\HECIWin.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microlms\heci\LMEConnection.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microlms\heci\PTHICommand.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibMulticastSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\meshinfo.c">
<Filter>Meshcore</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_ScriptContainer.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_MemoryStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibIPAddressMonitor.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_NetworkMonitor.c">
<Filter>Microscript</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MeshConsole.rc" />
</ItemGroup>
</Project>

132
meshconsole/main.c Normal file
View File

@@ -0,0 +1,132 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Windows.h>
#endif
#include "meshcore/agentcore.h"
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(_MINCORE)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
MeshAgentHostContainer *agentHost = NULL;
#ifdef WIN32
BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
{
if (agentHost != NULL) { MeshAgent_Stop(agentHost); }
return TRUE;
}
default:
return FALSE;
}
}
#endif
#if defined(_POSIX)
void BreakSink(int s)
{
UNREFERENCED_PARAMETER(s);
signal(SIGINT, SIG_IGN); // To ignore any more ctrl c interrupts
if (agentHost != NULL) { MeshAgent_Stop(agentHost); }
}
#endif
int main(int argc, char **argv)
{
int retCode = 0;
if (argc > 2 && memcmp(argv[1], "-faddr", 6) == 0)
{
uint64_t addrOffset;
util_hexToBuf(argv[2] + 2, strnlen_s(argv[2], 130) - 2, (char*)&addrOffset);
ILibChain_DebugOffset(ILibScratchPad, sizeof(ILibScratchPad), addrOffset);
printf("%s", ILibScratchPad);
return(0);
}
if (argc >= 2 && strnlen_s(argv[1], 9) >= 8 && strncmp(argv[1], "-update:",8) == 0)
{
/*
// If in OSX, attempt to clean up the KVM slave process.
#if defined(__APPLE__) && defined(_DAEMON) && defined(_LINKVM)
installOsx(0);
#endif
*/
// -update:"C:\Users\Public\Downloads\MeshManageability\Debug\MeshConsol2.exe"
MeshAgent_PerformSelfUpdate(argv[0], argv[1] + 8, argc, argv);
return 0;
}
#ifdef WIN32
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); // Set SIGNAL on windows to listen for Ctrl-C
CONTEXT winExceptionContext;
#elif defined(_POSIX)
signal(SIGPIPE, SIG_IGN); // Set a SIGNAL on Linux to listen for Ctrl-C
signal(SIGINT, BreakSink);// Shutdown on Ctrl + C
{
struct sigaction act;
act.sa_handler = SIG_IGN;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGPIPE, &act, NULL);
}
#ifndef _NOILIBSTACKDEBUG
char* crashMemory = ILib_POSIX_InstallCrashHandler(argv[0]);
#endif
#endif
#ifdef WIN32
__try
{
agentHost = MeshAgent_Create();
while (MeshAgent_Start(agentHost, argc, argv) != 0);
retCode = agentHost->exitCode;
MeshAgent_Destroy(agentHost);
}
__except (ILib_WindowsExceptionFilter(GetExceptionCode(), GetExceptionInformation(), &winExceptionContext))
{
ILib_WindowsExceptionDebug(&winExceptionContext);
}
_CrtDumpMemoryLeaks();
#else
agentHost = MeshAgent_Create();
while (MeshAgent_Start(agentHost, argc, argv) != 0);
retCode = agentHost->exitCode;
MeshAgent_Destroy(agentHost);
#ifndef _NOILIBSTACKDEBUG
if (crashMemory != NULL) { free(crashMemory); }
#endif
#endif
return retCode;
}

14
meshconsole/resource.h Normal file
View File

@@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MeshConsole.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,99 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "linux_compression.h"
unsigned char *jpeg_buffer = NULL;
int jpeg_buffer_length = 0;
void init_destination(j_compress_ptr cinfo)
{
JOCTET * next_output_byte;
if (jpeg_buffer != NULL) { free(jpeg_buffer); }
jpeg_buffer = malloc(MAX_BUFFER);
jpeg_buffer_length = 0;
next_output_byte = jpeg_buffer;
cinfo->dest->next_output_byte = next_output_byte;
cinfo->dest->free_in_buffer = MAX_BUFFER;
}
boolean empty_output_buffer(j_compress_ptr cinfo)
{
JOCTET * next_output_byte;
jpeg_buffer_length += MAX_BUFFER;
jpeg_buffer = (unsigned char *) realloc(jpeg_buffer, jpeg_buffer_length + MAX_BUFFER);
next_output_byte = jpeg_buffer + jpeg_buffer_length;
cinfo->dest->next_output_byte = next_output_byte;
cinfo->dest->free_in_buffer = MAX_BUFFER;
if (jpeg_buffer_length > 65500) return FALSE;
return TRUE;
}
void term_destination (j_compress_ptr cinfo)
{
int remaining_buff_length = MAX_BUFFER - cinfo->dest->free_in_buffer;
jpeg_buffer_length += remaining_buff_length;
if (jpeg_buffer_length > 65500) {
free(jpeg_buffer);
jpeg_buffer = NULL;
}
else {
jpeg_buffer = (unsigned char *) realloc(jpeg_buffer, jpeg_buffer_length);
}
}
int write_JPEG_buffer (JSAMPLE * image_buffer, int image_width, int image_height, int quality)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[1];
int row_stride;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
cinfo.dest = (struct jpeg_destination_mgr *) malloc (sizeof(struct jpeg_destination_mgr));
cinfo.dest->init_destination = &init_destination;
cinfo.dest->empty_output_buffer = &empty_output_buffer;
cinfo.dest->term_destination = &term_destination;
cinfo.image_width = image_width;
cinfo.image_height = image_height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
row_stride = image_width * 3;
while (cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
free(cinfo.dest);
cinfo.dest = NULL;
jpeg_destroy_compress(&cinfo);
return 0;
}

View File

@@ -0,0 +1,34 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef LINUX_COMPRESSION_H_
#define LINUX_COMPRESSION_H_
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include "../../libjpeg-turbo/jpeglib.h"
#include "../../libjpeg-turbo/jerror.h"
#else
#include <jpeglib.h>
#include <jerror.h>
#endif
#define MAX_BUFFER 22528 // 22 KiB should be fine.
extern int write_JPEG_buffer (JSAMPLE * image_buffer, int image_width, int image_height, int quality);
#endif /* LINUX_COMPRESSION_H_ */

View File

@@ -0,0 +1,204 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "linux_events.h"
static const int g_keymapLen = 96; // Modify this when you change anything in g_keymap.
extern int change_display;
static struct keymap_t g_keymap[] = {
{ XK_BackSpace, VK_BACK },
{ XK_Tab, VK_TAB },
{ XK_Clear, VK_CLEAR },
{ XK_Return, VK_RETURN },
{ XK_Pause, VK_PAUSE },
{ XK_Escape, VK_ESCAPE },
{ XK_Delete, VK_DELETE },
{ XK_Home, VK_HOME },
{ XK_Left, VK_LEFT },
{ XK_Up, VK_UP },
{ XK_Right, VK_RIGHT },
{ XK_Down, VK_DOWN },
{ XK_Page_Up, VK_PRIOR },
{ XK_Page_Down, VK_NEXT },
{ XK_End, VK_END },
{ XK_Select, VK_SELECT },
{ XK_Print, VK_SNAPSHOT },
{ XK_Execute, VK_EXECUTE },
{ XK_Insert, VK_INSERT },
{ XK_Help, VK_HELP },
{ XK_Break, VK_CANCEL },
{ XK_F1, VK_F1 },
{ XK_F2, VK_F2 },
{ XK_F3, VK_F3 },
{ XK_F4, VK_F4 },
{ XK_F5, VK_F5 },
{ XK_F6, VK_F6 },
{ XK_F7, VK_F7 },
{ XK_F8, VK_F8 },
{ XK_F9, VK_F9 },
{ XK_F10, VK_F10 },
{ XK_F11, VK_F11 },
{ XK_F12, VK_F12 },
{ XK_F13, VK_F13 },
{ XK_F14, VK_F14 },
{ XK_F15, VK_F15 },
{ XK_F16, VK_F16 },
{ XK_F17, VK_F17 },
{ XK_F18, VK_F18 },
{ XK_F19, VK_F19 },
{ XK_F20, VK_F20 },
{ XK_F21, VK_F21 },
{ XK_F22, VK_F22 },
{ XK_F23, VK_F23 },
{ XK_F24, VK_F24 },
{ XK_KP_Tab, VK_TAB },
{ XK_KP_Enter, VK_RETURN },
{ XK_KP_F1, VK_F1 },
{ XK_KP_F2, VK_F2 },
{ XK_KP_F3, VK_F3 },
{ XK_KP_F4, VK_F4 },
{ XK_KP_Home, VK_HOME },
{ XK_KP_End, VK_END },
{ XK_KP_Page_Up, VK_PRIOR },
{ XK_KP_Page_Down, VK_NEXT },
{ XK_KP_Begin, VK_CLEAR },
{ XK_KP_Insert, VK_INSERT },
{ XK_KP_Delete, VK_DELETE },
{ XK_KP_Multiply, VK_MULTIPLY },
{ XK_KP_Add, VK_ADD },
{ XK_KP_Separator, VK_SEPARATOR },
{ XK_KP_Subtract, VK_SUBTRACT },
{ XK_KP_Decimal, VK_DECIMAL },
{ XK_KP_Divide, VK_DIVIDE },
{ XK_KP_0, VK_NUMPAD0 },
{ XK_KP_1, VK_NUMPAD1 },
{ XK_KP_2, VK_NUMPAD2 },
{ XK_KP_3, VK_NUMPAD3 },
{ XK_KP_4, VK_NUMPAD4 },
{ XK_KP_5, VK_NUMPAD5 },
{ XK_KP_6, VK_NUMPAD6 },
{ XK_KP_7, VK_NUMPAD7 },
{ XK_KP_8, VK_NUMPAD8 },
{ XK_KP_9, VK_NUMPAD9 },
{ XK_Shift_L, VK_SHIFT },
{ XK_Shift_R, VK_SHIFT },
{ XK_Control_L, VK_CONTROL },
{ XK_Control_R, VK_CONTROL },
{ XK_Alt_L, VK_MENU },
{ XK_Alt_R, VK_MENU },
{ XK_Super_L, VK_LWIN },
{ XK_Super_R, VK_RWIN },
{ XK_Menu, VK_APPS },
{ XK_Kanji, VK_KANJI },
{ XK_Kana_Shift, VK_KANA },
{ XK_colon, VK_OEM_1 },
{ XK_plus, VK_OEM_PLUS },
{ XK_comma, VK_OEM_COMMA },
{ XK_minus, VK_OEM_MINUS },
{ XK_period, VK_OEM_PERIOD },
{ XK_slash, VK_OEM_2 },
{ XK_grave, VK_OEM_3 },
{ XK_bracketleft, VK_OEM_4 },
{ XK_backslash, VK_OEM_5 },
{ XK_bracketright, VK_OEM_6 },
{ XK_apostrophe, VK_OEM_7 }
};
void MouseAction(double absX, double absY, int button, short wheel, Display *display)
{
if (change_display) {
return;
}
if (!XTestFakeMotionEvent(display, -1, absX, absY, CurrentTime )) { return; }
if (button != 0) {
int mouseDown = 1;
switch (button) {
case MOUSEEVENTF_LEFTDOWN:
button = 1;
break;
case MOUSEEVENTF_RIGHTDOWN:
button = 3;
break;
case MOUSEEVENTF_MIDDLEDOWN:
button = 2;
break;
case MOUSEEVENTF_LEFTUP:
button = 1;
mouseDown = 0;
break;
case MOUSEEVENTF_RIGHTUP:
button = 3;
mouseDown = 0;
break;
case MOUSEEVENTF_MIDDLEUP:
button = 2;
mouseDown = 0;
break;
default:
break;
}
if (!XTestFakeButtonEvent(display, button, mouseDown, CurrentTime)) { return; }
}
else if (wheel != 0) {
if (wheel > 0) {
button = Button4;
}
else {
button = Button5;
}
if (!XTestFakeButtonEvent(display, button, True, CurrentTime)) { return; }
XFlush(display);
if (!XTestFakeButtonEvent(display, button, False, CurrentTime)) { return; }
}
XFlush(display);
}
void KeyAction(unsigned char vk, int up, Display *display) {
int i = 0;
unsigned int keysym = 0;
unsigned int keycode = 0;
if (change_display) {
return;
}
for (i = 0; i < g_keymapLen; i++) {
if (g_keymap[i].vk == vk) {
keysym = g_keymap[i].keysym;
break;
}
}
if (keysym == 0) {
keycode = XKeysymToKeycode(display, vk);
}
else {
keycode = XKeysymToKeycode(display, keysym);
}
//printf("%x %x %d %d\n", keysym, vk, keycode, up);
if (keycode != 0) {
if (!XTestFakeKeyEvent(display, keycode, !up, 0)) { return; }
XFlush(display);
}
}

View File

@@ -0,0 +1,391 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef LINUX_EVENTS_H_
#define LINUX_EVENTS_H_
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
enum MOUSE_EVENTS {
MOUSEEVENTF_LEFTDOWN = 0x0002,
MOUSEEVENTF_RIGHTDOWN = 0x0008,
MOUSEEVENTF_MIDDLEDOWN = 0x0020,
MOUSEEVENTF_LEFTUP = 0x0004,
MOUSEEVENTF_RIGHTUP = 0x0010,
MOUSEEVENTF_MIDDLEUP = 0x0040
};
// VK_LBUTTON (01) Left mouse button
#define VK_LBUTTON 0x01
// VK_RBUTTON (02) Right mouse button
#define VK_RBUTTON 0x02
// VK_CANCEL (03) Control-break processing
#define VK_CANCEL 0x03
// VK_MBUTTON (04) Middle mouse button (three-button mouse)
#define VK_MBUTTON 0x04
// VK_XBUTTON1 (05)
#define VK_XBUTTON1 0x05
// VK_XBUTTON2 (06)
#define VK_XBUTTON2 0x06
// VK_BACK (08) BACKSPACE key
#define VK_BACK 0x08
// VK_TAB (09) TAB key
#define VK_TAB 0x09
// VK_CLEAR (0C) CLEAR key
#define VK_CLEAR 0x0C
// VK_RETURN (0D)
#define VK_RETURN 0x0D
// VK_SHIFT (10) SHIFT key
#define VK_SHIFT 0x10
// VK_CONTROL (11) CTRL key
#define VK_CONTROL 0x11
// VK_MENU (12) ALT key
#define VK_MENU 0x12
// VK_PAUSE (13) PAUSE key
#define VK_PAUSE 0x13
// VK_CAPITAL (14) CAPS LOCK key
#define VK_CAPITAL 0x14
// VK_KANA (15) Input Method Editor (IME) Kana mode
#define VK_KANA 0x15
// VK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
// VK_HANGUL (15) IME Hangul mode
#define VK_HANGUL 0x15
// VK_JUNJA (17) IME Junja mode
#define VK_JUNJA 0x17
// VK_FINAL (18) IME final mode
#define VK_FINAL 0x18
// VK_HANJA (19) IME Hanja mode
#define VK_HANJA 0x19
// VK_KANJI (19) IME Kanji mode
#define VK_KANJI 0x19
// VK_ESCAPE (1B) ESC key
#define VK_ESCAPE 0x1B
// VK_CONVERT (1C) IME convert
#define VK_CONVERT 0x1C
// VK_NONCONVERT (1D) IME nonconvert
#define VK_NONCONVERT 0x1D
// VK_ACCEPT (1E) IME accept
#define VK_ACCEPT 0x1E
// VK_MODECHANGE (1F) IME mode change request
#define VK_MODECHANGE 0x1F
// VK_SPACE (20) SPACEBAR
#define VK_SPACE 0x20
// VK_PRIOR (21) PAGE UP key
#define VK_PRIOR 0x21
// VK_NEXT (22) PAGE DOWN key
#define VK_NEXT 0x22
// VK_END (23) END key
#define VK_END 0x23
// VK_HOME (24) HOME key
#define VK_HOME 0x24
// VK_LEFT (25) LEFT ARROW key
#define VK_LEFT 0x25
// VK_UP (26) UP ARROW key
#define VK_UP 0x26
// VK_RIGHT (27) RIGHT ARROW key
#define VK_RIGHT 0x27
// VK_DOWN (28) DOWN ARROW key
#define VK_DOWN 0x28
// VK_SELECT (29) SELECT key
#define VK_SELECT 0x29
// VK_PRINT (2A) PRINT key
#define VK_PRINT 0x2A
// VK_EXECUTE (2B) EXECUTE key
#define VK_EXECUTE 0x2B
// VK_SNAPSHOT (2C) PRINT SCREEN key
#define VK_SNAPSHOT 0x2C
// VK_INSERT (2D) INS key
#define VK_INSERT 0x2D
// VK_DELETE (2E) DEL key
#define VK_DELETE 0x2E
// VK_HELP (2F) HELP key
#define VK_HELP 0x2F
// (30) 0 key
#define VK_0 0x30
// (31) 1 key
#define VK_1 0x31
// (32) 2 key
#define VK_2 0x32
// (33) 3 key
#define VK_3 0x33
// (34) 4 key
#define VK_4 0x34
// (35) 5 key;
#define VK_5 0x35
// (36) 6 key
#define VK_6 0x36
// (37) 7 key
#define VK_7 0x37
// (38) 8 key
#define VK_8 0x38
// (39) 9 key
#define VK_9 0x39
// (41) A key
#define VK_A 0x41
// (42) B key
#define VK_B 0x42
// (43) C key
#define VK_C 0x43
// (44) D key
#define VK_D 0x44
// (45) E key
#define VK_E 0x45
// (46) F key
#define VK_F 0x46
// (47) G key
#define VK_G 0x47
// (48) H key
#define VK_H 0x48
// (49) I key
#define VK_I 0x49
// (4A) J key
#define VK_J 0x4A
// (4B) K key
#define VK_K 0x4B
// (4C) L key
#define VK_L 0x4C
// (4D) M key
#define VK_M 0x4D
// (4E) N key
#define VK_N 0x4E
// (4F) O key
#define VK_O 0x4F
// (50) P key
#define VK_P 0x50
// (51) Q key
#define VK_Q 0x51
// (52) R key
#define VK_R 0x52
// (53) S key
#define VK_S 0x53
// (54) T key
#define VK_T 0x54
// (55) U key
#define VK_U 0x55
// (56) V key
#define VK_V 0x56
// (57) W key
#define VK_W 0x57
// (58) X key
#define VK_X 0x58
// (59) Y key
#define VK_Y 0x59
// (5A) Z key
#define VK_Z 0x5A
// VK_LWIN (5B) Left Windows key (Microsoft Natural keyboard)
#define VK_LWIN 0x5B
// VK_RWIN (5C) Right Windows key (Natural keyboard)
#define VK_RWIN 0x5C
// VK_APPS (5D) Applications key (Natural keyboard)
#define VK_APPS 0x5D
// VK_SLEEP (5F) Computer Sleep key
#define VK_SLEEP 0x5F
// VK_NUMPAD0 (60) Numeric keypad 0 key
#define VK_NUMPAD0 0x60
// VK_NUMPAD1 (61) Numeric keypad 1 key
#define VK_NUMPAD1 0x61
// VK_NUMPAD2 (62) Numeric keypad 2 key
#define VK_NUMPAD2 0x62
// VK_NUMPAD3 (63) Numeric keypad 3 key
#define VK_NUMPAD3 0x63
// VK_NUMPAD4 (64) Numeric keypad 4 key
#define VK_NUMPAD4 0x64
// VK_NUMPAD5 (65) Numeric keypad 5 key
#define VK_NUMPAD5 0x65
// VK_NUMPAD6 (66) Numeric keypad 6 key
#define VK_NUMPAD6 0x66
// VK_NUMPAD7 (67) Numeric keypad 7 key
#define VK_NUMPAD7 0x67
// VK_NUMPAD8 (68) Numeric keypad 8 key
#define VK_NUMPAD8 0x68
// VK_NUMPAD9 (69) Numeric keypad 9 key
#define VK_NUMPAD9 0x69
// VK_MULTIPLY (6A) Multiply key
#define VK_MULTIPLY 0x6A
// VK_ADD (6B) Add key
#define VK_ADD 0x6B
// VK_SEPARATOR (6C) Separator key
#define VK_SEPARATOR 0x6C
// VK_SUBTRACT (6D) Subtract key
#define VK_SUBTRACT 0x6D
// VK_DECIMAL (6E) Decimal key
#define VK_DECIMAL 0x6E
// VK_DIVIDE (6F) Divide key
#define VK_DIVIDE 0x6F
// VK_F1 (70) F1 key
#define VK_F1 0x70
// VK_F2 (71) F2 key
#define VK_F2 0x71
// VK_F3 (72) F3 key
#define VK_F3 0x72
// VK_F4 (73) F4 key
#define VK_F4 0x73
// VK_F5 (74) F5 key
#define VK_F5 0x74
// VK_F6 (75) F6 key
#define VK_F6 0x75
// VK_F7 (76) F7 key
#define VK_F7 0x76
// VK_F8 (77) F8 key
#define VK_F8 0x77
// VK_F9 (78) F9 key
#define VK_F9 0x78
// VK_F10 (79) F10 key
#define VK_F10 0x79
// VK_F11 (7A) F11 key
#define VK_F11 0x7A
// VK_F12 (7B) F12 key
#define VK_F12 0x7B
// VK_F13 (7C) F13 key
#define VK_F13 0x7C
// VK_F14 (7D) F14 key
#define VK_F14 0x7D
// VK_F15 (7E) F15 key
#define VK_F15 0x7E
// VK_F16 (7F) F16 key
#define VK_F16 0x7F
// VK_F17 (80H) F17 key
#define VK_F17 0x80
// VK_F18 (81H) F18 key
#define VK_F18 0x81
// VK_F19 (82H) F19 key
#define VK_F19 0x82
// VK_F20 (83H) F20 key
#define VK_F20 0x83
// VK_F21 (84H) F21 key
#define VK_F21 0x84
// VK_F22 (85H) F22 key
#define VK_F22 0x85
// VK_F23 (86H) F23 key
#define VK_F23 0x86
// VK_F24 (87H) F24 key
#define VK_F24 0x87
// VK_NUMLOCK (90) NUM LOCK key
#define VK_NUMLOCK 0x90
// VK_SCROLL (91) SCROLL LOCK key
#define VK_SCROLL 0x91
// VK_LSHIFT (A0) Left SHIFT key
#define VK_LSHIFT 0xA0
// VK_RSHIFT (A1) Right SHIFT key
#define VK_RSHIFT 0xA1
// VK_LCONTROL (A2) Left CONTROL key
#define VK_LCONTROL 0xA2
// VK_RCONTROL (A3) Right CONTROL key
#define VK_RCONTROL 0xA3
// VK_LMENU (A4) Left MENU key
#define VK_LMENU 0xA4
// VK_RMENU (A5) Right MENU key
#define VK_RMENU 0xA5
// VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
#define VK_BROWSER_BACK 0xA6
// VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
#define VK_BROWSER_FORWARD 0xA7
// VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
#define VK_BROWSER_REFRESH 0xA8
// VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
#define VK_BROWSER_STOP 0xA9
// VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
#define VK_BROWSER_SEARCH 0xAA
// VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
#define VK_BROWSER_FAVORITES 0xAB
// VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
#define VK_BROWSER_HOME 0xAC
// VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
#define VK_VOLUME_MUTE 0xAD
// VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
#define VK_VOLUME_DOWN 0xAE
// VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
#define VK_VOLUME_UP 0xAF
// VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
#define VK_MEDIA_NEXT_TRACK 0xB0
// VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
#define VK_MEDIA_PREV_TRACK 0xB1
// VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
#define VK_MEDIA_STOP 0xB2
// VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
#define VK_MEDIA_PLAY_PAUSE 0xB3
// VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
#define VK_MEDIA_LAUNCH_MAIL 0xB4
// VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
#define VK_MEDIA_LAUNCH_MEDIA_SELECT 0xB5
// VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
#define VK_MEDIA_LAUNCH_APP1 0xB6
// VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
#define VK_MEDIA_LAUNCH_APP2 0xB7
// VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
#define VK_OEM_1 0xBA
// VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
#define VK_OEM_PLUS 0xBB
// VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
#define VK_OEM_COMMA 0xBC
// VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
#define VK_OEM_MINUS 0xBD
// VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
#define VK_OEM_PERIOD 0xBE
// VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
#define VK_OEM_2 0xBF
// VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
#define VK_OEM_3 0xC0
// VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
#define VK_OEM_4 0xDB
// VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
#define VK_OEM_5 0xDC
// VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
#define VK_OEM_6 0xDD
// VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
#define VK_OEM_7 0xDE
// VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
#define VK_OEM_8 0xDF
// VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
#define VK_OEM_102 0xE2
// VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
#define VK_PROCESSKEY 0xE5
// VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
#define VK_PACKET 0xE7
// VK_ATTN (F6) Attn key
#define VK_ATTN 0xF6
// VK_CRSEL (F7) CrSel key
#define VK_CRSEL 0xF7
// VK_EXSEL (F8) ExSel key
#define VK_EXSEL 0xF8
// VK_EREOF (F9) Erase EOF key
#define VK_EREOF 0xF9
// VK_PLAY (FA) Play key
#define VK_PLAY 0xFA
// VK_ZOOM (FB) Zoom key
#define VK_ZOOM 0xFB
// VK_NONAME (FC) Reserved for future use
#define VK_NONAME 0xFC
// VK_PA1 (FD) PA1 key
#define VK_PA1 0xFD
// VK_OEM_CLEAR (FE) Clear key
#define VK_OEM_CLEAR 0xFE
#define VK_UNKNOWN 0
struct keymap_t {
unsigned int keysym;
unsigned char vk;
};
extern void MouseAction(double absX, double absY, int button, short wheel, Display *display);
extern void KeyAction(unsigned char vk, int up, Display *display);
#endif /* LINUX_EVENTS_H_ */

View File

@@ -0,0 +1,786 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "linux_kvm.h"
#include "meshcore/meshdefines.h"
#include "microstack/ILibParsers.h"
#include "microstack/ILibAsyncSocket.h"
#include "microstack/ILibAsyncServerSocket.h"
#include "microstack/ILibProcessPipe.h"
#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#ifdef _DAEMON
#define _GNU_SOURCE
#endif
int SCREEN_NUM = 0;
int SCREEN_WIDTH = 0;
int SCREEN_HEIGHT = 0;
int SCREEN_DEPTH = 0;
int TILE_WIDTH = 0;
int TILE_HEIGHT = 0;
int TILE_WIDTH_COUNT = 0;
int TILE_HEIGHT_COUNT = 0;
int COMPRESSION_RATIO = 0;
int FRAME_RATE_TIMER = 0;
struct tileInfo_t **g_tileInfo = NULL;
pthread_t kvmthread = (pthread_t)NULL;
Display *eventdisplay = NULL;
int g_remotepause = 0;
int g_pause = 0;
int g_restartcount = 0;
int g_totalRestartCount = 0;
int g_shutdown = 0;
int change_display = 0;
unsigned short current_display = 0;
pid_t g_slavekvm = 0;
int master2slave[2];
int slave2master[2];
FILE *logFile = NULL;
int g_enableEvents = 0;
extern void* tilebuffer;
void kvm_send_resolution()
{
char buffer[8];
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_SCREEN); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)8); // Write the size
((unsigned short*)buffer)[2] = (unsigned short)htons((unsigned short)SCREEN_WIDTH); // X position
((unsigned short*)buffer)[3] = (unsigned short)htons((unsigned short)SCREEN_HEIGHT); // Y position
// Write the reply to the pipe.
//fprintf(logFile, "Writing from slave in kvm_send_resolution\n");
if (write(slave2master[1], buffer, 8)) {}
fsync(slave2master[1]);
//fprintf(logFile, "Written %d bytes to master in kvm_send_resolution\n", written);
}
void kvm_send_display()
{
char buffer[5];
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_SET_DISPLAY); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)5); // Write the size
buffer[4] = current_display; // Display number
// Write the reply to the pipe.
//fprintf(logFile, "Writing from slave in kvm_send_display\n");
if (write(slave2master[1], buffer, 5)) {}
fsync(slave2master[1]);
//fprintf(logFile, "Written %d bytes to master in kvm_send_display\n", written);
}
#define BUFSIZE 65535
#ifdef _DAEMON
int kvm_relay_restart(int paused);
void* kvm_mainrelay(void* param)
{
int ptr = 0;
int endPointer = 0;
unsigned short size;
char* pchRequest;
ssize_t cbBytesRead = 0;
enum ILibAsyncSocket_SendStatus r;
if ((pchRequest = (char*)malloc(BUFSIZE)) == NULL) ILIBCRITICALEXIT(254);
g_restartcount = 0;
while (!g_shutdown)
{
//fprintf(logFile, "Reading from slave in kvm_mainrelay\n");
cbBytesRead = read(slave2master[0], pchRequest + endPointer, BUFSIZE - endPointer);
//fprintf(logFile, "Read %d bytes from slave in kvm_mainrelay\n", cbBytesRead);
if (g_shutdown == 0 && (cbBytesRead == -1 || cbBytesRead == 0)) { g_shutdown = 3; }
if (g_shutdown) { /*ILIBMESSAGE("KVMBREAK-R1\r\n");*/ break; }
endPointer += cbBytesRead;
// See how much we can safely send
while (endPointer - ptr > 4)
{
//type = ntohs(((unsigned short*)(pchRequest + ptr))[0]);
size = ntohs(((unsigned short*)(pchRequest + ptr))[1]);
if (ptr + size > endPointer) break;
ptr += size;
}
if (ptr > 0)
{
// Send any complete data
r = GuardPost_ILibKVMSendTo(pchRequest, ptr, ILibAsyncSocket_MemoryOwnership_USER);
if (r == ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR) { /*ILIBMESSAGE("KVMBREAK-R2\r\n");*/ break; }
else if (r == ILibAsyncSocket_NOT_ALL_DATA_SENT_YET)
{
g_pause = 1;
while (g_pause && !g_shutdown) { if (GuardPost_ILibKVMGetPendingBytesToSend() == 0) { g_pause = 0; } usleep(5000); }
}
// Move remaining data to the front of the buffer
if (endPointer - ptr > 0) memcpy(pchRequest, pchRequest + ptr, endPointer - ptr);
endPointer -= ptr;
ptr = 0;
}
if (g_shutdown || ((BUFSIZE - endPointer) == 0)) break;
}
if (g_slavekvm != 0)
{
int r;
kill(g_slavekvm, SIGKILL);
waitpid(g_slavekvm, &r, 0);
g_slavekvm = 0;
}
close(slave2master[0]);
close(master2slave[1]);
kvmthread = (pthread_t)NULL;
free(pchRequest);
if (g_shutdown == 3 && g_restartcount < 4 && g_totalRestartCount < 256)
{
g_restartcount++;
g_totalRestartCount++;
usleep(500000);
// fprintf(logFile, "Restarting again!\n");
if (kvm_relay_restart(0) == 0) GuardPost_ILibKVMDisconnect();
}
else
{
if (g_shutdown == 2) GuardPost_ILibKVMDisconnect();
}
return 0;
}
#endif
int kvm_server_inputdata(char* block, int blocklen);
void* kvm_mainloopinput(void* parm)
{
int ptr = 0;
int ptr2 = 0;
int len = 0;
char* pchRequest2[30000];
ssize_t cbBytesRead = 0;
while (!g_shutdown)
{
//fprintf(logFile, "Reading from master in kvm_mainloopinput\n");
cbBytesRead = read(master2slave[0], pchRequest2 + len, 30000 - len);
//fprintf(logFile, "Read %d bytes from master in kvm_mainloopinput\n", cbBytesRead);
if (cbBytesRead == -1 || cbBytesRead == 0 || g_shutdown) { /*ILIBMESSAGE("KVMBREAK-K1\r\n");*/ g_shutdown = 1; break; }
len += cbBytesRead;
ptr2 = 0;
while ((ptr2 = kvm_server_inputdata((char*)pchRequest2 + ptr, cbBytesRead - ptr)) != 0) { ptr += ptr2; }
if (ptr == len) { len = 0; ptr = 0; }
// TODO: else move the reminder.
}
return 0;
}
int lockfileCheckFn(const struct dirent *ent) {
if (ent == NULL) {
return 0;
}
if (!strncmp(ent->d_name, ".X", 2) && strcmp(ent->d_name, ".X11-unix") && strcmp(ent->d_name, ".XIM-unix")) {
return 1;
}
return 0;
}
void getAvailableDisplays(unsigned short **array, int *len) {
DIR *dir = NULL;
struct dirent **ent = NULL;
int i;
*array = NULL;
*len = 0;
dir = opendir("/tmp/");
if (dir != NULL) {
*len = scandir("/tmp/", &ent, lockfileCheckFn, alphasort);
if ((*array = (unsigned short *)malloc(*len)) == NULL) ILIBCRITICALEXIT(254);
for (i = 0; i < *len; i++) {
int dispNo = 0;
sscanf(ent[i]->d_name, ".X%d-lock", &dispNo);
(*array)[i] = (unsigned short)dispNo;
}
}
}
int getNextDisplay() {
DIR *dir = NULL;
struct dirent **ent = NULL;
int i, dispNo;
dir = opendir("/tmp/");
if (dir != NULL) {
int numDisplays = scandir("/tmp/", &ent, lockfileCheckFn, alphasort);
if (numDisplays == 0) { return -1; }
for (i = 0; i < numDisplays; i++) {
sscanf(ent[i]->d_name, ".X%d-lock", &dispNo);
if (dispNo == (int)current_display) {
break;
}
}
if (i == numDisplays) {
i = 0;
}
else {
i = (i + 1) % numDisplays;
}
sscanf(ent[i]->d_name, ".X%d-lock", &dispNo);
current_display = (unsigned short) dispNo;
closedir(dir);
}
else {
current_display = 0;
}
return 0;
}
int setDisplay(unsigned short display_no) {
char cmd[BUFSIZ] = "";
char authFile[BUFSIZ] = "";
FILE *pfile = NULL;
int dispNo;
sprintf(cmd, "ps aux 2>/dev/null | grep '/X.* :[0-9][0-9]* .*-auth' | egrep -v 'startx|xinit' | sed -e 's,^.*/X.* :\\([0-9][0-9]*\\) .* -auth \\([^ ][^ ]*\\).*$,\\1\\,\\2,' | grep '%d,'", display_no);
pfile = popen(cmd, "r");
if (pfile == NULL) {
return -1;
}
if (fscanf(pfile, "%d,%510s", &dispNo, authFile) != 2) {
fclose(pfile);
return -1;
}
fclose(pfile);
return setenv("XAUTHORITY", authFile, 1);
}
void kvm_send_display_list()
{
unsigned short *displays = NULL;
int len = 0;
char* buffer;
int totalSize = 0;
int i;
getAvailableDisplays(&displays, &len);
totalSize = 2 /*Type*/ + 2 /*length of packet*/ + 2 /*length of data*/ + (len * 2) /*Data*/ + 2 /* Current display */;
if ((buffer = (char*)malloc(totalSize)) == NULL) ILIBCRITICALEXIT(254);
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_GET_DISPLAYS); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)totalSize); // Write the size
((unsigned short*)buffer)[2] = (unsigned short)htons((unsigned short)len); // Length
for (i = 0; i < len; i++) {
((unsigned short*)buffer)[i + 3] = (unsigned short)htons(displays[i]);
}
((unsigned short*)buffer)[i + 3] = (unsigned short)htons((unsigned short)current_display); // Current display
// Write the reply to the pipe.
//fprintf(logFile, "Writing from slave in kvm_send_displays\n");
if (write(slave2master[1], buffer, totalSize)) {}
fsync(slave2master[1]);
//fprintf(logFile, "Written %d bytes to master in kvm_send_displays\n", written);
if (displays != NULL) free(displays);
}
int kvm_init(int displayNo)
{
//fprintf(logFile, "kvm_init called\n"); fflush(logFile);
int old_height_count = TILE_HEIGHT_COUNT;
int count = 0;
int dummy1, dummy2, dummy3;
char displayString[256] = "";
sprintf(displayString, ":%d", (int)displayNo);
while (setDisplay(displayNo) != 0 && count++ < 10);
if (count == 10) { return -1; }
count = 0;
eventdisplay = XOpenDisplay(displayString);
//fprintf(logFile, "XAUTHORITY is %s", getenv("XAUTHORITY")); fflush(logFile);
if (eventdisplay != NULL) { current_display = (unsigned short)displayNo; }
while (eventdisplay == NULL && count++ < 100) {
if (getNextDisplay() == -1) { return -1; }
sprintf(displayString, ":%d", (int)current_display);
if (setDisplay(current_display) != 0) { continue; }
eventdisplay = XOpenDisplay(displayString);
}
if (count == 100 && eventdisplay == NULL) { return -1; }
g_enableEvents = XQueryExtension(eventdisplay, "XTEST", &dummy1, &dummy2, &dummy3)? 1 : 0;
if (!g_enableEvents) { printf("FATAL::::Fake motion is not supported.\n\n\n"); }
SCREEN_NUM = DefaultScreen(eventdisplay);
SCREEN_HEIGHT = DisplayHeight(eventdisplay, SCREEN_NUM);
SCREEN_WIDTH = DisplayWidth(eventdisplay, SCREEN_NUM);
SCREEN_DEPTH = DefaultDepth(eventdisplay, SCREEN_NUM);
if (SCREEN_DEPTH < 15) {
// fprintf(stderr, "kvm_init: We do not support display depth < 15.");
return -1;
}
// Some magic numbers.
TILE_WIDTH = 32;
TILE_HEIGHT = 32;
COMPRESSION_RATIO = 50;
FRAME_RATE_TIMER = 100;
TILE_HEIGHT_COUNT = SCREEN_HEIGHT / TILE_HEIGHT;
TILE_WIDTH_COUNT = SCREEN_WIDTH / TILE_WIDTH;
if (SCREEN_WIDTH % TILE_WIDTH) { TILE_WIDTH_COUNT++; }
if (SCREEN_HEIGHT % TILE_HEIGHT) { TILE_HEIGHT_COUNT++; }
kvm_send_resolution();
kvm_send_display();
reset_tile_info(old_height_count);
return 0;
}
void CheckDesktopSwitch(int checkres)
{
if (change_display) {
kvm_init(current_display);
change_display = 0;
return;
}
}
int kvm_server_inputdata(char* block, int blocklen)
{
unsigned short type, size;
CheckDesktopSwitch(0);
// Decode the block header
if (blocklen < 4) return 0;
type = ntohs(((unsigned short*)(block))[0]);
size = ntohs(((unsigned short*)(block))[1]);
if (size > blocklen) return 0;
switch (type)
{
case MNG_KVM_KEY: // Key
{
if (size != 6) break;
if (g_enableEvents) KeyAction(block[5], block[4], eventdisplay);
break;
}
case MNG_KVM_MOUSE: // Mouse
{
int x, y;
short w = 0;
if (size == 10 || size == 12)
{
x = ((int)ntohs(((unsigned short*)(block))[3]));
y = ((int)ntohs(((unsigned short*)(block))[4]));
if (size == 12) w = ((short)ntohs(((short*)(block))[5]));
// printf("x:%d, y:%d, b:%d, w:%d\n", x, y, block[5], w);
if (g_enableEvents) MouseAction(x, y, block[5], w, eventdisplay);
}
break;
}
case MNG_KVM_COMPRESSION: // Compression
{
if (size != 6) break;
set_tile_compression((int)block[4], (int)block[5]);
COMPRESSION_RATIO = 100;
break;
}
case MNG_KVM_REFRESH: // Refresh
{
int row, col;
if (size != 4) break;
if (g_tileInfo == NULL) {
if ((g_tileInfo = (struct tileInfo_t **) malloc(TILE_HEIGHT_COUNT * sizeof(struct tileInfo_t *))) == NULL) ILIBCRITICALEXIT(254);
for (row = 0; row < TILE_HEIGHT_COUNT; row++) {
if ((g_tileInfo[row] = (struct tileInfo_t *) malloc(TILE_WIDTH_COUNT * sizeof(struct tileInfo_t))) == NULL) ILIBCRITICALEXIT(254);
}
}
for (row = 0; row < TILE_HEIGHT_COUNT; row++) {
for (col = 0; col < TILE_WIDTH_COUNT; col++) {
g_tileInfo[row][col].crc = 0xFF;
g_tileInfo[row][col].flag = 0;
}
}
break;
}
case MNG_KVM_PAUSE: // Pause
{
if (size != 5) break;
g_remotepause = block[4];
break;
}
case MNG_KVM_GET_DISPLAYS:
{
kvm_send_display_list();
break;
}
case MNG_KVM_SET_DISPLAY:
{
if (ntohs(((unsigned short*)(block))[2]) == current_display) { break; } // Don't do anything
current_display = ntohs(((unsigned short*)(block))[2]);
change_display = 1;
break;
}
case MNG_KVM_FRAME_RATE_TIMER:
{
int fr = ((int)ntohs(((unsigned short*)(block))[2]));
if (fr > 20 && fr < 2000) FRAME_RATE_TIMER = fr;
break;
}
}
return size;
}
int kvm_relay_feeddata(char* buf, int len)
{
ssize_t written = 0;
// Write the reply to the pipe.
//fprintf(logFile, "Writing to slave in kvm_relay_feeddata\n");
written = write(
master2slave[1], // handle to pipe
buf, // buffer to write from
len);
fsync(master2slave[1]);
//fprintf(logFile, "Written %d bytes to slave in kvm_relay_feeddata\n", written);
if (written == -1) return 0;
if (len != (int)written) return written;
return len;
}
// Set the KVM pause state
void kvm_pause(int pause)
{
g_pause = pause;
}
void* kvm_server_mainloop(void* parm)
{
int x, y, height, width, r, c, count = 0;
long long desktopsize = 0;
long long tilesize = 0;
long long prev_timestamp = 0;
long long cur_timestamp = 0;
long long time_diff = 50;
struct timeb tp;
void *desktop = NULL;
XImage *image = NULL;
eventdisplay = NULL;
Display *imagedisplay = NULL;
void *buf = NULL;
char displayString[256] = "";
int screen_height, screen_width, screen_depth, screen_num;
ssize_t written;
XShmSegmentInfo shminfo;
// Init the kvm
//fprintf(logFile, "Before kvm_init.\n"); fflush(logFile);
if (kvm_init(0) != 0) { return (void*)-1; }
kvm_send_display_list();
//fprintf(logFile, "After kvm_init.\n"); fflush(logFile);
g_shutdown = 0;
pthread_create(&kvmthread, NULL, kvm_mainloopinput, parm);
//fprintf(logFile, "Created the kvmthread.\n"); fflush(logFile);
while (!g_shutdown) {
//printf("KVM/Loop");
ftime(&tp);
cur_timestamp = tp.time * 1000 + tp.millitm;
if (prev_timestamp != 0)
{
time_diff = (FRAME_RATE_TIMER - (cur_timestamp - prev_timestamp));
if (time_diff < 20) { time_diff = 20; }
}
usleep(time_diff * 1000);
prev_timestamp = cur_timestamp;
//printf("...\n");
for (r = 0; r < TILE_HEIGHT_COUNT; r++) {
for (c = 0; c < TILE_WIDTH_COUNT; c++) {
g_tileInfo[r][c].flag = TILE_TODO;
}
}
//fprintf(logFile, "Before CheckDesktopSwitch.\n"); fflush(logFile);
CheckDesktopSwitch(1);
//fprintf(logFile, "After CheckDesktopSwitch.\n"); fflush(logFile);
setDisplay(current_display);
sprintf(displayString, ":%d", (int)current_display);
imagedisplay = XOpenDisplay(displayString);
count = 0;
if (imagedisplay == NULL && count++ < 100) {
change_display = 1;
if (getNextDisplay() == -1) { return (void*)-1; }
//fprintf(logFile, "Before kvm_init1.\n"); fflush(logFile);
kvm_init(current_display);
//fprintf(logFile, "After kvm_init1.\n"); fflush(logFile);
change_display = 0;
if (image != NULL) { XDestroyImage(image); image = NULL; }
continue;
}
if (count == 100 && imagedisplay == NULL) { g_shutdown = 1; break; }
screen_num = DefaultScreen(imagedisplay);
screen_height = DisplayHeight(imagedisplay, screen_num);
screen_width = DisplayWidth(imagedisplay, screen_num);
screen_depth = DefaultDepth(imagedisplay, screen_num);
if (screen_depth <= 15) {
//fprintf(logFile, "We do not support display depth %d < 15.\n", screen_depth); fflush(logFile);
//fprintf(stderr, "We do not support display depth <= 15.");
break;
}
if ((SCREEN_HEIGHT != screen_height || SCREEN_WIDTH != screen_width || SCREEN_DEPTH != screen_depth || SCREEN_NUM != screen_num))
{
kvm_init(current_display);
if (image != NULL) { XDestroyImage(image); image = NULL; }
continue;
}
image = XShmCreateImage(imagedisplay,
DefaultVisual(imagedisplay, screen_num), // Use a correct visual. Omitted for brevity
screen_depth,
ZPixmap, NULL, &shminfo, screen_width, screen_height);
shminfo.shmid = shmget(IPC_PRIVATE,
image->bytes_per_line * image->height,
IPC_CREAT | 0777);
shminfo.shmaddr = image->data = shmat(shminfo.shmid, 0, 0);
shminfo.readOnly = False;
XShmAttach(imagedisplay, &shminfo);
XShmGetImage(imagedisplay,
RootWindowOfScreen(DefaultScreenOfDisplay(imagedisplay)),
image,
0,
0,
AllPlanes);
//image = XGetImage(imagedisplay,
// RootWindowOfScreen(DefaultScreenOfDisplay(imagedisplay))
// , 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, AllPlanes, ZPixmap);
if (image == NULL) {
g_shutdown = 1;
}
else {
getScreenBuffer((char **)&desktop, &desktopsize, image);
for (y = 0; y < TILE_HEIGHT_COUNT; y++) {
for (x = 0; x < TILE_WIDTH_COUNT; x++) {
height = TILE_HEIGHT * y;
width = TILE_WIDTH * x;
if (g_shutdown) { x = TILE_WIDTH_COUNT; y = TILE_HEIGHT_COUNT; break; }
if (g_tileInfo[y][x].flag == TILE_SENT || g_tileInfo[y][x].flag == TILE_DONT_SEND) {
continue;
}
getTileAt(width, height, &buf, &tilesize, desktop, desktopsize, y, x);
if (buf && !g_shutdown)
{
// Write the reply to the pipe.
//fprintf(logFile, "Writing to master in kvm_server_mainloop\n");
written = write(slave2master[1], buf, tilesize);
fsync(slave2master[1]);
//fprintf(logFile, "Wrote %d bytes to master in kvm_server_mainloop\n", written);
free(buf);
if (written == -1) { /*ILIBMESSAGE("KVMBREAK-K2\r\n");*/ g_shutdown = 1; height = SCREEN_HEIGHT; width = SCREEN_WIDTH; break; }
}
}
}
}
XShmDetach(imagedisplay, &shminfo);
XDestroyImage(image); image = NULL;
shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, 0);
if (imagedisplay != NULL)
{
XCloseDisplay(imagedisplay);
imagedisplay = NULL;
}
}
close(slave2master[1]);
close(master2slave[0]);
slave2master[1] = 0;
master2slave[0] = 0;
XCloseDisplay(eventdisplay);
eventdisplay = NULL;
pthread_join(kvmthread, NULL);
kvmthread = (pthread_t)NULL;
if (g_tileInfo != NULL)
{
for (r = 0; r < TILE_HEIGHT_COUNT; r++) { free(g_tileInfo[r]); }
free(g_tileInfo);
g_tileInfo = NULL;
}
if(tilebuffer != NULL) { free(tilebuffer); tilebuffer = NULL; }
return (void*)0;
}
void kvm_relay_readSink(ILibProcessPipe_Pipe sender, char *buffer, int bufferLen, int* bytesConsumed)
{
ILibKVM_WriteHandler writeHandler = (ILibKVM_WriteHandler)((void**)ILibMemory_GetExtraMemory(sender, ILibMemory_ILibProcessPipe_Pipe_CONTAINERSIZE))[0];
void *reserved = ((void**)ILibMemory_GetExtraMemory(sender, ILibMemory_ILibProcessPipe_Pipe_CONTAINERSIZE))[1];
unsigned short size;
if (bufferLen > 4)
{
size = ntohs(((unsigned short*)(buffer))[1]);
if (size <= bufferLen)
{
//printf("KVM Data: %u bytes\n", size);
*bytesConsumed = size;
writeHandler(buffer, size, reserved);
return;
}
}
*bytesConsumed = 0;
}
void* kvm_relay_restart(int paused, void *processPipeMgr, ILibKVM_WriteHandler writeHandler, void *reserved)
{
int r;
int count = 0;
ILibProcessPipe_Pipe slave_out;
if (g_slavekvm != 0)
{
kill(g_slavekvm, SIGKILL);
waitpid(g_slavekvm, &r, 0);
g_slavekvm = 0;
}
r = pipe(slave2master);
r = pipe(master2slave);
slave_out = ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(processPipeMgr, slave2master[0], 2 * sizeof(void*));
((void**)ILibMemory_GetExtraMemory(slave_out, ILibMemory_ILibProcessPipe_Pipe_CONTAINERSIZE))[0] = writeHandler;
((void**)ILibMemory_GetExtraMemory(slave_out, ILibMemory_ILibProcessPipe_Pipe_CONTAINERSIZE))[1] = reserved;
UNREFERENCED_PARAMETER(r);
do
{
g_slavekvm = fork();
if (g_slavekvm == -1 && paused == 0) sleep(2); // If we can't launch the child process, retry in a little while.
}
while (g_slavekvm == -1 && paused == 0 && ++count < 10);
if (g_slavekvm == -1) return(NULL);
if (g_slavekvm == 0) //slave
{
close(slave2master[0]);
close(master2slave[1]);
logFile = fopen("/tmp/slave", "w");
//fprintf(logFile, "Starting kvm_server_mainloop\n");
kvm_server_mainloop((void*)0);
return(NULL);
}
else { //master
close(slave2master[1]);
close(master2slave[0]);
logFile = fopen("/tmp/master", "w");
// We will asyncronously read from the pipe, so we can just return
ILibProcessPipe_Pipe_AddPipeReadHandler(slave_out, 65535, kvm_relay_readSink);
return(slave_out);
}
}
// Setup the KVM session. Return 1 if ok, 0 if it could not be setup.
void* kvm_relay_setup(void *processPipeMgr, ILibKVM_WriteHandler writeHandler, void *reserved)
{
if (kvmthread != (pthread_t)NULL || g_slavekvm != 0) return 0;
g_restartcount = 0;
return kvm_relay_restart(1, processPipeMgr, writeHandler, reserved);
}
// Force a KVM reset & refresh
void kvm_relay_reset()
{
char buffer[4];
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_REFRESH); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)4); // Write the size
kvm_relay_feeddata(buffer, 4);
}
// Clean up the KVM session.
void kvm_cleanup()
{
int code;
g_shutdown = 1;
if (master2slave[1] != 0 && g_slavekvm != 0)
{
kill(g_slavekvm, SIGKILL);
waitpid(g_slavekvm, &code, 0);
g_slavekvm = 0;
}
g_totalRestartCount = 0;
}

View File

@@ -0,0 +1,47 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef LINUX_KVM_H_
#define LINUX_KVM_H_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/timeb.h>
#include <unistd.h>
#include <linux/stat.h>
#include "linux_tile.h"
#include "linux_events.h"
#include "microstack/ILibParsers.h"
typedef ILibTransport_DoneState(*ILibKVM_WriteHandler)(char *buffer, int bufferLen, void *reserved);
int kvm_relay_feeddata(char* buf, int len);
void kvm_pause(int pause);
void* kvm_relay_setup(void *processPipeMgr, ILibKVM_WriteHandler writeHandler, void *reserved);
void kvm_relay_reset();
void kvm_cleanup();
#endif /* LINUX_KVM_H_ */

View File

@@ -0,0 +1,465 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "linux_tile.h"
#include "meshcore/meshdefines.h"
#include "microstack/ILibParsers.h"
extern int SCREEN_NUM;
extern int SCREEN_WIDTH;
extern int SCREEN_HEIGHT;
extern int SCREEN_DEPTH;
extern int TILE_WIDTH;
extern int TILE_HEIGHT;
extern int TILE_WIDTH_COUNT;
extern int TILE_HEIGHT_COUNT;
extern int COMPRESSION_RATIO;
extern struct tileInfo_t **g_tileInfo;
extern unsigned char *jpeg_buffer;
extern int jpeg_buffer_length;
int tilebuffersize = 0;
void* tilebuffer = NULL;
int COMPRESSION_QUALITY = 50;
/******************************************************************************
* INTERNAL FUNCTIONS
******************************************************************************/
//Extracts the required tile buffer from the desktop buffer
int get_tile_buffer(int x, int y, void **buffer, long long bufferSize, void *desktop, long long desktopsize, int tilewidth, int tileheight)
{
char *target = *buffer;
int height = 0;
for (height = y; height < y + tileheight; height++) {
memcpy(target, (const void *)(((char *)desktop) + (3 * ((height * adjust_screen_size(SCREEN_WIDTH)) + x))), (size_t)(tilewidth * 3));
target = (char *) (target + (3 * tilewidth));
}
return 0;
}
//This function returns 0 and *buffer != NULL if everything was good. retval = jpegsize if the captured image was too large.
int calc_opt_compr_send(int x, int y, int captureWidth, int captureHeight, void* desktop, long long desktopsize, void ** buffer, long long *bufferSize)
{
*buffer = NULL;
*bufferSize = 0;
// Make sure a tile buffer is available. Most of the time, this is skipped.
if (tilebuffersize != captureWidth * captureHeight * 3)
{
if (tilebuffer != NULL) free(tilebuffer);
tilebuffersize = captureWidth * captureHeight * 3;
if ((tilebuffer = malloc(tilebuffersize)) == NULL) return 0;
}
//Get the final coalesced tile
get_tile_buffer(x, y, &tilebuffer, tilebuffersize, desktop, desktopsize, captureWidth, captureHeight);
write_JPEG_buffer(tilebuffer, captureWidth, captureHeight, COMPRESSION_QUALITY);
if (jpeg_buffer_length > 65500) {
return jpeg_buffer_length;
}
else {
return 0;
}
}
#if 0
void dump32bit (const XImage * input)
{
int row, col;
static char head[256];
static FILE *fp2 = NULL;
char *ptr2, *output;
long size;
register unsigned int
rm = input->red_mask,
gm = input->green_mask,
bm = input->blue_mask,
rs = 16,
gs = 8,
bs = 0, *p32 = (unsigned int *) input->data;
sprintf (head, "P6\n%d %d\n%d\n", input->width, input->height, 255);
size = ((input->bytes_per_line * input->height) / 4) * 3;
output = malloc (size);
ptr2 = output;
for (row = 0; row < input->height; row++) {
for (col = 0; col < input->width; col++) {
*output++ = ((*p32 & rm) >> rs);
*output++ = ((*p32 & gm) >> gs);
*output++ = ((*p32 & bm) >> bs);
p32++; // ignore alpha values
}
//
// eat padded bytes, for better speed we use shifting,
// (bytes_per_line - bits_per_pixel / 8 * width ) / 4
//
p32 += (input->bytes_per_line - (input->bits_per_pixel >> 3)
* input->width) >> 2;
}
fp2 = fopen ("/tmp/pic.rgb.pnm", "w");
fwrite (head, strlen (head), 1, fp2);
fwrite (ptr2, size, 1, fp2);
fclose (fp2);
free (ptr2);
}
#endif
// Really fast CRC-like method. Used for the KVM.
int util_crc(int x, int y, long long bufferSize, void *desktop, long long desktopsize, int tilewidth, int tileheight)
{
int hval = 0;
int *bp = NULL;
int *be = NULL;
int height = 0;
for (height = y; height < y + tileheight; height++) {
bp = (int *)(((char *)desktop) + (3 * ((height * adjust_screen_size(SCREEN_WIDTH)) + x)));
be = (int *)(((char *)desktop) + (3 * ((height * adjust_screen_size(SCREEN_WIDTH)) + x + tilewidth)));
while ((bp + 1) <= be)
{
// hval *= 0x01000193;
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
hval ^= *bp++;
}
if (be - bp >= 0) {
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
hval ^= (*(int *)(((char *)be) - 3));
}
}
return hval;
}
/******************************************************************************
* EXTERNAL FUNCTIONS
******************************************************************************/
// Adjusts the screen size(width or height) to be exactly divisible by TILE_WIDTH
int adjust_screen_size(int pixles)
{
int extra = pixles % TILE_WIDTH; //Assuming tile width and height will remain the same.
if (extra != 0) { return pixles + TILE_WIDTH - extra; }
return pixles;
}
// Reset the tile info structure
int reset_tile_info(int old_height_count) {
int row, col;
if (g_tileInfo != NULL) {
for (row = 0; row < old_height_count; row++) {
free(g_tileInfo[row]);
}
free(g_tileInfo);
g_tileInfo = NULL;
}
if ((g_tileInfo = (struct tileInfo_t **) malloc (sizeof(struct tileInfo_t *) * TILE_HEIGHT_COUNT)) == NULL) ILIBCRITICALEXIT(254);
for (row = 0; row < TILE_HEIGHT_COUNT; row++) {
if ((g_tileInfo[row] = (struct tileInfo_t *)calloc(TILE_WIDTH_COUNT, sizeof(struct tileInfo_t))) == NULL) ILIBCRITICALEXIT(254);
for (col = 0; col < TILE_WIDTH_COUNT; col++) {
g_tileInfo[row][col].crc = 0xff;
}
}
return 0;
}
//Fetches the encoded jpeg tile at the given location. The neighboring tiles are coalesced to form a larger jpeg before returning.
int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop, long long desktopsize, int row, int col)
{
int CRC, rcol, i, r, c;
int rightcol = col; //Used in coalescing. Indicates the rightmost column to be coalesced.
int botrow = row; //Used in coalescing. Indicates the bottom most row to be coalesced.
int r_x = x;
int r_y = y;
int captureWidth = TILE_WIDTH;
int captureHeight = TILE_HEIGHT;
*buffer = NULL; // If anything fails, this will be the indication.
*bufferSize = 0;
if (g_tileInfo[row][col].flag == TILE_TODO) { //First check whether the tile-crc needs to be calculated or not.
if ((CRC = util_crc(x, y, TILE_HEIGHT * TILE_WIDTH * 3, desktop, desktopsize, TILE_WIDTH, TILE_HEIGHT)) == g_tileInfo[row][col].crc) return 0;
g_tileInfo[row][col].crc = CRC; //Update the tile CRC in the global data structure.
}
g_tileInfo[row][col].flag = TILE_MARKED_NOT_SENT;
//COALESCING SECTION
// First got to the right most changed tile and record it
while (rightcol + 1 < TILE_WIDTH_COUNT) {
rightcol++;
r_x = rightcol * TILE_WIDTH;
CRC = g_tileInfo[row][rightcol].crc;
if (g_tileInfo[row][rightcol].flag == TILE_TODO) {
CRC = util_crc(r_x, y, TILE_HEIGHT * TILE_WIDTH * 3, desktop, desktopsize, TILE_WIDTH, TILE_HEIGHT);
}
if (CRC != g_tileInfo[row][rightcol].crc || g_tileInfo[row][rightcol].flag == TILE_MARKED_NOT_SENT) { //If the tile has changed, increment the capturewidth.
g_tileInfo[row][rightcol].crc = CRC;
//Here we check whether the size of the coalesced bitmap is greater than the threshold (65500)
if ((captureWidth + TILE_WIDTH) * TILE_HEIGHT * 3 / COMPRESSION_RATIO > 65500) {
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
--rightcol;
break;
}
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
captureWidth += TILE_WIDTH;
}
else {
g_tileInfo[row][rightcol].flag = TILE_DONT_SEND;
--rightcol;
break;
}
}
//int TOLERANCE = (rightcol - col) / 3;
// Now go to the bottom tiles, check if they have changed and record them
while ((botrow + 1 < TILE_HEIGHT_COUNT) && ((captureHeight + TILE_HEIGHT) * captureWidth * 3 / COMPRESSION_RATIO <= 65500)) {
botrow++;
r_y = botrow * TILE_HEIGHT;
int fail = 0;
r_x = x;
//int missCount = 0;
for (rcol = col; rcol <= rightcol; rcol++) {
CRC = g_tileInfo[botrow][rcol].crc;
if (g_tileInfo[botrow][rcol].flag == TILE_TODO) {
CRC = util_crc(r_x, r_y, TILE_HEIGHT * TILE_WIDTH * 3, desktop, desktopsize, TILE_WIDTH, TILE_HEIGHT);
}
if (CRC != g_tileInfo[botrow][rcol].crc || g_tileInfo[botrow][rcol].flag == TILE_MARKED_NOT_SENT) {
g_tileInfo[botrow][rcol].flag = TILE_MARKED_NOT_SENT;
g_tileInfo[botrow][rcol].crc = CRC;
r_x += TILE_WIDTH;
}
else {
/*//Keep this part commented. Adding tolerance adds to the complexity of this code.
missCount++;
if (missCount > TOLERANCE) {
fail = 1;
for (int i = col; i < rcol; i++) {
if (g_tileInfo[botrow][i].flag == TILE_SKIPPED) {
g_tileInfo[botrow][i].flag = TILE_DONT_SEND;
}
else {
g_tileInfo[botrow][i].flag = TILE_MARKED_NOT_SENT;
}
}
g_tileInfo[botrow][rcol].flag = TILE_DONT_SEND;
botrow--;
break;
}
else {
g_tileInfo[botrow][rcol].flag = TILE_SKIPPED;
g_tileInfo[botrow][rcol].crc = CRC;
r_x += TILE_WIDTH;
}*/
fail = 1;
for (i = col; i < rcol; i++) {
g_tileInfo[botrow][i].flag = TILE_MARKED_NOT_SENT;
}
g_tileInfo[botrow][rcol].flag = TILE_DONT_SEND;
botrow--;
break;
}
}
if (!fail) {
captureHeight += TILE_HEIGHT;
}
else {
break;
}
}
int retval = 0;
int firstTime = 1;
//This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time.
do {
//retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent.
retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize);
if (retval != 0) {
if (firstTime) {
//Re-adjust the compression ratio.
COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO/(double)retval) * 60000);//Magic number: 60000 ~= 65500
if (COMPRESSION_RATIO <= 1) {
COMPRESSION_RATIO = 2;
}
firstTime = 0;
}
if (botrow > row) { //First time, try reducing the height.
botrow = row + ((botrow - row + 1) / 2);
captureHeight = (botrow - row + 1) * TILE_HEIGHT;
}
else if (rightcol > col){ //If it is not possible, reduce the width
rightcol = col + ((rightcol - col + 1) / 2);
captureWidth = (rightcol - col + 1) * TILE_WIDTH;
}
else { //This never happens in any case.
retval = 0;
break;
}
}
} while (retval != 0);
//Set the flags to TILE_SENT
if (jpeg_buffer != NULL) {
*bufferSize = jpeg_buffer_length + 8;
if ((*buffer = malloc(*bufferSize)) == NULL) ILIBCRITICALEXIT(254);
((unsigned short*)*buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_PICTURE); // Write the type
((unsigned short*)*buffer)[1] = (unsigned short)htons((unsigned short)*bufferSize); // Write the size
((unsigned short*)*buffer)[2] = (unsigned short)htons((unsigned short)x); // X position
((unsigned short*)*buffer)[3] = (unsigned short)htons((unsigned short)y); // Y position
memcpy((char *)(*buffer) + 8, jpeg_buffer, jpeg_buffer_length);
free(jpeg_buffer);
jpeg_buffer = NULL;
jpeg_buffer_length = 0;
for (r = row; r <= botrow; r++) {
for (c = col; c <= rightcol; c++) {
g_tileInfo[r][c].flag = TILE_SENT;
}
}
}
return retval;
}
// Get screen buffer from the XImage structure
int getScreenBuffer(char **desktop, long long *desktopsize, XImage *image)
{
long long size = adjust_screen_size(SCREEN_WIDTH) * adjust_screen_size(SCREEN_HEIGHT) * 3;
int row, col, i, width_padding_size = 0, height_padding_size = 0;
char *output;
register unsigned char* tmpPtr2 = (unsigned char *)image->data;
register unsigned short* tmpPtr3 = (unsigned short *)image->data;
register unsigned int
rm = image->red_mask,
gm = image->green_mask,
bm = image->blue_mask,
rs = 16,
gs = 8,
bs = 0, *tmpPtr = (unsigned int *) image->data;
int bpp = image->bits_per_pixel;
if (*desktopsize != size) {
if (*desktop != NULL) { free(*desktop); }
*desktopsize = size;
if ((*desktop = (char *) malloc (*desktopsize)) == NULL) ILIBCRITICALEXIT(254);
}
if (bpp == 16) {
rs = 11;
gs = 5;
}
output = *desktop;
for (row = 0; row < image->height; row++) {
for (col = 0; col < image->width; col++) {
if (bpp == 16) {
*output++ = ((*tmpPtr3 >> rs) & 0x01f) << 3;
*output++ = ((*tmpPtr3 >> gs) & 0x03f) << 2;
*output++ = ((*tmpPtr3 >> bs) & 0x01f) << 3;
tmpPtr3++;
}
else if (bpp == 24) {
*output++ = *(tmpPtr2 + 2);
*output++ = *(tmpPtr2 + 1);
*output++ = *tmpPtr2;
tmpPtr2 += 3;
}
else {
*output++ = ((*tmpPtr & rm) >> rs);
*output++ = ((*tmpPtr & gm) >> gs);
*output++ = ((*tmpPtr & bm) >> bs);
tmpPtr = (unsigned int *) (((char *)tmpPtr) + (image->bits_per_pixel >> 3));
//tmpPtr++; // ignore alpha values
}
}
//
// eat padded bytes, for better speed we use shifting,
// (bytes_per_line - bits_per_pixel / 8 * width ) / 4
tmpPtr += (image->bytes_per_line - (image->bits_per_pixel >> 3)
* image->width) >> 2;
width_padding_size = (adjust_screen_size(SCREEN_WIDTH) - image->width) * 3;
if (width_padding_size != 0) {
for (i = 0; i < width_padding_size; i++) {
*output++ = 0;
}
}
}
height_padding_size = adjust_screen_size(SCREEN_HEIGHT) - image->height;
if (height_padding_size != 0) {
for (row = 0; row < height_padding_size; row++) {
for (col = 0; col < (image->width * 3) + width_padding_size; col++) {
*output++ = 0;
}
}
}
return 0;
}
// Set the compression quality
void set_tile_compression(int type, int level)
{
if (level > 0 && level <= 100) {
COMPRESSION_QUALITY = level;
}
else {
COMPRESSION_QUALITY = 60;
}
// TODO Make sure the all the types are handled. We ignore the type variable for now.
}

View File

@@ -0,0 +1,47 @@
/*
Copyright 2010 - 2011 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef LINUX_TILE_H_
#define LINUX_TILE_H_
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <string.h>
#include <arpa/inet.h>
#include "linux_compression.h"
enum TILE_FLAGS_ENUM {
TILE_TODO, //The tile CRC needs to be calculated.
TILE_SENT, //CRC has been calculated and the tile has been sent.
TILE_MARKED_NOT_SENT, //CRC has been calculated, but the tile was not sent.
TILE_DONT_SEND //CRC has been calculated, tile need not be sent.
//TILE_SKIPPED //CRC has been calculated, tile need not be sent, but was skipped to include a greater region
};
struct tileInfo_t {
int crc;
enum TILE_FLAGS_ENUM flag;
};
extern int reset_tile_info(int old_height_count);
extern int adjust_screen_size(int pixles);
extern int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop, long long desktopsize, int row, int col);
extern int getScreenBuffer(char **desktop, long long *desktopsize, XImage *image);
extern void set_tile_compression(int type, int level);
#endif /* LINUX_TILE_H_ */

View File

@@ -0,0 +1,248 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(_LINKVM)
#include <Windows.h>
#include <Winuser.h>
#include <stdio.h>
#include "input.h"
/*
#if defined(WIN32) && !defined(_WIN32_WCE)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
*/
/*
MOUSEEVENTF_LEFTDOWN 0x0002
MOUSEEVENTF_RIGHTDOWN 0x0008
MOUSEEVENTF_MIDDLEDOWN 0x0020
MOUSEEVENTF_LEFTUP 0x0004
MOUSEEVENTF_RIGHTUP 0x0010
MOUSEEVENTF_MIDDLEUP 0x0040
*/
void MouseAction(double absX, double absY, int button, short wheel)
{
INPUT mouse;
mouse.type = INPUT_MOUSE;
mouse.mi.dx = (long) absX;
mouse.mi.dy = (long) absY;
mouse.mi.mouseData = wheel;
mouse.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_VIRTUALDESK | MOUSEEVENTF_MOVE | button;
if (wheel) mouse.mi.dwFlags |= MOUSEEVENTF_WHEEL;
mouse.mi.time = 0;
mouse.mi.dwExtraInfo = 0;
SendInput(1, &mouse, sizeof(INPUT));
}
// Handling keyboard Input
// MSDN References:
// Keyboard input structure: http://msdn.microsoft.com/en-us/library/ms646271%28v=VS.85%29.aspx
// Virtual key-codes: http://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx
void KeyAction(unsigned char keycode, int up)
{
HWND windowHandle = GetForegroundWindow();
INPUT key;
if (windowHandle == NULL) return;
SetForegroundWindow(windowHandle);
key.type = INPUT_KEYBOARD;
key.ki.wVk = keycode;
key.ki.dwFlags = 0;
if (up == 1) key.ki.dwFlags = KEYEVENTF_KEYUP; // 1 = UP
else if (up == 3) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; // 3 = EXUP
else if (up == 4) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; // 4 = EXDOWN
key.ki.time = 0;
key.ki.wScan = (WORD)MapVirtualKey((UINT)keycode, MAPVK_VK_TO_VSC); // This is required to make RDP client work.
key.ki.dwExtraInfo = 0;
SendInput(1, &key, sizeof(INPUT));
}
// Windows 8 Touch Related Support
#define MAX_TOUCH_COUNT 256
#define TOUCH_FEEDBACK_DEFAULT 0x1
#define TOUCH_FEEDBACK_INDIRECT 0x2
#define TOUCH_FEEDBACK_NONE 0x3
#if WINVER < 0x0602 // If compiled on anything below Windows8
typedef enum _POINTER_BUTTON_CHANGE_TYPE { // This is a guess as what these values are, check for real values for this enum
POINTER_CHANGE_NONE = 0x00000000,
POINTER_CHANGE_FIRSTBUTTON_DOWN = 0x00000001,
POINTER_CHANGE_FIRSTBUTTON_UP = 0x00000002,
POINTER_CHANGE_SECONDBUTTON_DOWN = 0x00000004,
POINTER_CHANGE_SECONDBUTTON_UP = 0x00000010,
POINTER_CHANGE_THIRDBUTTON_DOWN = 0x00000020,
POINTER_CHANGE_THIRDBUTTON_UP = 0x00000040,
POINTER_CHANGE_FOURTHBUTTON_DOWN = 0x00000100,
POINTER_CHANGE_FOURTHBUTTON_UP = 0x00000200,
POINTER_CHANGE_FIFTHBUTTON_DOWN = 0x00000400,
POINTER_CHANGE_FIFTHBUTTON_UP = 0x00001000
} POINTER_BUTTON_CHANGE_TYPE;
typedef enum tagPOINTER_FLAGS {
POINTER_FLAG_NONE = 0x00000000,
POINTER_FLAG_NEW = 0x00000001,
POINTER_FLAG_INRANGE = 0x00000002,
POINTER_FLAG_INCONTACT = 0x00000004,
POINTER_FLAG_FIRSTBUTTON = 0x00000010,
POINTER_FLAG_SECONDBUTTON = 0x00000020,
POINTER_FLAG_THIRDBUTTON = 0x00000040,
POINTER_FLAG_FOURTHBUTTON = 0x00000080,
POINTER_FLAG_FIFTHBUTTON = 0x00000100,
POINTER_FLAG_PRIMARY = 0x00002000,
POINTER_FLAG_CONFIDENCE = 0x000004000,
POINTER_FLAG_CANCELED = 0x000008000,
POINTER_FLAG_DOWN = 0x00010000,
POINTER_FLAG_UPDATE = 0x00020000,
POINTER_FLAG_UP = 0x00040000,
POINTER_FLAG_WHEEL = 0x00080000,
POINTER_FLAG_HWHEEL = 0x00100000,
POINTER_FLAG_CAPTURECHANGED = 0x00200000
} POINTER_FLAGS;
typedef enum tagPOINTER_INPUT_TYPE {
PT_POINTER = 0x00000001,
PT_TOUCH = 0x00000002,
PT_PEN = 0x00000003,
PT_MOUSE = 0x00000004
} POINTER_INPUT_TYPE;
typedef enum tagTOUCH_MASK {
TOUCH_MASK_NONE = 0x00000000,
TOUCH_MASK_CONTACTAREA = 0x00000001,
TOUCH_MASK_ORIENTATION = 0x00000002,
TOUCH_MASK_PRESSURE = 0x00000004,
} TOUCH_MASK;
typedef struct tagPOINTER_INFO {
POINTER_INPUT_TYPE pointerType;
UINT32 pointerId;
UINT32 frameId;
POINTER_FLAGS pointerFlags;
HANDLE sourceDevice;
HWND hwndTarget;
POINT ptPixelLocation;
POINT ptHimetricLocation;
POINT ptPixelLocationRaw;
POINT ptHimetricLocationRaw;
DWORD dwTime;
UINT32 historyCount;
INT32 inputData;
DWORD dwKeyStates;
UINT64 PerformanceCount;
POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
} POINTER_INFO;
typedef struct tagPOINTER_TOUCH_INFO {
POINTER_INFO pointerInfo;
int touchFlags;
int touchMask;
RECT rcContact;
RECT rcContactRaw;
UINT32 orientation;
UINT32 pressure;
} POINTER_TOUCH_INFO;
#endif
typedef BOOL(WINAPI *_InitializeTouchInjection)(UINT32 maxCount, DWORD dwMode);
typedef BOOL(WINAPI *_InjectTouchInput)(UINT32 count, const POINTER_TOUCH_INFO *contacts);
_InjectTouchInput g_TouchInjectionCall = NULL;
HMODULE g_TouchLoadLibrary = NULL;
int g_TouchLoadLibraryState = 0;
int TouchInit()
{
_InitializeTouchInjection init = NULL;
if (g_TouchLoadLibraryState > 0) return g_TouchLoadLibraryState;
g_TouchLoadLibrary = LoadLibrary(TEXT("User32.dll"));
if (g_TouchLoadLibrary == NULL) { g_TouchLoadLibraryState = 2; return 2; }
init = (_InitializeTouchInjection)GetProcAddress(g_TouchLoadLibrary, "InitializeTouchInjection");
g_TouchInjectionCall = (_InjectTouchInput)GetProcAddress(g_TouchLoadLibrary, "InjectTouchInput");
if (init == NULL || g_TouchInjectionCall == NULL || !init(MAX_TOUCH_COUNT, TOUCH_FEEDBACK_DEFAULT)) { FreeLibrary(g_TouchLoadLibrary); g_TouchLoadLibraryState = 2; return 2; }
g_TouchLoadLibraryState = 1;
return 1;
}
void TouchUnInit()
{
if (g_TouchLoadLibraryState != 1) return;
FreeLibrary(g_TouchLoadLibrary);
g_TouchLoadLibrary = NULL;
g_TouchInjectionCall = NULL;
g_TouchLoadLibraryState = 0;
}
void MakeTouchObject(POINTER_TOUCH_INFO* contact, unsigned char id, POINTER_FLAGS flags, int x, int y)
{
memset(contact, 0, sizeof(POINTER_TOUCH_INFO));
contact->pointerInfo.pointerType = PT_TOUCH; // we're sending touch input
contact->pointerInfo.pointerId = id; // contact id
contact->pointerInfo.ptPixelLocation.x = x;
contact->pointerInfo.ptPixelLocation.y = y;
contact->pointerInfo.pointerFlags = flags;
contact->touchFlags = 0;
contact->touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
contact->orientation = 90;
contact->pressure = 32000;
// Contact area
contact->rcContact.top = contact->pointerInfo.ptPixelLocation.y - 2;
contact->rcContact.bottom = contact->pointerInfo.ptPixelLocation.y + 2;
contact->rcContact.left = contact->pointerInfo.ptPixelLocation.x - 2;
contact->rcContact.right = contact->pointerInfo.ptPixelLocation.x + 2;
}
int TouchAction1(unsigned char id, unsigned int flags, unsigned short x, unsigned short y)
{
POINTER_TOUCH_INFO contact;
if (g_TouchLoadLibraryState != 1) return 0;
MakeTouchObject(&contact, id, (POINTER_FLAGS)flags, x, y);
if (!g_TouchInjectionCall(1, &contact)) { printf("TOUCH1ERROR: id=%d, flags=%d, x=%d, y=%d, err=%ld\r\n", id, flags, x, y, GetLastError()); return 1; }
//printf("TOUCH: id=%d, flags=%d, x=%d, y=%d\r\n", id, flags, x, y);
return 0;
}
int TouchAction2(char* data, int datalen, int scaling)
{
int i, records = datalen / 9;
POINTER_TOUCH_INFO contact[16];
if (g_TouchLoadLibraryState != 1) return 0;
if (records > 16) records = 16;
for (i = 0; i < records; i++) {
int flags = (int)ntohl(((unsigned int*)(data + (9 * i) + 1))[0]);
int x = (int)(ntohs(((unsigned short*)(data + (9 * i) + 5))[0]));
int y = (int)(ntohs(((unsigned short*)(data + (9 * i) + 7))[0]));
x = (x * 1024) / scaling;
y = (y * 1024) / scaling;
MakeTouchObject(&contact[i], data[i * 9], (POINTER_FLAGS)flags, x, y);
//printf("TOUCH2: flags=%d, x=%d, y=%d\r\n", flags, x, y);
}
if (!g_TouchInjectionCall(records, contact)) { printf("TOUCH2ERROR: records=%d, err=%ld\r\n", records, GetLastError()); return 1; }
return 0;
}
#endif

View File

@@ -0,0 +1,26 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(_LINKVM)
void MouseAction(double absX, double absY, int button, short wheel);
void KeyAction(unsigned char keycode, int up);
int TouchInit();
void TouchUnInit();
int TouchAction1(unsigned char id, unsigned int flags, unsigned short x, unsigned short y);
int TouchAction2(char* data, int datalen, int scaling);
#endif

1077
meshcore/KVM/Windows/kvm.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(_LINKVM)
#include "microstack/ILibParsers.h"
typedef ILibTransport_DoneState(*ILibKVM_WriteHandler)(char *buffer, int bufferLen, void *reserved);
int kvm_relay_feeddata(char* buf, int len, ILibKVM_WriteHandler writeHandler, void *reserved);
void kvm_pause(int pause);
int kvm_relay_setup(char* exePath, void *processPipeMgr, ILibKVM_WriteHandler writeHandler, void *reserved);
void kvm_cleanup();
void kvm_setupSasPermissions();
void kvm_relay_reset(ILibKVM_WriteHandler writeHandler, void *reserved);
#endif

View File

@@ -0,0 +1,602 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(_LINKVM)
#include <stdio.h>
#include "tile.h"
#include <gdiplus.h>
#include "meshcore/meshdefines.h"
using namespace Gdiplus;
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(_MINCORE)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
// #define KVMDEBUGENABLED 1
#ifdef KVMDEBUGENABLED
extern "C"
{
extern void KvmCriticalLog(const char* msg, const char* file, int line, int user1, int user2);
#define KVMDEBUG(m,u) { KvmCriticalLog(m, __FILE__, __LINE__, u, GetLastError()); printf("TVMMSG: %s (%d,%d).\r\n", m, (int)u, (int)GetLastError()); }
#define KVMDEBUG2(x) x
}
#else
#define KVMDEBUG(m, u)
#define KVMDEBUG2(x)
#endif
extern "C"
{
#include "microstack/ILibCrypto.h"
extern int TILE_WIDTH;
extern int TILE_HEIGHT;
extern int SCREEN_WIDTH;
extern int SCREEN_HEIGHT;
extern int SCREEN_X;
extern int SCREEN_Y;
extern int SCALED_WIDTH;
extern int SCALED_HEIGHT;
extern int PIXEL_SIZE;
extern int TILE_WIDTH_COUNT;
extern int TILE_HEIGHT_COUNT;
extern int COMPRESSION_RATIO;
extern int SCALING_FACTOR;
extern int SCALING_FACTOR_NEW;
extern int FRAME_RATE_TIMER;
extern tileInfo_t **tileInfo;
}
// Used with setting up a GDI+ session.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
HDC hDesktopDC;
HDC hCaptureDC;
HBITMAP hCapturedBitmap;
//HDC hdc;
CLSID encoderClsid;
ULONG encCompression = 50; // Image compression
EncoderParameters encParam;
LPVOID tilebuffer = NULL;
unsigned int tilebuffersize = 0;
// Used to obtain the GUID for the image encoder.
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
unsigned int num = 0, size = 0;
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if (size == 0) return -1;
if ((pImageCodecInfo = (ImageCodecInfo*)(malloc(size))) == NULL) return -1;
GetImageEncoders(num, size, pImageCodecInfo);
for (unsigned int j = 0; j < num; ++j)
{
if (wcsncmp(pImageCodecInfo[j].MimeType, format, size) == 0)
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
// Adjusts the screen size(width or height) to be exactly divisible by TILE_WIDTH
int adjust_screen_size(int pixles)
{
int extra = pixles % TILE_WIDTH; // Assuming tile width and height will remain the same.
if (extra != 0) return pixles + TILE_WIDTH - extra;
return pixles;
}
// Extracts the required tile buffer from the desktop buffer
int get_tile_buffer(int x, int y, void **buffer, void *desktop, int tilewidth, int tileheight)
{
void *target = *buffer;
for (int height = adjust_screen_size(SCALED_HEIGHT) - y - tileheight; height < adjust_screen_size(SCALED_HEIGHT) - y; height++)
{
memcpy_s(target, tilebuffersize, (const void *)((unsigned char *)desktop + (((height * adjust_screen_size(SCALED_WIDTH)) + x) * PIXEL_SIZE) ), (size_t)(tilewidth * PIXEL_SIZE));
target = (void *) ((unsigned char *)target + tilewidth * PIXEL_SIZE);
}
return 0;
}
int tile_crc(int x, int y, void *desktop, int tilewidth, int tileheight)
{
int crc = 0;
for (int height = adjust_screen_size(SCALED_HEIGHT) - y - tileheight; height < adjust_screen_size(SCALED_HEIGHT) - y; height++)
{
crc = util_crc(((unsigned char *)desktop + (((height * adjust_screen_size(SCALED_WIDTH)) + x) * PIXEL_SIZE) ), (size_t)(tilewidth * PIXEL_SIZE), crc);
}
return crc;
}
// This function returns 0 and *buffer != NULL if everything was good. retval = jpegsize if the captured image was too large.
int calc_opt_compr_send(int x, int y, int captureWidth, int captureHeight, void* desktop, void ** buffer, long long *bufferSize)
{
BITMAPINFO bmpInfo;
LARGE_INTEGER Offset;
BITMAPFILEHEADER bmpFileHeader;
*buffer = NULL;
*bufferSize = 0;
KVMDEBUG("calc_opt_compr_send()", 0);
// Get the bmpInfo structure
bmpInfo = get_bmp_info(captureWidth, captureHeight);
// Make sure a tile buffer is available. Most of the time, this is skipped.
if (tilebuffersize != bmpInfo.bmiHeader.biSizeImage)
{
if (tilebuffer != NULL) free(tilebuffer);
tilebuffersize = bmpInfo.bmiHeader.biSizeImage;
if ((tilebuffer = malloc(tilebuffersize)) == NULL) return 0;
}
// Get the final coalesced tile
get_tile_buffer(x, y, &tilebuffer, desktop, captureWidth, captureHeight);
bmpFileHeader.bfReserved1 = 0;
bmpFileHeader.bfReserved2 = 0;
bmpFileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmpInfo.bmiHeader.biSizeImage;
bmpFileHeader.bfType = 'MB';
bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
// Construct stream object.
IStream* bmpStream = NULL;
if (CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&bmpStream) != S_OK)
{
KVMDEBUG("CreateStreamOnHGlobal() failed", 0);
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Write entire contents of the source BMP into this stream.
bmpStream->Write(&bmpFileHeader, sizeof(BITMAPFILEHEADER), NULL);
bmpStream->Write(&bmpInfo, sizeof(BITMAPINFOHEADER), NULL);
bmpStream->Write(tilebuffer, bmpInfo.bmiHeader.biSizeImage, NULL);
// Move the stream pointer to the beginning of the stream.
Offset.QuadPart = 0;
if (bmpStream->Seek(Offset, STREAM_SEEK_SET, NULL) != S_OK)
{
KVMDEBUG("bmpStream->Seek() failed", 0);
bmpStream->Release();
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Construct GDI+ Image object from the BMP stream.
Gdiplus::Image* DIBImage = Gdiplus::Image::FromStream(bmpStream);
// Create stream to receive the encoded JPEG.
IStream* jpegStream = NULL;
if (CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&jpegStream) != S_OK)
{
KVMDEBUG("CreateStreamOnHGlobal() failed", 0);
delete DIBImage;
bmpStream->Release();
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Save image stream into the stream object.
Status SaveStatus = DIBImage->Save(jpegStream, &encoderClsid, &encParam);
if (SaveStatus != S_OK)
{
KVMDEBUG("DIBImage->Save() failed", 0);
delete DIBImage;
bmpStream->Release();
jpegStream->Release();
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Get the size of the output stream
ULARGE_INTEGER Size;
Offset.QuadPart = 0;
if (jpegStream->Seek(Offset, STREAM_SEEK_END, &Size) != S_OK)
{
KVMDEBUG("jpegStream->Save() failed", 0);
delete DIBImage;
bmpStream->Release();
jpegStream->Release();
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Move the image stream's pointer to its beginning.
Offset.QuadPart = 0;
if (jpegStream->Seek(Offset, STREAM_SEEK_SET, NULL) != S_OK)
{
KVMDEBUG("jpegStream->Seek() failed", 0);
delete DIBImage;
bmpStream->Release();
jpegStream->Release();
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Check if the tile is too large to send
DWORD jpegSize = (DWORD)Size.QuadPart;
if (jpegSize > 65500)
{
KVMDEBUG("jpegSize > 65500", jpegSize);
delete DIBImage;
*bufferSize = 0;
// ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return jpegSize;
}
// Save the image stream in memory.
char* Tile = (char*)ILibMemory_Allocate(jpegSize + 8, 0, NULL, NULL);
if (jpegStream->Read(Tile + 8, jpegSize, NULL) != S_OK)
{
KVMDEBUG("jpegStream->Read() failed", 0);
delete DIBImage;
free(Tile);
bmpStream->Release();
jpegStream->Release();
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
return 0;
}
// Cleanup
delete DIBImage;
bmpStream->Release();
jpegStream->Release();
*buffer = (unsigned char*)Tile;
*bufferSize = jpegSize + 8;
// Place the header
((unsigned short*)*buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_PICTURE); // Write the type
((unsigned short*)*buffer)[1] = (unsigned short)htons((unsigned short)*bufferSize); // Write the size
((unsigned short*)*buffer)[2] = (unsigned short)htons((unsigned short)x); // X position
((unsigned short*)*buffer)[3] = (unsigned short)htons((unsigned short)y); // Y position
return 0;
}
extern "C"
{
//Fetches the encoded jpeg tile at the given location. The neighboring tiles are coalesed to form a larger jpeg before returning.
int get_tile_at(int x, int y, void** buffer, long long *bufferSize, void *desktop, int row, int col)
{
int CRC;
int rightcol = col; // Used in coalescing. Indicates the right-most column to be coalesced.
int botrow = row; // Used in coalescing. Indicates the bottom-most row to be coalesced.
int r_x = x;
int r_y = y;
int captureWidth = TILE_WIDTH;
int captureHeight = TILE_HEIGHT;
*buffer = NULL; // If anything fails, this will be the indication.
*bufferSize = 0;
if (tileInfo[row][col].flags == (char)TILE_TODO) // First check whether the tile-crc needs to be calcualted or not.
{
// Compute CRC on the contents of the bitmap; Proceed with image encoding only if the CRC is different.
if ((CRC = tile_crc(x, y, desktop, TILE_WIDTH, TILE_HEIGHT)) == tileInfo[row][col].crc) return 0;
tileInfo[row][col].crc = CRC; // Update the tile CRC in the global data structure.
}
tileInfo[row][col].flags = (char)TILE_MARKED_NOT_SENT;
// COALESCING SECTION
// First got to the right most changed tile and record it
while (rightcol + 1 < TILE_WIDTH_COUNT)
{
rightcol++;
r_x = rightcol * TILE_WIDTH;
CRC = tileInfo[row][rightcol].crc;
if (tileInfo[row][rightcol].flags == (char)TILE_TODO) {
// Compute CRC on the contents of the bitmap.
CRC = tile_crc(r_x, y, desktop, TILE_WIDTH, TILE_HEIGHT);
}
if (CRC != tileInfo[row][rightcol].crc || tileInfo[row][rightcol].flags == (char)TILE_MARKED_NOT_SENT) // If the tile has changed, increment the capturewidth.
{
tileInfo[row][rightcol].crc = CRC;
// Here we check whether the size of the coalesced bitmap is greater than the threshold (65500)
if ((captureWidth + TILE_WIDTH) * TILE_HEIGHT * PIXEL_SIZE / COMPRESSION_RATIO > 65500) {
tileInfo[row][rightcol].flags = (char)TILE_MARKED_NOT_SENT;
--rightcol;
break;
}
tileInfo[row][rightcol].flags = (char)TILE_MARKED_NOT_SENT;
captureWidth += TILE_WIDTH;
}
else
{
tileInfo[row][rightcol].flags = (char)TILE_DONT_SEND;
--rightcol;
break;
}
}
// int TOLERANCE = (rightcol - col) / 4;
// Now go to the bottom tiles, check if they have changed and record them
while ((botrow + 1 < TILE_HEIGHT_COUNT) && ((captureHeight + TILE_HEIGHT) * captureWidth * PIXEL_SIZE / COMPRESSION_RATIO <= 65500))
{
botrow++;
r_y = botrow * TILE_HEIGHT;
int fail = 0;
r_x = x;
// int missCount = 0;
for (int rcol = col; rcol <= rightcol; rcol++) {
CRC = tileInfo[botrow][rcol].crc;
if (tileInfo[botrow][rcol].flags == (char)TILE_TODO)
{
// Compute CRC on the contents of the bitmap; Proceed with image encoding only if the CRC is different.
CRC = tile_crc(r_x, r_y, desktop, TILE_WIDTH, TILE_HEIGHT);
}
if (CRC != tileInfo[botrow][rcol].crc || tileInfo[botrow][rcol].flags == (char)TILE_MARKED_NOT_SENT)
{
tileInfo[botrow][rcol].flags = (char)TILE_MARKED_NOT_SENT;
tileInfo[botrow][rcol].crc = CRC;
r_x += TILE_WIDTH;
}
else
{
/*// Keep this part commented. Adding tolerance adds to the complexity of this code.
missCount++;
if (missCount > TOLERANCE) {
fail = 1;
for (int i = col; i < rcol; i++) {
if (tileInfo[botrow][i].flags == (char)TILE_SKIPPED) {
tileInfo[botrow][i].flags = (char)TILE_DONT_SEND;
}
else {
tileInfo[botrow][i].flags = (char)TILE_MARKED_NOT_SENT;
}
}
tileInfo[botrow][rcol].flags = (char)TILE_DONT_SEND;
botrow--;
break;
}
else {
tileInfo[botrow][rcol].flags = (char)TILE_SKIPPED;
tileInfo[botrow][rcol].crc = CRC;
r_x += TILE_WIDTH;
}*/
fail = 1;
for (int i = col; i < rcol; i++)
{
tileInfo[botrow][i].flags = (char)TILE_MARKED_NOT_SENT;
}
tileInfo[botrow][rcol].flags = (char)TILE_DONT_SEND;
botrow--;
break;
}
}
if (!fail)
{
captureHeight += TILE_HEIGHT;
}
else
{
break;
}
}
int retval = 0;
int firstTime = 1;
// This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time.
do {
// retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent.
retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, buffer, bufferSize);
if (retval == 0 && *bufferSize == 0) break;
if (retval != 0)
{
if (firstTime)
{
// Re-adjust the compression ratio.
COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO/(double)retval) * 60000);//Magic number: 60000 ~= 65500
if (COMPRESSION_RATIO <= 1) COMPRESSION_RATIO = 2;
firstTime = 0;
}
if (botrow > row) // First time, try reducing the height.
{
botrow = row + ((botrow - row + 1) / 2);
captureHeight = (botrow - row + 1) * TILE_HEIGHT;
}
else if (rightcol > col) // If it is not possible, reduce the width
{
rightcol = col + ((rightcol - col + 1) / 2);
captureWidth = (rightcol - col + 1) * TILE_WIDTH;
}
else
{ // This never happens, but just in case.
retval = 0;
break;
}
}
} while (*buffer == NULL);
// Set the flags to TILE_SENT
if (*buffer != NULL) {
for (int r = row; r <= botrow; r++) {
for (int c = col; c <= rightcol; c++) {
tileInfo[r][c].flags = (char)TILE_SENT;
}
}
}
return retval;
}
// This function captures the entire desktop buffer to scan.
int get_desktop_buffer(void **buffer, long long *bufferSize)
{
BITMAPINFO bmpInfo;
*buffer = NULL; // If anything fails, this will be the indication.
*bufferSize = 0;
if (hDesktopDC) ReleaseDC(NULL, hDesktopDC);
if ((hDesktopDC = GetDC(NULL)) == NULL) { KVMDEBUG("GetDC(NULL) returned NULL", 0); return 1; } // We need to do this incase the current desktop changes.
if (hCapturedBitmap) DeleteObject(hCapturedBitmap);
if ((hCapturedBitmap = CreateCompatibleBitmap(hDesktopDC, adjust_screen_size(SCALED_WIDTH), adjust_screen_size(SCALED_HEIGHT))) == NULL)
{
KVMDEBUG("CreateCompatibleBitmap() returned NULL", 0);
return 0;
}
if (SelectObject(hCaptureDC, hCapturedBitmap) == NULL) { KVMDEBUG("SelectObject() failed", 0); }
if (SCALING_FACTOR == 1024)
{
if (BitBlt(hCaptureDC, 0, 0, adjust_screen_size(SCREEN_WIDTH), adjust_screen_size(SCREEN_HEIGHT), hDesktopDC, SCREEN_X, SCREEN_Y, SRCCOPY | CAPTUREBLT) == FALSE)
{
KVMDEBUG("BitBlt() returned FALSE", 0);
return 1; // If the copy fails, error out.
}
}
else
{
if (SetStretchBltMode(hCaptureDC, HALFTONE) == 0) { KVMDEBUG("SetStretchBltMode() failed", 0); }
if (StretchBlt(hCaptureDC, 0, 0, adjust_screen_size(SCALED_WIDTH), adjust_screen_size(SCALED_HEIGHT), hDesktopDC, SCREEN_X, SCREEN_Y, adjust_screen_size(SCREEN_WIDTH), adjust_screen_size(SCREEN_HEIGHT), SRCCOPY | CAPTUREBLT) == FALSE)
{
KVMDEBUG("StretchBlt() returned FALSE", 0);
return 1; // If the copy fails, error out.
}
}
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// Populates some fields in the bmpInfo struct based on the properties of the bitmap.
if (GetDIBits(hDesktopDC, hCapturedBitmap, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS) == 0)
{
KVMDEBUG("GetDIBits() failed", 0);
ILibCriticalLog(NULL, __FILE__, __LINE__, 252, GetLastError());
}
if (bmpInfo.bmiHeader.biSizeImage <= 0)
{
bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth * abs(bmpInfo.bmiHeader.biHeight) * (bmpInfo.bmiHeader.biBitCount + 7) / 8;
}
*bufferSize = bmpInfo.bmiHeader.biSizeImage;
PIXEL_SIZE = bmpInfo.bmiHeader.biBitCount / 8;
if ((*buffer = malloc((size_t)*bufferSize)) == NULL) { KVMDEBUG("malloc() failed", 0); return 0; }
bmpInfo.bmiHeader.biCompression = BI_RGB;
if (GetDIBits(hDesktopDC, hCapturedBitmap, 0, bmpInfo.bmiHeader.biHeight, *buffer, &bmpInfo, DIB_RGB_COLORS) == 0) { KVMDEBUG("GetDIBits() failed", 0); }
return 0;
}
// Creates a BITMAPINFO object with required width and height
BITMAPINFO get_bmp_info(int width, int height)
{
BITMAPINFO bmpInfo;
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biBitCount = (WORD)(PIXEL_SIZE * 8);
bmpInfo.bmiHeader.biSize = 40;
bmpInfo.bmiHeader.biHeight = height;
bmpInfo.bmiHeader.biWidth = width;
bmpInfo.bmiHeader.biSizeImage = height * width * PIXEL_SIZE;
bmpInfo.bmiHeader.biPlanes = 1;
return bmpInfo;
}
short initialize_gdiplus()
{
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
TILE_WIDTH = 32;
TILE_HEIGHT = 32;
COMPRESSION_RATIO = 100;
FRAME_RATE_TIMER = 50;
SCALING_FACTOR = 1024;
SCALING_FACTOR_NEW = 1024;
SCALED_WIDTH = SCREEN_WIDTH = GetSystemMetrics(SM_CXSCREEN);
SCALED_HEIGHT = SCREEN_HEIGHT = GetSystemMetrics(SM_CYSCREEN);
if ((hDesktopDC = GetDC(NULL)) == NULL) { KVMDEBUG("GetDC() failed", 0); return 0; }
if ((hCaptureDC = CreateCompatibleDC(hDesktopDC)) == NULL) { KVMDEBUG("CreateCompatibleDC() failed", 0); return 0; }
if ((hCapturedBitmap = CreateCompatibleBitmap(hDesktopDC, SCALED_WIDTH, SCALED_HEIGHT)) == NULL) { KVMDEBUG("CreateCompatibleBitmap() failed", 0); return 0; }
if (SelectObject(hCaptureDC, hCapturedBitmap) == NULL) { KVMDEBUG("SelectObject() failed", 0); }
// Find encoder and setup encoder parameters
GetEncoderClsid(L"image/jpeg", &encoderClsid);
encParam.Count = 1;
encParam.Parameter[0].Guid = EncoderQuality;
encParam.Parameter[0].Type = EncoderParameterValueTypeLong;
encParam.Parameter[0].NumberOfValues = 1;
encParam.Parameter[0].Value = &encCompression;
return 1;
}
void teardown_gdiplus()
{
if (tilebuffer) free(tilebuffer);
tilebuffersize = 0;
tilebuffer = NULL;
GdiplusShutdown(gdiplusToken);
DeleteDC(hCaptureDC);
DeleteObject(hCapturedBitmap);
if (hDesktopDC) ReleaseDC(NULL, hDesktopDC);
hDesktopDC = NULL;
}
void set_tile_compression(int type, int level)
{
encCompression = level;
if (tilebuffer == NULL) { KVMDEBUG("set_tile_compression(), tilebuffer == NULL.", 0); return; }
KVMDEBUG("set_tile_compression() type", type);
KVMDEBUG("set_tile_compression() level", level);
switch (type)
{
case 1: { GetEncoderClsid(L"image/jpeg", &encoderClsid); break; }
case 2: { GetEncoderClsid(L"image/png", &encoderClsid); break; }
case 3: { GetEncoderClsid(L"image/tiff", &encoderClsid); break; }
}
}
}
#endif

View File

@@ -0,0 +1,52 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(_LINKVM)
#include <Windows.h>
#include <tchar.h>
#if defined(_cplus_plus) || defined(__cplusplus) || defined(_cplusplus)
extern "C"
{
#endif
struct tileInfo_t {
int crc;
char flags; // See TILE_FLAGS_ENUM
};
enum TILE_FLAGS_ENUM {
TILE_TODO, // The tile CRC needs to be calculated.
TILE_SENT, // CRC has been calculated and the tile has been sent.
TILE_MARKED_NOT_SENT, // CRC has been calculated, but the tile was not sent.
TILE_DONT_SEND // CRC has been calculated, tile need not be sent.
//TILE_SKIPPED // CRC has been calculated, tile need not be sent, but was skipped to include a greater region
};
short initialize_gdiplus();
void teardown_gdiplus();
int get_tile_at(int x, int y, void** buffer, long long *bufferSize, void *desktop, int row, int col);
int get_desktop_buffer(void **buffer, long long *bufferSize);
BITMAPINFO get_bmp_info(int width, int height);
void set_tile_compression(int type, int level);
void switch_to_desktop_context();
#if defined(_cplus_plus) || defined(__cplusplus) || defined(_cplusplus)
}
#endif
#endif

3024
meshcore/agentcore.c Normal file

File diff suppressed because it is too large Load Diff

204
meshcore/agentcore.h Normal file
View File

@@ -0,0 +1,204 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __AGENTCORE__
#define __AGENTCORE__
#ifdef MICROSTACK_NOTLS
#define UTIL_HASHSIZE 32
#endif
typedef char JS_ENGINE_CONTEXT[16];
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Windows.h>
#include <WinBase.h>
#endif
#include "microstack/ILibParsers.h"
#include "microstack/ILibWebServer.h"
#include "microstack/ILibWebClient.h"
#include "microstack/ILibSimpleDataStore.h"
#include "microstack/ILibRemoteLogging.h"
#include "microstack/ILibProcessPipe.h"
#include "microscript/duktape.h"
#include "microscript/ILibWebServer_Duktape.h"
#include "microscript/ILibParsers_Duktape.h"
#include "microscript/ILibWebClient_Duktape.h"
#include "microscript/ILibAsyncSocket_Duktape.h"
#include "microscript/ILibDuktape_WebRTC.h"
#include "microscript/ILibDuktape_http.h"
#include "microscript/ILibDuktape_net.h"
#include "microscript/ILibDuktapeModSearch.h"
#include "microscript/ILibDuktape_GenericMarshal.h"
#include "microscript/ILibDuktape_SimpleDataStore.h"
#include "microscript/ILibDuktape_ProcessPipe.h"
#include "microscript/ILibDuktape_fs.h"
#include "microstack/ILibProcessPipe.h"
#include "microstack/ILibCrypto.h"
typedef enum AgentIdentifiers
{
AGENTID_UNKNOWN = 0, //!< Self-update not supported
AGENTID_WIN32_CONSOLE = 1, //!< Windows x86 console app
AGENTID_WIN64_CONSOLE = 2, //!< Windows x86-64 console app
AGENTID_WIN32_SERVICE = 3, //!< Windows x86 service
AGENTID_WIN64_SERVICE = 4, //!< Windows x86-64 service
AGENTID_LINUX32 = 5, //!< Linux x86
AGENTID_LINUX64 = 6, //!< Linux x64
AGENTID_MIPS = 7, //!< MIPS (used for home routers)
AGENTID_XEN_x86 = 8, //!< XEN Virtualization
AGENTID_ANDROID_ARM = 9, //!< Android ARM devices
AGENTID_LINUX_ARM = 10, //!< Linux/ARM, used for PlugPC
AGENTID_MAC_OSX = 11, //!< Apple MAC OS X
AGENTID_ANDROID_x86 = 12, //!< Android/x86
AGENTID_POGOPLUG_ARM = 13, //!< PogoPlug/ARM
AGENTID_ANDROID_APK = 14, //!< Android Market
AGENTID_LINUX_POKY_X86 = 15, //!< Intel Galileo
AGENTID_MAC_OSX64 = 16, //!< Apple MAC OSX (64 bit)
AGENTID_CHROMEOS = 17, //!< ChromeOS
AGENTID_LINUXPOKY64 = 18, //!< Linux Poky (64 bit)
AGENTID_LINUX_NOKVM_X86 = 19, //!< Linux NOKVM (32 bit)
AGENTID_LINUX_NOKVM_X64 = 20, //!< Linux NOKVM (64 bit)
AGENTID_WIN32_MIN_CONSOLE = 21, //!< Windows MinCore Console (32 bit)
AGENTID_WIN32_MIN_SERVICE = 22, //!< Windows MinCore Service (32 bit)
AGENTID_NODEJS = 23 //!< NodeJS agent
}AgentIdentifiers;
// MeshServer to/from MeshAgent commands.
// Commands 0 to 9 are reserved for client/server authentication, once authenticated they can't be used and must not be processed.
// Commands 10 and above must only be processed if the server is authenticated. All these commands have 2 bytes commandid + 2 bytes requestid.
// Commands with an id that starts with '{' (123, 0x7B) are reserved for JSON commands, that is commands 31488 (0x7B00) to 31743 (0x7BFF)
typedef enum MeshCommands_Binary
{
MeshCommand_AuthRequest = 1, // Server web certificate public key sha256 hash + agent or server nonce
MeshCommand_AuthVerify = 2, // Agent or server signature
MeshCommand_AuthInfo = 3, // Agent information
MeshCommand_AuthConfirm = 4, // Server confirm to the agent that is it authenticated
MeshCommand_CoreModule = 10, // New core modules to be used instead of the old one, if empty, remove the core module
MeshCommand_CoreModuleHash = 11, // Request/return the SHA256 hash of the core module
MeshCommand_AgentHash = 12, // Request/return the SHA256 hash of the agent executable
MeshCommand_AgentUpdate = 13, // Indicate the start and end of the mesh agent binary transfer
MeshCommand_AgentUpdateBlock = 14, // Part of the mesh agent sent from the server to the agent, confirmation/flowcontrol from agent to server
MeshCommand_AgentTag = 15 // Send the mesh agent tag to the server
} MeshCommands_Binary;
#pragma pack(push,1)
typedef struct MeshAgent_Commands_SCRIPT_CreateContext
{
unsigned short CommandType;
JS_ENGINE_CONTEXT ContextGUID;
unsigned int SecurityFlags;
unsigned int ExecutionTimeout;
}MeshAgent_Commands_SCRIPT_CreateContext;
typedef struct MeshAgent_Commands_SCRIPT_DeleteContext
{
unsigned short CommandType;
JS_ENGINE_CONTEXT ContextGUID;
}MeshAgent_Commands_SCRIPT_DeleteContext;
typedef struct MeshAgent_Commands_SCRIPT_ExecuteString
{
unsigned short CommandType;
JS_ENGINE_CONTEXT ContextGUID;
char script[];
}MeshAgent_Commands_SCRIPT_ExecuteString;
#pragma pack(pop)
typedef struct MeshAgentDuktapePtrs
{
struct MeshAgentDuktapePtrs *Next;
duk_context *ctx;
void *MeshAgentObject;
void *OnCommand;
void *OnConnect;
void *OnReady;
}MeshAgentDuktapePtrs;
typedef enum MeshAgentHost_BatteryInfo
{
MeshAgentHost_BatteryInfo_HIGH = 1,
MeshAgentHost_BatteryInfo_LOW = 2,
MeshAgentHost_BatteryInfo_CRITICAL = 4,
MeshAgentHost_BatteryInfo_CHARGING = 8,
MeshAgentHost_BatteryInfo_NONE = 3,
MeshAgentHost_BatteryInfo_UNKNOWN = 0,
}MeshAgentHost_BatteryInfo;
extern char* MeshAgentHost_BatteryInfo_STRINGS[];
typedef struct MeshAgentHostContainer
{
void* chain;
int slaveMode;
duk_context *meshCoreCtx;
MeshAgentDuktapePtrs *DuktapeMeshBindings;
ILibProcessPipe_Manager *pipeManager;
char* exePath;
ILibWebClient_RequestManager httpClientManager;
ILibSimpleDataStore masterDb;
ILibWebClient_StateObject controlChannel;
struct sockaddr_in6* proxyServer;
int localScript;
int version;
char hostname[255];
char serveruri[1024];
AgentIdentifiers agentID;
int serverIndex;
int retryTime;
MeshAgentHost_BatteryInfo batteryState;
char meshId[UTIL_HASHSIZE];
int performSelfUpdate;
int disableUpdate;
char agentHash[UTIL_HASHSIZE];
char serverHash[UTIL_HASHSIZE];
#ifndef MICROSTACK_NOTLS
struct util_cert selfcert;
struct util_cert selftlscert;
struct util_cert selftlsclientcert;
char serverWebHash[UTIL_HASHSIZE];
char serverNonce[UTIL_HASHSIZE];
char agentNonce[UTIL_HASHSIZE];
int serverAuthState;
#endif
int controlChannel_idleTimeout_seconds;
char g_selfid[UTIL_HASHSIZE];
void* microLMS;
void* multicastDiscovery;
char* multicastServerUrl;
int serverConnectionState;
int exitCode;
#ifndef WIN32
int dbRetryCount;
#endif
}MeshAgentHostContainer;
MeshAgentHostContainer* MeshAgent_Create();
void MeshAgent_Destroy(MeshAgentHostContainer* agent);
int MeshAgent_Start(MeshAgentHostContainer *agent, int argc, char **argv);
void MeshAgent_Stop(MeshAgentHostContainer *agent);
void MeshAgent_PerformSelfUpdate(char* selfpath, char* exepath, int argc, char **argv);
char* MeshAgent_MakeAbsolutePath(char *basePath, char *localPath);
#endif

65
meshcore/meshdefines.h Normal file
View File

@@ -0,0 +1,65 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if !defined(__MeshDefines__)
#define __MeshDefined__
#define UTIL_HASHSIZE 32
#define MESH_AGENT_PORT 16990 //!< Default Mesh Agent Port
#define MESH_AGENT_STUN_PORT 16991 //!< Default Mesh Agent STUN Port
#define MESH_AGENT_VERSION 1 //!< Used for self-update system.
typedef enum RemoteManagementCommands
{
MNG_KVM_NOP = 0,
MNG_KVM_KEY = 1,
MNG_KVM_MOUSE = 2,
MNG_KVM_PICTURE = 3,
MNG_KVM_COPY = 4,
MNG_KVM_COMPRESSION = 5,
MNG_KVM_REFRESH = 6,
MNG_KVM_SCREEN = 7,
MNG_KVM_PAUSE = 8,
MNG_TERMTEXT = 9,
MNG_CTRLALTDEL = 10,
MNG_KVM_GET_DISPLAYS = 11,
MNG_KVM_SET_DISPLAY = 12,
MNG_KVM_FRAME_RATE_TIMER = 13,
MNG_KVM_INIT_TOUCH = 14,
MNG_KVM_TOUCH = 15,
MNG_KVM_CONNECTCOUNT = 16,
MNG_KVM_MESSAGE = 17,
MNG_ECHO = 21,
MNG_GETDIR = 50,
MNG_FILEMOVE = 51,
MNG_FILEDELETE = 52,
MNG_FILECOPY = 53,
MNG_FILECREATEDIR = 54,
MNG_FILETRANSFER = 55,
MNG_FILEUPLOAD = 56,
MNG_FILESEARCH = 57,
MNG_FILETRANSFER2 = 58,
MNG_KVM_DISCONNECT = 59,
MNG_GETDIR2 = 60, // Same as MNG_GETDIR but with date/time.
MNG_FILEUPLOAD2 = 61, // Used for slot based fast upload.
MNG_FILEDELETEREC = 62, // Same as MNG_FILEDELETE but recursive
MNG_USERCONSENT = 63, // Used to notify management console of user consent state
MNG_DEBUG = 64, // Debug/Logging Message for ILibRemoteLogging
MNG_ENCAPSULATE_AGENT_COMMAND = 70
}RemoteManagementCommands;
#endif

590
meshcore/meshinfo.c Normal file
View File

@@ -0,0 +1,590 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(_MINCORE)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#if defined(WINSOCK2)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#elif defined(WINSOCK1)
#include <winsock.h>
#include <wininet.h>
#elif defined(_POSIX)
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#include <sys/syscall.h>
#include <linux/reboot.h>
#define inaddrr(x) (*(struct in_addr *) &ifr->x[sizeof sa.sin_port])
#define IFRSIZE ((int)(size * sizeof (struct ifreq)))
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../microstack/ILibParsers.h"
#include "../microstack/ILibCrypto.h"
#include "meshinfo.h"
#ifdef WINSOCK2
// This is the Windows implementation of a method that gets information about local interfaces
int info_GetLocalInterfaces(char* data, int maxdata)
{
#ifdef _MINCORE
return 0;
#else
IP_ADAPTER_INFO *pAdapterInfo;
IP_ADAPTER_ADDRESSES *pAdapterAddresses;
PIP_ADAPTER_INFO pAdapter;
PIP_ADAPTER_ADDRESSES pAdapterAddr;
ULONG ulOutBufLen = 0;
DWORD dwRetVal;
unsigned int j;
int adapterCount = 0;
unsigned long palen;
unsigned char pa[16];
int ptr = 0;
size_t templen;
char temp[1024];
IPAddr ip1;
IPAddr ip2;
// Lets see how much memory we need to get the list of local interfaces
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) return 0;
ulOutBufLen = sizeof(IP_ADAPTER_INFO);
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS) { free(pAdapterInfo); if (ulOutBufLen == 0) return 0; pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); }
// Get the list of all local interfaces
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) != ERROR_SUCCESS || ulOutBufLen == 0) { free(pAdapterInfo); return 0; }
// Count how many interfaces are present
pAdapter = pAdapterInfo;
while (pAdapter) { adapterCount++; pAdapter = pAdapter->Next; }
// Lets see how much memory we need to get the list of local adapters
pAdapterAddresses = (IP_ADAPTER_ADDRESSES *)malloc(sizeof(IP_ADAPTER_ADDRESSES));
if (pAdapterAddresses == NULL) { free(pAdapterInfo); return 0; }
ulOutBufLen = sizeof(IP_ADAPTER_ADDRESSES);
if (GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_GATEWAYS | GAA_FLAG_INCLUDE_PREFIX, NULL, pAdapterAddresses, &ulOutBufLen) != ERROR_SUCCESS)
{
free(pAdapterAddresses);
if (ulOutBufLen == 0) return 0;
pAdapterAddresses = (IP_ADAPTER_ADDRESSES *)malloc(ulOutBufLen);
}
// Get the list of all local interfaces
if ((dwRetVal = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_GATEWAYS | GAA_FLAG_INCLUDE_PREFIX, NULL, pAdapterAddresses, &ulOutBufLen)) != ERROR_SUCCESS || ulOutBufLen == 0) { free(pAdapterInfo); free(pAdapterAddresses); return 0; }
j = 0;
pAdapter = pAdapterInfo;
while (pAdapter)
{
// Find the corresponding adapter for this interface
pAdapterAddr = pAdapterAddresses;
while (pAdapterAddr != NULL && pAdapterAddr->IfIndex != pAdapter->Index) { pAdapterAddr = pAdapterAddr->Next; }
if (pAdapterAddr == NULL) { free(pAdapterInfo); free(pAdapterAddresses); return 0; }
if (j > 0) { ptr += snprintf(data + ptr, maxdata - ptr, ","); }
ptr += snprintf(data + ptr, maxdata - ptr, "{");
// Interface type
ptr += snprintf(data + ptr, maxdata - ptr, "\"type\":%d", pAdapter->Type);
// Interface name
if (wcslen(pAdapterAddr->FriendlyName) > 0) {
wcstombs_s(&templen, temp, 1023, pAdapterAddr->FriendlyName, wcslen(pAdapterAddr->FriendlyName));
ptr += snprintf(data + ptr, maxdata - ptr, ",\"name\":\"%s\"", temp);
}
// Interface description
if (wcslen(pAdapterAddr->Description) > 0) {
wcstombs_s(&templen, temp, 1023, pAdapterAddr->Description, wcslen(pAdapterAddr->Description));
ptr += snprintf(data + ptr, maxdata - ptr, ",\"desc\":\"%s\"", temp);
}
// Interface MAC address
if (pAdapter->AddressLength == 6) {
ptr += snprintf(data + ptr, maxdata - ptr, ",\"mac\":\"%02x%02x%02x%02x%02x%02x\"", pAdapter->Address[0], pAdapter->Address[1], pAdapter->Address[2], pAdapter->Address[3], pAdapter->Address[4], pAdapter->Address[5]);
}
// Interface DNS suffix
if (wcslen(pAdapterAddr->DnsSuffix) > 0) {
wcstombs_s(&templen, temp, 1023, pAdapterAddr->DnsSuffix, wcslen(pAdapterAddr->DnsSuffix));
ptr += snprintf(data + ptr, maxdata - ptr, ",\"dnssuffix\":\"%s\"", temp);
}
// IPv4 address and subnet mask
ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4addr\":\"%s\"", pAdapter->IpAddressList.IpAddress.String);
ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4mask\":\"%s\"", pAdapter->IpAddressList.IpMask.String);
ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4gateway\":\"%s\"", pAdapter->GatewayList.IpAddress.String);
// Get the gateway MAC address
ILibInet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String, &ip1);
ILibInet_pton(AF_INET, pAdapter->GatewayList.IpAddress.String, &ip2);
SendARP(ip2, ip1, pa, &palen);
if (palen == 6) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"gatewaymac\":\"%02x%02x%02x%02x%02x%02x\"", pa[0], pa[1], pa[2], pa[3], pa[4], pa[5]); }
ptr += snprintf(data + ptr, maxdata - ptr, "}");
j++;
pAdapter = pAdapter->Next;
}
// Free the local interface memory
free(pAdapterInfo);
free(pAdapterAddresses);
return ptr;
#endif
}
#endif
#ifdef _POSIX
// This method reads a stream where the length of the file can't be determined. Useful in POSIX only
int __fastcall utilx_readfile2(char* filename, char** data)
{
FILE * pFile;
int count = 0;
int len = 0;
*data = NULL;
if (filename == NULL) return 0;
pFile = fopen(filename, "rb");
if (pFile != NULL)
{
*data = malloc(1024);
if (*data == NULL) { fclose(pFile); return 0; }
do
{
len = fread((*data) + count, 1, 1023, pFile);
count += len;
if (len == 1023) *data = realloc(*data, count + 1024);
} while (len == 100);
(*data)[count] = 0;
fclose(pFile);
}
return count;
}
// TODO: Add support for IPv6, and check that it's on the correct interface
int info_GetHwAddress(char* ipaddr, int ipaddrlen, char** hwaddr)
{
char* arpcache = NULL;
int len, r = 0;
char* ptr = NULL;
char substr[32];
*hwaddr = NULL;
if (ipaddrlen >= 30 || (ipaddrlen == 7 && memcmp(ipaddr, "0.0.0.0", 7) == 0)) return 0;
len = utilx_readfile2("/proc/net/arp", &arpcache);
if (len == 0) return 0;
substr[0] = '\n';
memcpy(substr + 1, ipaddr, ipaddrlen);
substr[ipaddrlen + 1] = ' ';
substr[ipaddrlen + 2] = 0;
ptr = strstr(arpcache, substr);
if ((ptr != NULL) && (ptr + 61 < arpcache + len) && (ptr[44] == ':') && (ptr[47] == ':') && (ptr[56] == ':'))
{
if ((*hwaddr = (char*)malloc(6)) == NULL) ILIBCRITICALEXIT(254);
for (; r < 6; r++) { (*hwaddr)[r] = util_hexToint(ptr + 42 + (r * 3), 2); }
}
free(arpcache);
return r;
}
// The Linux equal of Windows SendARP
int SendARP(char* DestIP, char* SrcIP, void* pMacAddr, int* PhyAddrLen)
{
char tmp[50];
char* ptr = NULL;
ILibInet_ntop(AF_INET, DestIP, tmp, 50);
if (*PhyAddrLen < 6) return -1;
*PhyAddrLen = info_GetHwAddress(tmp, strlen(tmp), &ptr);
if (ptr != NULL)
{
memcpy(pMacAddr, ptr, 6);
free(ptr);
return 0;
}
return -1;
}
// TODO: See if we can do this for each interface, right now interface is ignored
int info_GetDefaultFqdn(char* ifname, char** fqdn)
{
char* resolv;
int len, r = 0;
struct parser_result* parse;
struct parser_result_field* p;
struct parser_result* parse2;
struct parser_result_field* p2;
*fqdn = NULL;
len = utilx_readfile2("/etc/resolv.conf", &resolv);
if (len == 0) return 0;
parse = ILibParseString(resolv, 0, len, "\n", 1);
p = parse->FirstResult;
while (p != NULL)
{
parse2 = ILibParseString(p->data, 0, p->datalength, " ", 1);
p2 = parse2->FirstResult;
if (p2->datalength == 6 && memcmp(p2->data, "domain", 6) == 0)
{
// We found the system's default FQDN
r = p2->NextResult->datalength;
*fqdn = malloc(r + 1);
memcpy(*fqdn, p2->NextResult->data, r);
(*fqdn)[r] = 0;
ILibDestructParserResults(parse2);
break;
}
ILibDestructParserResults(parse2);
p = p->NextResult; // Skip to next line
}
ILibDestructParserResults(parse);
free(resolv);
return r;
}
// TODO: Add IPv6 support
int info_GetDefaultGateway(char* ifname, char** gateway)
{
char* route;
char* temp;
int len, r = 0, i;
int ifnamelen = strlen(ifname);
struct parser_result* parse;
struct parser_result_field* p;
struct parser_result* parse2;
struct parser_result_field* p2;
*gateway = NULL;
len = utilx_readfile2("/proc/net/route", &route);
if (len == 0) return 0;
parse = ILibParseString(route, 0, len, "\n", 1);
p = parse->FirstResult;
p = p->NextResult; // Skip the first line
while (p != NULL)
{
parse2 = ILibParseString(p->data, 0, p->datalength, "\t", 1);
p2 = parse2->FirstResult;
if (ifnamelen == p2->datalength && memcmp(p2->data, ifname, ifnamelen) == 0)
{
if (p2->NextResult->datalength == 8 && memcmp(p2->NextResult->data, "00000000", 8) == 0)
{
// We found the default gateway for this interface
r = p2->NextResult->NextResult->datalength / 2;
*gateway = malloc(r);
temp = p2->NextResult->NextResult->data;
for (i = 0; i < r; i++) { (*gateway)[r - (i + 1)] = util_hexToint(temp + (i * 2), 2); }
ILibDestructParserResults(parse2);
break;
}
}
ILibDestructParserResults(parse2);
p = p->NextResult; // Skip to next line
}
ILibDestructParserResults(parse);
free(route);
return r;
}
// This is the POSIX implementation of a method that gets information about local interfaces
int info_GetLocalInterfaces(char* data, int maxdata)
{
#ifdef NACL
return 0;
#else
int ptr = 0;
int sockfd, size = 1, j;
int adapterCount = 0;
struct ifreq *ifr;
struct ifconf ifc;
char temp[1024];
char* gateway = NULL;
// Fetch the list of local interfaces
if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) return 0;
ifc.ifc_len = IFRSIZE;
ifc.ifc_req = NULL;
do
{
++size;
// realloc buffer size until no overflow occurs
if ((ifc.ifc_req = realloc(ifc.ifc_req, IFRSIZE)) == NULL) return 0;
ifc.ifc_len = IFRSIZE;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) != 0) return 0;
} while (IFRSIZE <= ifc.ifc_len);
ifr = ifc.ifc_req;
for (; (char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len; ++ifr)
{
if (ifr->ifr_addr.sa_data == (ifr + 1)->ifr_addr.sa_data) continue; // Duplicate
if (ioctl(sockfd, SIOCGIFFLAGS, ifr)) continue; // Failed
if (memcmp(ifr->ifr_name, "lo", 3) == 0) continue; // Loopback
if (adapterCount > 0) { ptr += snprintf(data + ptr, maxdata - ptr, ","); }
ptr += snprintf(data + ptr, maxdata - ptr, "{");
// Get the name of the interface
ptr += snprintf(data + ptr, maxdata - ptr, "\"name\":\"%s\"", ifr->ifr_name);
// Get the FQDN (DNS Suffix)
j = info_GetDefaultFqdn(ifr->ifr_name, &gateway);
if (j > 0) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"dnssuffix\":\"%s\"", gateway); }
if (gateway != NULL) { free(gateway); gateway = NULL; }
// Get the Default Gateway IP address
j = info_GetDefaultGateway(ifr->ifr_name, &gateway);
if (j == 4) { ILibInet_ntop(AF_INET, gateway, temp, 1024); ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4gateway\":\"%s\"", temp); }
if (gateway != NULL) { free(gateway); gateway = NULL; }
// Get the Default Gateway MAC address
j = info_GetHwAddress(temp, strlen(temp), &gateway);
if (j == 6) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"gatewaymac\":\"%02x%02x%02x%02x%02x%02x\"", (unsigned char)gateway[0], (unsigned char)gateway[1], (unsigned char)gateway[2], (unsigned char)gateway[3], (unsigned char)gateway[4], (unsigned char)gateway[5]); }
if (gateway != NULL) free(gateway);
// Attempt to figure out the interface type
j = 0;
if (strlen(ifr->ifr_name) > 3 && memcmp(ifr->ifr_name, "eth", 3) == 0) { j = 6; }
//if (strlen(ifr->ifr_name) > 2 && memcmp(ifr->ifr_name, "wl", 2) == 0) { j = 6; } // TODO: Wireless
if (j > 0) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"type\":\"%d\"", j); }
// Get the hardware MAC address
if (ioctl(sockfd, SIOCGIFHWADDR, ifr) == 0) {
if (ifr->ifr_hwaddr.sa_family == 1) {
ptr += snprintf(data + ptr, maxdata - ptr, ",\"mac\":\"%02x%02x%02x%02x%02x%02x\"", (unsigned char)ifr->ifr_hwaddr.sa_data[0], (unsigned char)ifr->ifr_hwaddr.sa_data[1], (unsigned char)ifr->ifr_hwaddr.sa_data[2], (unsigned char)ifr->ifr_hwaddr.sa_data[3], (unsigned char)ifr->ifr_hwaddr.sa_data[4], (unsigned char)ifr->ifr_hwaddr.sa_data[5]);
}
}
// Get the IP address
if (ioctl(sockfd, SIOCGIFADDR, ifr) == 0) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4addr\":\"%s\"", inet_ntoa(((struct sockaddr_in*)(&(ifr->ifr_addr)))->sin_addr)); }
// Get the subnet mask
if (ioctl(sockfd, SIOCGIFNETMASK, ifr) == 0) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4mask\":\"%s\"", inet_ntoa(((struct sockaddr_in*)(&(ifr->ifr_addr)))->sin_addr)); }
ptr += snprintf(data + ptr, maxdata - ptr, "}");
adapterCount++;
}
free(ifc.ifc_req);
close(sockfd);
return ptr;
#endif
}
#endif
// Returns a JSON text with system information
int MeshInfo_GetSystemInformation(char** data)
{
int ptr = 0;
// Setup the response
*data = (char*)malloc(65536);
ptr += snprintf(*data + ptr, 65536 - ptr, "{\"netif\":[");
ptr += info_GetLocalInterfaces(*data + ptr, 65536 - ptr);
ptr += snprintf(*data + ptr, 65536 - ptr, "]}");
(*data)[ptr] = 0;
*data = realloc(*data, ptr + 1);
return ptr;
}
#ifdef WIN32
#if defined(_LINKVM)
DWORD WINAPI kvm_ctrlaltdel(LPVOID Param);
#endif
int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force)
{
#ifdef _MINCORE
if (flg == 0 || flg > 5) return 0; // NOP
switch (flg)
{
case POWERSTATE_SHUTDOWN: // SHUTDOWN
InitiateSystemShutdownEx(NULL, NULL, 30, TRUE, FALSE, SHTDN_REASON_MINOR_OTHER);
break;
case POWERSTATE_REBOOT: // REBOOT
InitiateSystemShutdownEx(NULL, NULL, 30, TRUE, TRUE, SHTDN_REASON_MINOR_OTHER);
break;
}
return 1;
#else
TOKEN_PRIVILEGES tp;
BOOL fResult = 0;
HANDLE ht;
if (flg == POWERSTATE_NOP) return 0; // NOP
if (flg == POWERSTATE_DISPLAYON) { SetThreadExecutionState(ES_DISPLAY_REQUIRED); SetThreadExecutionState(ES_USER_PRESENT); return 1; } // Turn on display
if (flg == POWERSTATE_KEEPAWAKE) { SetThreadExecutionState(ES_SYSTEM_REQUIRED); return 1; } // Keep system awake
if (flg == POWERSTATE_BEEP) { MessageBeep(0xFFFFFFFF); return 1; }
if (flg == POWERSTATE_CTRLALTDEL)
{
#if defined(_LINKVM)
ht = CreateThread(NULL, 0, kvm_ctrlaltdel, 0, 0, 0);
if (ht != NULL) CloseHandle(ht);
return 1;
#else
return 0;
#endif
}
// Attempt to exit
if (flg > POWERSTATE_HIBERNATE) return 0; // NOP
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &ht)) return 0;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid);
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(ht, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS) { CloseHandle(ht); return 0; }
switch (flg)
{
case POWERSTATE_LOGOFF: // LOGOFF
if (force) fResult = ExitWindowsEx(EWX_LOGOFF | EWX_FORCE, SHTDN_REASON_FLAG_PLANNED);
else fResult = ExitWindowsEx(EWX_LOGOFF, SHTDN_REASON_FLAG_PLANNED);
break;
case POWERSTATE_SHUTDOWN: // SHUTDOWN
fResult = InitiateSystemShutdown(NULL, NULL, 30, TRUE, FALSE);
break;
case POWERSTATE_REBOOT: // REBOOT
fResult = InitiateSystemShutdown(NULL, NULL, 30, TRUE, TRUE);
break;
case POWERSTATE_SLEEP: // SLEEP
fResult = SetSystemPowerState(TRUE, force);
break;
case POWERSTATE_HIBERNATE: // HIBERNATE
fResult = SetSystemPowerState(FALSE, force);
break;
}
if (!fResult) { CloseHandle(ht); return 0; }
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(ht, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
CloseHandle(ht);
return 1;
#endif
}
#elif _VX_CPU // If VxWorks, we still need to implement this.
int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force)
{
// TODO
return 0;
}
#else
int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force)
{
switch (flg)
{
case POWERSTATE_NOP:
case POWERSTATE_DISPLAYON:
case POWERSTATE_KEEPAWAKE:
case POWERSTATE_BEEP:
case POWERSTATE_CTRLALTDEL:
// NO OP
break;
case POWERSTATE_LOGOFF: // LOGOFF
break;
case POWERSTATE_SHUTDOWN: // SHUTDOWN
#if defined(_ANDROID)
reboot(RB_POWER_OFF);
#elif defined(__APPLE__)
// TODO
#elif defined(NACL)
//do nothing
#else
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF, 0);
#endif
return 1;
case POWERSTATE_REBOOT: // REBOOT
#if defined(_ANDROID) || defined(__APPLE__)
reboot(RB_AUTOBOOT);
#elif defined(NACL)
//do nothing
#else
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, 0);
#endif
return 1;
case POWERSTATE_SLEEP: // SLEEP
#if defined(__APPLE__)
{
io_connect_t port = IOPMFindPowerManagement(MACH_PORT_NULL);
IOPMSleepSystem(port);
IOServiceClose(port);
}
#endif
break;
#ifdef LINUX_REBOOT_CMD_SW_SUSPEND
case POWERSTATE_HIBERNATE: // HIBERNATE
#if defined(_ANDROID) || defined(__APPLE__)
// TODO
#else
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_SW_SUSPEND, 0);
#endif
return 1;
#endif
case POWERSTATE_VIBRATE: // VIBRATE
#if defined(ANDROID)
{
ai_vibrate(1000);
}
#endif
break;
case POWERSTATE_FLASH: // FLASH
#if defined(ANDROID)
{
ai_flash(1000);
}
#endif
break;
}
return 0;
}
#endif

36
meshcore/meshinfo.h Normal file
View File

@@ -0,0 +1,36 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
typedef enum AgentPowerStateActions
{
POWERSTATE_NOP = 0,
POWERSTATE_LOGOFF = 1,
POWERSTATE_SHUTDOWN = 2,
POWERSTATE_REBOOT = 3,
POWERSTATE_SLEEP = 4,
POWERSTATE_HIBERNATE = 5,
POWERSTATE_DISPLAYON = 6,
POWERSTATE_KEEPAWAKE = 7,
POWERSTATE_BEEP = 8,
POWERSTATE_CTRLALTDEL = 9,
POWERSTATE_VIBRATE = 13,
POWERSTATE_FLASH = 14
} AgentPowerStateActions;
int MeshInfo_GetSystemInformation(char** data);
int MeshInfo_PowerState(AgentPowerStateActions flg, int force);

225
meshcore/signcheck.c Normal file
View File

@@ -0,0 +1,225 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(WIN32) && !defined(_MINCORE)
#include <windows.h>
#include <netfw.h>
#include <objbase.h>
#include <oleauto.h>
#endif
#ifdef WIN32
#include <windows.h>
#include <Softpub.h>
#include <wchar.h>
#include <Psapi.h>
#endif
#include "MeshDefines.h"
#include "signcheck.h"
#include "microstack/ILibParsers.h"
#include "microstack/ILibCrypto.h"
// Trusted mesh agent update certificate hashs
const int TrustedCertificatesCount = 2;
const char TrustedCertificates[2][32] = {
{ 0xde, 0x6e, 0x97, 0x6d, 0x14, 0xe9, 0x5e, 0xd6, 0x71, 0xe6, 0xd8, 0x14, 0x36, 0xd2, 0x66, 0x43, 0x03, 0x02, 0x8f, 0x5c, 0xf3, 0x63, 0x11, 0x78, 0x95, 0xc1, 0x01, 0xd0, 0xba, 0x22, 0x02, 0x23 },
{ 0xd1, 0x7a, 0xae, 0x40, 0x9a, 0xef, 0x05, 0xf6, 0x4a, 0x6e, 0x18, 0x55, 0x97, 0xb5, 0x97, 0xd8, 0xb7, 0x8d, 0xb7, 0xae, 0x14, 0x47, 0xe3, 0xfb, 0xa1, 0x81, 0x08, 0xcf, 0x11, 0xcf, 0x67, 0x3c }
};
//! Check the file signature of an executable
/*!
\param filename File path to executable to verify
\param upgrade 1 = 'filename' expected to be a higher version. \n 2 = 'filename' is expected to be the same version
\return 0 = FAIL \n 1 = SUCCESS
*/
int signcheck_verifysign(char* filename, int upgrade)
{
#if defined(WIN32) && !defined(_MINCORE)
int i, ver = 0, agentid = 0, found = 0;
size_t len = 0;
WCHAR str[_MAX_PATH];
GUID guidAction = WINTRUST_ACTION_GENERIC_VERIFY_V2;
WINTRUST_FILE_INFO sWintrustFileInfo;
WINTRUST_DATA sWintrustData;
char hash[32];
CRYPT_PROVIDER_DATA const *psProvData = NULL;
CRYPT_PROVIDER_SGNR *psProvSigner = NULL;
CRYPT_PROVIDER_CERT *psProvCert = NULL;
// Setup and check the executable signature hash & certificate
memset((void*)&sWintrustFileInfo, 0x00, sizeof(WINTRUST_FILE_INFO));
memset((void*)&sWintrustData, 0x00, sizeof(WINTRUST_DATA));
mbstowcs_s(&len, str, _MAX_PATH, filename, _MAX_PATH);
sWintrustFileInfo.cbStruct = sizeof(WINTRUST_FILE_INFO);
sWintrustFileInfo.pcwszFilePath = str;
sWintrustFileInfo.hFile = NULL;
sWintrustData.cbStruct = sizeof(WINTRUST_DATA);
sWintrustData.dwUIChoice = WTD_UI_NONE;
sWintrustData.fdwRevocationChecks = WTD_REVOKE_NONE;
sWintrustData.dwUnionChoice = WTD_CHOICE_FILE;
sWintrustData.pFile = &sWintrustFileInfo;
sWintrustData.dwStateAction = WTD_STATEACTION_VERIFY; // Allocates memory that must be cleared
sWintrustData.dwProvFlags = WTD_HASH_ONLY_FLAG;
if (WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &guidAction, &sWintrustData) == 0)
{
if ((psProvData = WTHelperProvDataFromStateData(sWintrustData.hWVTStateData)) != 0)
{
if ((psProvSigner = WTHelperGetProvSignerFromChain((PCRYPT_PROVIDER_DATA)psProvData, 0, FALSE, 0)) != 0)
{
if ((psProvCert = WTHelperGetProvCertFromChain(psProvSigner, 0)) != 0)
{
util_sha256((char*)(psProvCert->pCert->pbCertEncoded), psProvCert->pCert->cbCertEncoded, hash);
for (i = 0; (int)i < TrustedCertificatesCount; i++) if (memcmp(TrustedCertificates[i], hash, 32) == 0) found = 1;
}
}
}
}
// Cleanup
sWintrustData.dwUIChoice = WTD_UI_NONE;
sWintrustData.dwStateAction = WTD_STATEACTION_CLOSE;
WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &guidAction, &sWintrustData);
if (found == 0) return 0; // Problem, exit now
// Get the version number of the executable
if (GetFileVersionInfo(filename, 0, sizeof(ILibScratchPad2), ILibScratchPad2))
{
VS_FIXEDFILEINFO *pFileInfo;
int buflen;
if (VerQueryValueA(ILibScratchPad2, "\\", (LPVOID *)&pFileInfo, (PUINT)&buflen))
{
ver += HIWORD(pFileInfo->dwFileVersionMS) * 10000;
ver += LOWORD(pFileInfo->dwFileVersionMS) * 100;
ver += HIWORD(pFileInfo->dwFileVersionLS);
#ifdef _WIN64
agentid = LOWORD(pFileInfo->dwFileVersionLS) + 1;
#else
agentid = LOWORD(pFileInfo->dwFileVersionLS);
#endif
}
}
// Compare architecture
// Setup the AgentID
if (agentid != MESH_AGENTID) { ILIBMESSAGE("BAD-ARCH-CHECK"); return 0; } // TODO: Replace AGENTID_WIN32_SERVICE with real value
// Compare version information
if (upgrade) return (ver >= MESH_AGENT_VERSION ? 1 : 0); // Debug: upgrades should normally be stricly better versions.
return (ver == MESH_AGENT_VERSION ? 1 : 0);
#else
FILE *pFile = NULL;
size_t totallen = 0;
size_t len = 0;
int endblock[4];
char* signatureblock = NULL;
int signatureblocklen = 0;
SHA256_CTX c;
char *buf = NULL;
char *hashs = NULL;
int hashslen;
char totalfilehash[32];
struct util_cert cert;
size_t i = 0;
int j = 0;
char* certbuf = NULL;
int certbuflen = 0;
int found = 0;
char certhash[32];
int agentid = 0;
int ver = 0;
if (filename == NULL) return 0;
cert.pkey = NULL;
cert.x509 = NULL;
#ifdef WIN32
fopen_s(&pFile, filename, "rb");
#else
pFile = fopen(filename, "rb");
#endif
if (pFile == NULL) goto error;
// Get the file total length
if (fseek(pFile, 0, SEEK_END)) goto error;
if ((totallen = ftell(pFile)) < 16) goto error;
// Seek 16 bytes before the end of the file and read the end block
if (fseek(pFile, -16, SEEK_END)) goto error;
if (fread(&endblock, 1, 16, pFile) != 16) goto error;
endblock[0] = ntohl(endblock[0]);
endblock[1] = ntohl(endblock[1]);
endblock[2] = ntohl(endblock[2]);
endblock[3] = ntohl(endblock[3]);
if (endblock[1] != 1 || endblock[2] != 0x11BB22DD || endblock[3] != 0x21CB32ED || totallen <= (size_t)(endblock[0] + 16)) goto error;
// Seek back and get the signature block
if (fseek(pFile, -(endblock[0] + 16), SEEK_END)) goto error;
if ((signatureblock = (char*)malloc(endblock[0])) == NULL) goto error;
signatureblocklen = fread(signatureblock, 1, endblock[0], pFile);
// Decode and verify the signature block
hashslen = util_verify(signatureblock, signatureblocklen, &cert, &hashs);
if (hashslen != 72) goto error;
// Set the file version and architecture numbers
ver = ntohl(((int*)hashs)[16]);
agentid = ntohl(((int*)hashs)[17]);
// Compare architecture
if (agentid != g_agentid) { ILIBMESSAGE("BAD-ARCH-CHECK"); fclose(pFile); return 0; }
// Seek to the start and hash the entire file except for the signature stuff at the end
SHA256_Init(&c);
if (fseek(pFile, 0, SEEK_SET)) goto error;
i = totallen - (size_t)(endblock[0] + 16);
if ((buf = (char*)malloc(4096)) == NULL) goto error;
while ((i > 0) && (len = fread(buf, 1, i > 4096 ? 4096 : i, pFile)) > 0) { SHA256_Update(&c, buf, len); i -= len; }
free(buf);
if (i != 0) goto error;
SHA256_Final((unsigned char*)totalfilehash, &c);
// Check that the file hash is the same as the second hash in the hash block
if (memcmp(hashs + 32, totalfilehash, 32) != 0) goto error;
// Get the public certificate block
certbuflen = util_to_cer(cert, &certbuf);
// Compute the certificate key hash
util_sha256(certbuf, certbuflen, certhash);
// Check if the certificate is trusted
for (j = 0; j < TrustedCertificatesCount; j++) if (memcmp(TrustedCertificates[j], certhash, 32) == 0) found = 1;
error:
// Clean up
util_freecert(&cert);
if (certbuf != NULL) free(certbuf);
if (hashs != NULL) free(hashs);
if (pFile != NULL) fclose(pFile);
if (signatureblock != NULL) free(signatureblock);
if (found != 1 || ver == 0 || agentid == 0) return 0;
// Compare version information
if (upgrade) return (ver >= MESH_AGENT_VERSION ? 1 : 0); // Debug: upgrades should normally be stricly better versions.
return (ver == MESH_AGENT_VERSION ? 1 : 0);
#endif
}

19
meshcore/signcheck.h Normal file
View File

@@ -0,0 +1,19 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
int signcheck_verifysign(char* filename, int upgrade);

BIN
meshservice/MeshService.aps Normal file

Binary file not shown.

Binary file not shown.

BIN
meshservice/MeshService.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

170
meshservice/MeshService.rc Normal file
View File

@@ -0,0 +1,170 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "MeshService.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,2,0,3
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Mesh Agent Service"
VALUE "FileVersion", "0.2.0.3"
VALUE "InternalName", "MeshAgent"
VALUE "LegalCopyright", "Apache 2.0 License"
VALUE "OriginalFilename", "MeshAgent.exe"
VALUE "ProductName", "Mesh Agent Service"
VALUE "ProductVersion", "0, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_INSTALLDIALOG DIALOGEX 0, 100, 317, 148
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION
CAPTION "Mesh Agent v2 Installer"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Close",IDCANCEL,260,127,50,14
LTEXT "Click the buttons below to install or uninstall the mesh agent. When installed, this software runs in the background allowing this computer to be managed and controlled by a remote administrator.",IDC_STATIC,7,7,275,28
GROUPBOX "Installation Information",IDC_STATIC,7,38,303,87
PUSHBUTTON "Install / Update",IDC_INSTALLBUTTON,7,127,77,14
PUSHBUTTON "Uninstall",IDC_UNINSTALLBUTTON,87,127,77,14
ICON IDI_ICON1,IDC_STATIC,288,7,21,20
LTEXT "Current Agent Status",IDC_STATIC,14,51,70,8
LTEXT "Unknown",IDC_STATUSTEXT,127,51,175,8,0,WS_EX_RIGHT
LTEXT "New Agent Version",IDC_STATIC,14,63,62,8
LTEXT "Unknown",IDC_VERSIONTEXT,127,63,175,8,0,WS_EX_RIGHT
LTEXT "New Mesh Identifier",IDC_STATIC,14,99,65,8
LTEXT "Unknown",IDC_HASHTEXT,127,99,175,8,0,WS_EX_RIGHT
LTEXT "New Mesh Name",IDC_STATIC,14,87,54,8
LTEXT "Unknown",IDC_POLICYTEXT,127,87,175,8,0,WS_EX_RIGHT
LTEXT "New Server Identifier",IDC_STATIC,14,111,70,8
LTEXT "Unknown",IDC_SERVERID,127,111,175,8,0,WS_EX_RIGHT
LTEXT "New Server Location",IDC_STATIC,14,75,67,8
LTEXT "Unknown",IDC_SERVERLOCATION,127,75,175,8,0,WS_EX_RIGHT
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_INSTALLDIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 310
TOPMARGIN, 7
BOTTOMMARGIN, 141
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//
IDD_INSTALLDIALOG AFX_DIALOG_LAYOUT
BEGIN
0
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,365 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}</ProjectGuid>
<RootNamespace>MeshConsole</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>MeshService</ProjectName>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)\$(TargetName)\$(Platform)\OBJ\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</PostBuildEventUseInBuild>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectName)</TargetName>
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</PostBuildEventUseInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MESH_AGENTID=3;NOLMSCOMMANDER;MICROSTACK_PROXY;_LINKVM;WIN32;_WINSERVICE;_DEBUG;_CONSOLE;MEMORY_CHECK;__STDC__;WINSOCK2;ILibWebServer_SESSION_TRACKING;MICROSTACK_NO_STDAFX;MICROSTACK_PROXY;MICROSTACK_TLS_DETECT;_REMOTELOGGING;_REMOTELOGGINGSERVER;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);ILibChain_WATCHDOG_TIMEOUT=600000;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;DbgHelp.lib;Gdiplus.lib;Iphlpapi.lib;ws2_32.lib;Setupapi.lib;Psapi.lib;Crypt32.lib;Wintrust.lib;Version.lib;Wtsapi32.lib;Winhttp.lib;..\openssl\libstatic\libcrypto32MTd.lib;..\openssl\libstatic\libssl32MTd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<Profile>false</Profile>
<OptimizeReferences>true</OptimizeReferences>
<GenerateMapFile>
</GenerateMapFile>
<MapExports>
</MapExports>
<AssemblyDebug>true</AssemblyDebug>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshService" /du "http://opentools.homeip.net" "$(TargetPath)"</Command>
</PostBuildEvent>
<Manifest>
<AdditionalManifestFiles>$(ProjectDir)dpiaware.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MESH_AGENTID=4;MICROSTACK_PROXY;_WINSERVICE;NOLMSCOMMANDER;WIN32;WIN64;_LINKVM;_DEBUG;_CONSOLE;MEMORY_CHECK;MICROSTACK_NO_STDAFX;MICROSTACK_PROXY;__STDC__;_CRT_SECURE_NO_WARNINGS;WINSOCK2;ILibWebServer_SESSION_TRACKING;_REMOTELOGGING;_REMOTELOGGINGSERVER;MICROSTACK_TLS_DETECT;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);ILibChain_WATCHDOG_TIMEOUT=600000;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;DbgHelp.lib;Iphlpapi.lib;ws2_32.lib;Setupapi.lib;Psapi.lib;Crypt32.lib;Wintrust.lib;Version.lib;Wtsapi32.lib;Gdiplus.lib;Winhttp.lib;Ncrypt.lib;..\openssl\libstatic\libcrypto64MTd.lib;..\openssl\libstatic\libssl64MTd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
<Profile>true</Profile>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
</Link>
<PostBuildEvent>
<Command>signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshService" /du "http://opentools.homeip.net" "$(TargetPath)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MESH_AGENTID=3;NOLMSCOMMANDER;MICROSTACK_PROXY;_LINKVM;WIN32;NDEBUG;_WINSERVICE;_CONSOLE;_LINKVM;WINSOCK2;MICROSTACK_NO_STDAFX;MICROSTACK_PROXY;MICROSTACK_TLS_DETECT;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CallingConvention>Cdecl</CallingConvention>
<OmitFramePointers>true</OmitFramePointers>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;Crypt32.lib;DbgHelp.lib;Iphlpapi.lib;ws2_32.lib;Setupapi.lib;Psapi.lib;Wintrust.lib;Version.lib;Wtsapi32.lib;Gdiplus.lib;Winhttp.lib;..\openssl\libstatic\libcrypto32MT.lib;..\openssl\libstatic\libssl32MT.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
</Link>
<PostBuildEvent>
<Command>signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshService" /du "http://opentools.homeip.net" /t http://timestamp.comodoca.com/authenticode "$(TargetPath)"</Command>
</PostBuildEvent>
<Manifest>
<AdditionalManifestFiles>$(ProjectDir)dpiaware.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>MinSpace</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\openssl\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MESH_AGENTID=4;NOLMSCOMMANDER;MICROSTACK_PROXY;WIN32;WIN64;_WINSERVICE;NDEBUG;_LINKVM;_CONSOLE;MICROSTACK_NO_STDAFX;MICROSTACK_PROXY;WINSOCK2;MICROSTACK_TLS_DETECT;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SetupAPI.lib;DbgHelp.lib;Iphlpapi.lib;ws2_32.lib;Setupapi.lib;Psapi.lib;Crypt32.lib;Wintrust.lib;Version.lib;Wtsapi32.lib;Gdiplus.lib;Winhttp.lib;Ncrypt.lib;..\openssl\libstatic\libcrypto64MT.lib;..\openssl\libstatic\libssl64MT.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX64</TargetMachine>
<AdditionalOptions> /ignore:4099 %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
</Link>
<PostBuildEvent>
<Command>signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshService" /du "http://opentools.homeip.net" /t http://timestamp.comodoca.com/authenticode "$(TargetPath)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ResourceCompile Include="MeshService.rc">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="MeshService.ico" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\meshcore\agentcore.c" />
<ClCompile Include="..\meshcore\KVM\Windows\input.c" />
<ClCompile Include="..\meshcore\KVM\Windows\kvm.c" />
<ClCompile Include="..\meshcore\KVM\Windows\tile.cpp" />
<ClCompile Include="..\meshcore\meshinfo.c" />
<ClCompile Include="..\meshcore\signcheck.c" />
<ClCompile Include="..\microlms\heci\HECIWin.c" />
<ClCompile Include="..\microlms\heci\LMEConnection.c" />
<ClCompile Include="..\microlms\heci\PTHICommand.c" />
<ClCompile Include="..\microlms\lms\ILibLMS.c" />
<ClCompile Include="..\microscript\duktape.c" />
<ClCompile Include="..\microscript\ILibAsyncSocket_Duktape.c" />
<ClCompile Include="..\microscript\ILibDuktapeModSearch.c" />
<ClCompile Include="..\microscript\ILibDuktape_Debugger.c" />
<ClCompile Include="..\microscript\ILibDuktape_Dgram.c" />
<ClCompile Include="..\microscript\ILibDuktape_DuplexStream.c" />
<ClCompile Include="..\microscript\ILibDuktape_EncryptionStream.c" />
<ClCompile Include="..\microscript\ILibduktape_EventEmitter.c" />
<ClCompile Include="..\microscript\ILibDuktape_fs.c" />
<ClCompile Include="..\microscript\ILibDuktape_GenericMarshal.c" />
<ClCompile Include="..\microscript\ILibDuktape_Helpers.c" />
<ClCompile Include="..\microscript\ILibDuktape_http.c" />
<ClCompile Include="..\microscript\ILibDuktape_MemoryStream.c" />
<ClCompile Include="..\microscript\ILibDuktape_net.c" />
<ClCompile Include="..\microscript\ILibDuktape_NetworkMonitor.c" />
<ClCompile Include="..\microscript\ILibDuktape_Polyfills.c" />
<ClCompile Include="..\microscript\ILibDuktape_ProcessPipe.c" />
<ClCompile Include="..\microscript\ILibDuktape_ReadableStream.c" />
<ClCompile Include="..\microscript\ILibDuktape_ScriptContainer.c" />
<ClCompile Include="..\microscript\ILibDuktape_SHA256.c" />
<ClCompile Include="..\microscript\ILibDuktape_SimpleDataStore.c" />
<ClCompile Include="..\microscript\ILibDuktape_WebRTC.c" />
<ClCompile Include="..\microscript\ILibDuktape_WritableStream.c" />
<ClCompile Include="..\microscript\ILibParsers_Duktape.c" />
<ClCompile Include="..\microscript\ILibWebClient_Duktape.c" />
<ClCompile Include="..\microscript\ILibWebServer_Duktape.c" />
<ClCompile Include="..\microstack\ILibAsyncServerSocket.c" />
<ClCompile Include="..\microstack\ILibAsyncSocket.c" />
<ClCompile Include="..\microstack\ILibAsyncUDPSocket.c" />
<ClCompile Include="..\microstack\ILibCrypto.c" />
<ClCompile Include="..\microstack\ILibIPAddressMonitor.c" />
<ClCompile Include="..\microstack\ILibMulticastSocket.c" />
<ClCompile Include="..\microstack\ILibParsers.c" />
<ClCompile Include="..\microstack\ILibProcessPipe.c" />
<ClCompile Include="..\microstack\ILibRemoteLogging.c" />
<ClCompile Include="..\microstack\ILibSimpleDataStore.c" />
<ClCompile Include="..\microstack\ILibWebClient.c" />
<ClCompile Include="..\microstack\ILibWebRTC.c" />
<ClCompile Include="..\microstack\ILibWebServer.c" />
<ClCompile Include="..\microstack\ILibWrapperWebRTC.c" />
<ClCompile Include="firewall.cpp" />
<ClCompile Include="ServiceMain.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\meshcore\agentcore.h" />
<ClInclude Include="..\meshcore\KVM\Windows\input.h" />
<ClInclude Include="..\meshcore\KVM\Windows\kvm.h" />
<ClInclude Include="..\meshcore\KVM\Windows\tile.h" />
<ClInclude Include="..\meshcore\meshdefines.h" />
<ClInclude Include="..\meshcore\meshinfo.h" />
<ClInclude Include="..\meshcore\signcheck.h" />
<ClInclude Include="..\microlms\heci\HECIWin.h" />
<ClInclude Include="..\microlms\heci\HECI_if.h" />
<ClInclude Include="..\microlms\heci\LMEConnection.h" />
<ClInclude Include="..\microlms\heci\LMS_if.h" />
<ClInclude Include="..\microlms\heci\LMS_if_constants.h" />
<ClInclude Include="..\microlms\heci\mei.h" />
<ClInclude Include="..\microlms\heci\PTHICommand.h" />
<ClInclude Include="..\microlms\heci\StatusCodeDefinitions.h" />
<ClInclude Include="..\microlms\lms\ILibLMS-WebSite.h" />
<ClInclude Include="..\microlms\lms\ILibLMS.h" />
<ClInclude Include="..\microscript\duktape.h" />
<ClInclude Include="..\microscript\duk_config.h" />
<ClInclude Include="..\microscript\ILibAsyncSocket_Duktape.h" />
<ClInclude Include="..\microscript\ILibDuktapeModSearch.h" />
<ClInclude Include="..\microscript\ILibDuktape_Debugger.h" />
<ClInclude Include="..\microscript\ILibDuktape_Dgram.h" />
<ClInclude Include="..\microscript\ILibDuktape_DuplexStream.h" />
<ClInclude Include="..\microscript\ILibDuktape_EncryptionStream.h" />
<ClInclude Include="..\microscript\ILibDuktape_EventEmitter.h" />
<ClInclude Include="..\microscript\ILibDuktape_fs.h" />
<ClInclude Include="..\microscript\ILibDuktape_GenericMarshal.h" />
<ClInclude Include="..\microscript\ILibDuktape_Helpers.h" />
<ClInclude Include="..\microscript\ILibDuktape_http.h" />
<ClInclude Include="..\microscript\ILibDuktape_net.h" />
<ClInclude Include="..\microscript\ILibDuktape_NetworkMonitor.h" />
<ClInclude Include="..\microscript\ILibDuktape_Polyfills.h" />
<ClInclude Include="..\microscript\ILibDuktape_ProcessPipe.h" />
<ClInclude Include="..\microscript\ILibDuktape_ReadableStream.h" />
<ClInclude Include="..\microscript\ILibDuktape_ScriptContainer.h" />
<ClInclude Include="..\microscript\ILibDuktape_SHA256.h" />
<ClInclude Include="..\microscript\ILibDuktape_SimpleDataStore.h" />
<ClInclude Include="..\microscript\ILibDuktape_WebRTC.h" />
<ClInclude Include="..\microscript\ILibDuktape_WritableStream.h" />
<ClInclude Include="..\microscript\ILibParsers_Duktape.h" />
<ClInclude Include="..\microscript\ILibWebClient_Duktape.h" />
<ClInclude Include="..\microscript\ILibWebServer_Duktape.h" />
<ClInclude Include="..\microstack\ILibAsyncServerSocket.h" />
<ClInclude Include="..\microstack\ILibAsyncSocket.h" />
<ClInclude Include="..\microstack\ILibAsyncUDPSocket.h" />
<ClInclude Include="..\microstack\ILibCrypto.h" />
<ClInclude Include="..\microstack\ILibIPAddressMonitor.h" />
<ClInclude Include="..\microstack\ILibMulticastSocket.h" />
<ClInclude Include="..\microstack\ILibParsers.h" />
<ClInclude Include="..\microstack\ILibProcessPipe.h" />
<ClInclude Include="..\microstack\ILibRemoteLogging.h" />
<ClInclude Include="..\microstack\ILibSimpleDataStore.h" />
<ClInclude Include="..\microstack\ILibWebClient.h" />
<ClInclude Include="..\microstack\ILibWebRTC.h" />
<ClInclude Include="..\microstack\ILibWebServer.h" />
<ClInclude Include="..\microstack\ILibWrapperWebRTC.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,362 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="Microstack">
<UniqueIdentifier>{75ed1bbd-b6b1-4867-9f66-2da5b6ad082d}</UniqueIdentifier>
</Filter>
<Filter Include="Microscript">
<UniqueIdentifier>{d3b5275c-5fb4-406e-a5b2-e24e2b3a60b1}</UniqueIdentifier>
</Filter>
<Filter Include="Meshcore">
<UniqueIdentifier>{867ca42f-0151-42e8-9dcd-728b129c5767}</UniqueIdentifier>
</Filter>
<Filter Include="Meshcore\KVM">
<UniqueIdentifier>{074ddd93-a67c-44e2-b7d9-b84549b60522}</UniqueIdentifier>
</Filter>
<Filter Include="MicroLMS">
<UniqueIdentifier>{555848d8-baf6-4cf1-94d6-935c78f6fd48}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MeshService.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="MeshService.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<ClCompile Include="firewall.cpp" />
<ClCompile Include="ServiceMain.c" />
<ClCompile Include="..\microscript\duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibAsyncSocket_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Debugger.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_DuplexStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_GenericMarshal.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Helpers.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_http.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_net.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_ReadableStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_SimpleDataStore.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_WritableStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktapeModSearch.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibParsers_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibWebClient_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibWebServer_Duktape.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibAsyncServerSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibAsyncSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibAsyncUDPSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibParsers.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibProcessPipe.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibRemoteLogging.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibSimpleDataStore.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWebClient.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWebRTC.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWebServer.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibWrapperWebRTC.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\agentcore.c">
<Filter>Meshcore</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\signcheck.c">
<Filter>Meshcore</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_ProcessPipe.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_fs.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_SHA256.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_EncryptionStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\KVM\Windows\input.c">
<Filter>Meshcore\KVM</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\KVM\Windows\kvm.c">
<Filter>Meshcore\KVM</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\KVM\Windows\tile.cpp">
<Filter>Meshcore\KVM</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibduktape_EventEmitter.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibCrypto.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Polyfills.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_WebRTC.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microlms\lms\ILibLMS.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microlms\heci\HECIWin.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microlms\heci\LMEConnection.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microlms\heci\PTHICommand.c">
<Filter>MicroLMS</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibMulticastSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\meshcore\meshinfo.c">
<Filter>Meshcore</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_Dgram.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_ScriptContainer.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_MemoryStream.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microscript\ILibDuktape_NetworkMonitor.c">
<Filter>Microscript</Filter>
</ClCompile>
<ClCompile Include="..\microstack\ILibIPAddressMonitor.c">
<Filter>Microstack</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\microscript\duk_config.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibAsyncSocket_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Debugger.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_DuplexStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_GenericMarshal.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Helpers.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_http.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_net.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_ReadableStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_SimpleDataStore.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_WritableStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktapeModSearch.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibParsers_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibWebClient_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibWebServer_Duktape.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibAsyncServerSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibAsyncSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibAsyncUDPSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibParsers.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibProcessPipe.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibRemoteLogging.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibSimpleDataStore.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWebClient.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWebRTC.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWebServer.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibWrapperWebRTC.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\agentcore.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\meshdefines.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\signcheck.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_ProcessPipe.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_fs.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_SHA256.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_EncryptionStream.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\KVM\Windows\input.h">
<Filter>Meshcore\KVM</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\KVM\Windows\kvm.h">
<Filter>Meshcore\KVM</Filter>
</ClInclude>
<ClInclude Include="..\meshcore\KVM\Windows\tile.h">
<Filter>Meshcore\KVM</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_EventEmitter.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibCrypto.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Polyfills.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_WebRTC.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microlms\lms\ILibLMS.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\lms\ILibLMS-WebSite.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\HECI_if.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\HECIWin.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\LMEConnection.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\LMS_if.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\LMS_if_constants.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\mei.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\PTHICommand.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microlms\heci\StatusCodeDefinitions.h">
<Filter>MicroLMS</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibMulticastSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="resource.h" />
<ClInclude Include="..\meshcore\meshinfo.h">
<Filter>Meshcore</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_Dgram.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_ScriptContainer.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microscript\ILibDuktape_NetworkMonitor.h">
<Filter>Microscript</Filter>
</ClInclude>
<ClInclude Include="..\microstack\ILibIPAddressMonitor.h">
<Filter>Microstack</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,153 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "..\\..\\media\\MeshController.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,57,4
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Mesh Agent Service"
VALUE "FileVersion", "0.1.57.4"
VALUE "InternalName", "MeshAgent"
VALUE "OriginalFilename", "MeshAgent.exe"
VALUE "ProductName", "Mesh Agent Service"
VALUE "ProductVersion", "0, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_INSTALLDIALOG DIALOGEX 0, 100, 316, 133
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION
CAPTION "Mesh Agent Installer"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Close",IDCANCEL,259,112,50,14
LTEXT "Click the buttons below to install or uninstall the peer-to-peer mesh agent. When installed, the mesh agent runs as a background service, linking up to other computers. The agents facilitates computer management and other applications.",IDC_STATIC,7,7,275,28
GROUPBOX "Installation Information",IDC_STATIC,7,38,302,65
PUSHBUTTON "Install / Update",IDC_INSTALLBUTTON,7,112,77,14
PUSHBUTTON "Uninstall",IDC_UNINSTALLBUTTON,87,112,77,14
ICON IDI_ICON1,IDC_STATIC,288,7,21,20
LTEXT "Current Service Status",IDC_STATIC,14,51,74,8
LTEXT "Unknown",IDC_STATUSTEXT,127,51,175,8,0,WS_EX_RIGHT
LTEXT "New Service Version",IDC_STATIC,14,63,66,8
LTEXT "Unknown",IDC_VERSIONTEXT,127,63,175,8,0,WS_EX_RIGHT
LTEXT "New Trusted Hash",IDC_STATIC,14,87,60,8
LTEXT "Unknown",IDC_HASHTEXT,127,87,175,8,0,WS_EX_RIGHT
LTEXT "New Trusted Policy",IDC_STATIC,14,75,62,8
LTEXT "Unknown",IDC_POLICYTEXT,127,75,175,8,0,WS_EX_RIGHT
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_INSTALLDIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 309
TOPMARGIN, 7
BOTTOMMARGIN, 126
END
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

1275
meshservice/ServiceMain.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

221
meshservice/firewall.cpp Normal file
View File

@@ -0,0 +1,221 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(WIN32) && !defined(_MINCORE)
#include <windows.h>
#include <netfw.h>
#include <objbase.h>
#include <oleauto.h>
extern "C"
{
// This is the old version, we now use explicit rules for both TCP and UDP ports
int SetupWindowsFirewallOld(wchar_t* friendlyname, wchar_t* processname)
{
BSTR fwBstr1 = NULL;
BSTR fwBstr2 = NULL;
INetFwMgr* fwMgr = NULL;
INetFwPolicy* fwPolicy = NULL;
INetFwProfile* fwProfile = NULL;
INetFwAuthorizedApplication* fwApp = NULL;
INetFwAuthorizedApplications* fwApps = NULL;
int ret = 0;
// Setup COM calls & firewall interface
if (FAILED(CoCreateInstance(__uuidof(NetFwMgr), NULL, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void**)&fwMgr))) goto error;
// Get firewall policy, profile, apps
if (FAILED(fwMgr->get_LocalPolicy(&fwPolicy))) goto error;
if (FAILED(fwPolicy->get_CurrentProfile(&fwProfile))) goto error;
if (FAILED(fwProfile->get_AuthorizedApplications(&fwApps))) goto error;
// Add an application to the Microsoft Windows XP firewall
{
// Create an instance of an authorized application.
if (FAILED(CoCreateInstance(__uuidof(NetFwAuthorizedApplication), NULL, CLSCTX_INPROC_SERVER, __uuidof(INetFwAuthorizedApplication), (void**)&fwApp))) goto error;
// Set the process image file name.
fwBstr1 = SysAllocString(processname);
if (fwBstr1 == NULL) goto error;
if (FAILED(fwApp->put_ProcessImageFileName(fwBstr1))) goto error;
// Set the application friendly name.
fwBstr2 = SysAllocString(friendlyname);
if (SysStringLen(fwBstr2) == 0) goto error;
if (FAILED(fwApp->put_Name(fwBstr2))) goto error;
// Add the application to the collection.
if (FAILED(fwApps->Add(fwApp))) goto error;
}
ret = 1;
error:
// Clean up
if (fwBstr1 != NULL) SysFreeString(fwBstr1);
if (fwBstr2 != NULL) SysFreeString(fwBstr2);
if (fwApp != NULL) fwApp->Release();
if (fwApps != NULL) fwApps->Release();
if (fwProfile != NULL) fwProfile->Release();
if (fwPolicy != NULL) fwPolicy->Release();
if (fwMgr != NULL) fwMgr->Release();
return ret;
}
int SetupWindowsFirewall(wchar_t* processname)
{
BSTR fwBstr2 = NULL;
INetFwRule* pNetFwRule = NULL;
INetFwRules* pNetFwRules = NULL;
INetFwPolicy2* pNetFwPolicy2 = NULL;
int ret = 0;
// Convert the friendly name.
fwBstr2 = SysAllocString(processname);
if (SysStringLen(fwBstr2) == 0) goto error;
// Fetch the rules
if (FAILED(CoCreateInstance(__uuidof(NetFwPolicy2), NULL, CLSCTX_ALL, __uuidof(INetFwPolicy2), (void**)&pNetFwPolicy2))) goto error;
if (FAILED(pNetFwPolicy2->get_Rules(&pNetFwRules))) goto error;
// Create a new rule for local P2P UDP traffic
if (FAILED(CoCreateInstance(__uuidof(NetFwRule), NULL, CLSCTX_ALL, __uuidof(INetFwRule), (void**)&pNetFwRule))) goto error;
if (FAILED(pNetFwRule->put_Name(L"Mesh Agent peer-to-peer (UDP)"))) goto error; // Put the rule name
if (FAILED(pNetFwRule->put_ApplicationName(fwBstr2))) goto error; // Put the application path
if (FAILED(pNetFwRule->put_Protocol(static_cast<NET_FW_IP_PROTOCOL>(NET_FW_IP_PROTOCOL_UDP)))) goto error; // Put the protocol (UDP)
if (FAILED(pNetFwRule->put_LocalPorts(L"16990"))) goto error; // Put the ports
if (FAILED(pNetFwRule->put_Description(L"Meshcentral agent UDP port for local peer-to-peer traffic."))) goto error; // Put the description
if (FAILED(pNetFwRule->put_EdgeTraversal(VARIANT_FALSE))) goto error; // Set edge traversal
if (FAILED(pNetFwRule->put_Enabled(VARIANT_TRUE))) goto error; // Enable rule
if (FAILED(pNetFwRules->Add(pNetFwRule))) goto error; // Add the new rule
pNetFwRule->Release();
pNetFwRule = NULL;
// Create a new rule for STUN/WebRTC internet traffic
if (FAILED(CoCreateInstance(__uuidof(NetFwRule), NULL, CLSCTX_ALL, __uuidof(INetFwRule), (void**)&pNetFwRule))) goto error;
if (FAILED(pNetFwRule->put_Name(L"Mesh Agent management (UDP)"))) goto error; // Put the rule name
if (FAILED(pNetFwRule->put_ApplicationName(fwBstr2))) goto error; // Put the application path
if (FAILED(pNetFwRule->put_Protocol(static_cast<NET_FW_IP_PROTOCOL>(NET_FW_IP_PROTOCOL_UDP)))) goto error; // Put the protocol (UDP)
if (FAILED(pNetFwRule->put_LocalPorts(L"16991"))) goto error; // Put the ports
if (FAILED(pNetFwRule->put_Description(L"Meshcentral agent UDP port for internet WebRTC management traffic."))) goto error; // Put the description
if (FAILED(pNetFwRule->put_EdgeTraversal(VARIANT_TRUE))) goto error; // Set edge traversal
if (FAILED(pNetFwRule->put_Enabled(VARIANT_TRUE))) goto error; // Enable rule
if (FAILED(pNetFwRules->Add(pNetFwRule))) goto error; // Add the new rule
pNetFwRule->Release();
pNetFwRule = NULL;
// Create a new rule for local P2P TCP traffic
if (FAILED(CoCreateInstance(__uuidof(NetFwRule), NULL, CLSCTX_ALL, __uuidof(INetFwRule), (void**)&pNetFwRule))) goto error;
if (FAILED(pNetFwRule->put_Name(L"Mesh Agent peer-to-peer (TCP)"))) goto error; // Put the rule name
if (FAILED(pNetFwRule->put_ApplicationName(fwBstr2))) goto error; // Put the application path
if (FAILED(pNetFwRule->put_Protocol(static_cast<NET_FW_IP_PROTOCOL>(NET_FW_IP_PROTOCOL_TCP)))) goto error; // Put the protocol (TCP)
if (FAILED(pNetFwRule->put_LocalPorts(L"16990"))) goto error; // Put the ports
if (FAILED(pNetFwRule->put_Description(L"Meshcentral agent TCP port for local peer-to-peer traffic."))) goto error; // Put the description
if (FAILED(pNetFwRule->put_Enabled(VARIANT_TRUE))) goto error; // Enable rule
if (FAILED(pNetFwRules->Add(pNetFwRule))) goto error; // Add the new rule
pNetFwRule->Release();
pNetFwRule = NULL;
// Create a new rule for TCP management traffic
if (FAILED(CoCreateInstance(__uuidof(NetFwRule), NULL, CLSCTX_ALL, __uuidof(INetFwRule), (void**)&pNetFwRule))) goto error;
if (FAILED(pNetFwRule->put_Name(L"Mesh Agent management (TCP)"))) goto error; // Put the rule name
if (FAILED(pNetFwRule->put_ApplicationName(fwBstr2))) goto error; // Put the application path
if (FAILED(pNetFwRule->put_Protocol(static_cast<NET_FW_IP_PROTOCOL>(NET_FW_IP_PROTOCOL_TCP)))) goto error; // Put the protocol (TCP)
if (FAILED(pNetFwRule->put_LocalPorts(L"16991"))) goto error; // Put the ports
if (FAILED(pNetFwRule->put_Description(L"Meshcentral agent TCP port for management traffic."))) goto error; // Put the description
if (FAILED(pNetFwRule->put_Enabled(VARIANT_TRUE))) goto error; // Enable rule
if (FAILED(pNetFwRules->Add(pNetFwRule))) goto error; // Add the new rule
pNetFwRule->Release();
pNetFwRule = NULL;
ret = 1;
error:
// Clean up
if (fwBstr2 != NULL) SysFreeString(fwBstr2);
if (pNetFwRule != NULL) pNetFwRule->Release();
if (pNetFwRules != NULL) pNetFwRules->Release();
if (pNetFwPolicy2 != NULL) pNetFwPolicy2->Release();
if (ret == 0) SetupWindowsFirewallOld(L"Mesh Agent background service", processname);
return ret;
}
int ClearWindowsFirewall(wchar_t* processname)
{
HRESULT h = 0;
BSTR fwBstr = NULL;
INetFwMgr* fwMgr = NULL;
INetFwPolicy* fwPolicy = NULL;
INetFwProfile* fwProfile = NULL;
INetFwRules* pNetFwRules = NULL;
INetFwPolicy2* pNetFwPolicy2 = NULL;
INetFwAuthorizedApplications* fwApps = NULL;
BSTR s1 = NULL, s2 = NULL, s3 = NULL, s4 = NULL;
int i, ret = 0;
// Convert the friendly name.
if ((s1 = SysAllocString(L"Mesh Agent peer-to-peer (UDP)")) == NULL) goto error;
if ((s2 = SysAllocString(L"Mesh Agent management (UDP)")) == NULL) goto error;
if ((s3 = SysAllocString(L"Mesh Agent peer-to-peer (TCP)")) == NULL) goto error;
if ((s4 = SysAllocString(L"Mesh Agent management (TCP)")) == NULL) goto error;
// Setup firewall interface
if (FAILED(CoCreateInstance(__uuidof(NetFwMgr), NULL, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void**)&fwMgr))) goto error;
// Get firewall policy, profile, apps
if (FAILED(fwMgr->get_LocalPolicy(&fwPolicy))) goto error;
if (FAILED(fwPolicy->get_CurrentProfile(&fwProfile))) goto error;
if (FAILED(fwProfile->get_AuthorizedApplications(&fwApps))) goto error;
// Remove the firewall rules
fwBstr = SysAllocString(processname);
if (fwBstr == NULL) goto error;
for (i = 0; i < 4; i++) { if (FAILED(fwApps->Remove(fwBstr))) goto error; }
// Fetch the rules & remove our rules
if (FAILED(CoCreateInstance(__uuidof(NetFwPolicy2), NULL, CLSCTX_ALL, __uuidof(INetFwPolicy2), (void**)&pNetFwPolicy2))) goto error;
if (FAILED(pNetFwPolicy2->get_Rules(&pNetFwRules))) goto error;
for (i = 0; i < 4; i++) { h = pNetFwRules->Remove(s1); h = pNetFwRules->Remove(s2); h = pNetFwRules->Remove(s3); h = pNetFwRules->Remove(s4); }
ret = 1;
error:
// Cleanup
if (fwBstr != NULL) SysFreeString(fwBstr);
if (fwApps != NULL) fwApps->Release();
if (fwProfile != NULL) fwProfile->Release();
if (fwPolicy != NULL) fwPolicy->Release();
if (fwMgr != NULL) fwMgr->Release();
if (pNetFwRules != NULL) pNetFwRules->Release();
if (pNetFwPolicy2 != NULL) pNetFwPolicy2->Release();
if (s1 != NULL) SysFreeString(s1);
if (s2 != NULL) SysFreeString(s2);
if (s3 != NULL) SysFreeString(s3);
if (s4 != NULL) SysFreeString(s4);
return ret;
}
}
#endif

29
meshservice/resource.h Normal file
View File

@@ -0,0 +1,29 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MeshService.rc
//
#define IDI_ICON1 101
#define IDD_INSTALLDIALOG 103
#define IDC_BUTTON2 1002
#define IDC_INSTALLBUTTON 1002
#define IDC_BUTTON3 1004
#define IDC_UNINSTALLBUTTON 1004
#define IDC_STATUSTEXT 1005
#define IDC_VERSIONTEXT 1006
#define IDC_HASHTEXT 1007
#define IDC_HASHTEXT2 1008
#define IDC_POLICYTEXT 1008
#define IDC_HASHTEXT3 1011
#define IDC_SERVERID 1011
#define IDC_SERVERLOCATION 1012
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MicroLMS", "console\MicroLMS.vcxproj", "{03A09084-0576-45C5-97CA-B83B1A8688B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Debug|x64.ActiveCfg = Debug|x64
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Debug|x64.Build.0 = Debug|x64
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Debug|x86.ActiveCfg = Debug|Win32
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Debug|x86.Build.0 = Debug|Win32
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Release|x64.ActiveCfg = Release|x64
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Release|x64.Build.0 = Release|x64
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Release|x86.ActiveCfg = Release|Win32
{03A09084-0576-45C5-97CA-B83B1A8688B8}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MicroLMSService", "service\MicroLMSService.vcxproj", "{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|Win32.ActiveCfg = Debug|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|Win32.Build.0 = Debug|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|x64.ActiveCfg = Debug|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Debug|x64.Build.0 = Debug|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|Win32.ActiveCfg = Release|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|Win32.Build.0 = Release|Win32
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|x64.ActiveCfg = Release|x64
{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,98 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,1
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Mesh Messenger"
VALUE "FileVersion", "0.0.0.1"
VALUE "InternalName", "MeshConsole"
VALUE "OriginalFilename", "MeshMessenger.exe"
VALUE "ProductName", "Mesh Messenger"
VALUE "ProductVersion", "0, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,249 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\microstack\ILibCrypto.c" />
<ClCompile Include="..\heci\HECIWin.c" />
<ClCompile Include="..\heci\LMEConnection.c" />
<ClCompile Include="..\heci\PTHICommand.c" />
<ClCompile Include="..\..\microstack\ILibAsyncServerSocket.c" />
<ClCompile Include="..\..\microstack\ILibAsyncSocket.c" />
<ClCompile Include="..\..\microstack\ILibParsers.c" />
<ClCompile Include="..\..\microstack\ILibWebClient.c" />
<ClCompile Include="..\..\microstack\ILibWebServer.c" />
<ClCompile Include="..\..\microstack\md5.c" />
<ClCompile Include="..\..\microstack\sha1.c" />
<ClCompile Include="..\lms\ILibLMS.c" />
<ClCompile Include="main.c" />
<ClCompile Include="stdafx.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\microstack\ILibCrypto.h" />
<ClInclude Include="..\heci\HECIWin.h" />
<ClInclude Include="..\heci\HECI_if.h" />
<ClInclude Include="..\heci\LMEConnection.h" />
<ClInclude Include="..\heci\LMS_if.h" />
<ClInclude Include="..\heci\LMS_if_constants.h" />
<ClInclude Include="..\heci\PTHICommand.h" />
<ClInclude Include="..\heci\StatusCodeDefinitions.h" />
<ClInclude Include="..\..\microstack\ILibAsyncServerSocket.h" />
<ClInclude Include="..\..\microstack\ILibAsyncSocket.h" />
<ClInclude Include="..\..\microstack\ILibParsers.h" />
<ClInclude Include="..\..\microstack\ILibWebClient.h" />
<ClInclude Include="..\..\microstack\ILibWebServer.h" />
<ClInclude Include="..\..\microstack\md5.h" />
<ClInclude Include="..\..\microstack\sha1.h" />
<ClInclude Include="..\lms\ILibLMS-WebSite.h" />
<ClInclude Include="..\lms\ILibLMS.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{03A09084-0576-45C5-97CA-B83B1A8688B8}</ProjectGuid>
<RootNamespace>MeshConsole</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>MicroLMS</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</PostBuildEventUseInBuild>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../../openssl/include;../../openssl/include/openssl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;MEMORY_CHECK;__STDC__;WINSOCK2;ILibWebServer_SESSION_TRACKING;MICROSTACK_NO_STDAFX;MICROSTACK_NOTLS;MICROSTACK_PROXY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<CallingConvention>Cdecl</CallingConvention>
<AssemblerOutput>NoListing</AssemblerOutput>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<Profile>false</Profile>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>ws2_32.lib;DbgHelp.lib;Setupapi.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateMapFile>
</GenerateMapFile>
<MapExports>
</MapExports>
<AssemblyDebug>true</AssemblyDebug>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../../openssl/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;WIN64;_DEBUG;_CONSOLE;MEMORY_CHECK;__STDC__;_CRT_SECURE_NO_WARNINGS;WINSOCK2;ILibWebServer_SESSION_TRACKING;NOCOMMANDER;MICROSTACK_NO_STDAFX;MICROSTACK_NOTLS;MICROSTACK_PROXY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>Iphlpapi.lib;DbgHelp.lib;ws2_32.lib;Setupapi.lib;Psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
<Profile>true</Profile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MinSpace</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>../../openssl/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;WINSOCK2;NOCOMMANDER;MICROSTACK_NO_STDAFX;MICROSTACK_NOTLS;MICROSTACK_PROXY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>Iphlpapi.lib;DbgHelp.lib;Setupapi.lib;ws2_32.lib;Psapi.lib;Crypt32.lib;Wintrust.lib;Version.lib;Wtsapi32.lib;%(AdditionalDependencies);Gdiplus.lib</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<PostBuildEvent>
<Command>signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshConsole" /du "http://opentools.homeip.net" "$(TargetPath)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>MinSpace</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>../../openssl/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;WIN64;NDEBUG;_CONSOLE;WINSOCK2;NOCOMMANDER;MICROSTACK_NO_STDAFX;MICROSTACK_NOTLS;MICROSTACK_PROXY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;DbgHelp.lib;Setupapi.lib;Psapi.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="main.c" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="..\heci\HECIWin.c">
<Filter>MEI</Filter>
</ClCompile>
<ClCompile Include="..\heci\PTHICommand.c">
<Filter>MEI</Filter>
</ClCompile>
<ClCompile Include="..\heci\LMEConnection.c">
<Filter>MEI</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibAsyncSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibParsers.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibWebClient.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibWebServer.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibAsyncServerSocket.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\sha1.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\md5.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibCrypto.c">
<Filter>Microstack</Filter>
</ClCompile>
<ClCompile Include="..\lms\ILibLMS.c">
<Filter>LMS</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="..\heci\HECI_if.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\heci\HECIWin.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\heci\PTHICommand.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\heci\StatusCodeDefinitions.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\heci\LMEConnection.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\heci\LMS_if.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\heci\LMS_if_constants.h">
<Filter>MEI</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibWebServer.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibAsyncServerSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibAsyncSocket.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibParsers.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibWebClient.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\sha1.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\md5.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibCrypto.h">
<Filter>Microstack</Filter>
</ClInclude>
<ClInclude Include="..\lms\ILibLMS.h">
<Filter>LMS</Filter>
</ClInclude>
<ClInclude Include="..\lms\ILibLMS-WebSite.h">
<Filter>LMS</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<Filter Include="MEI">
<UniqueIdentifier>{5878a0ef-e109-42f4-a6d2-8e20a623b275}</UniqueIdentifier>
</Filter>
<Filter Include="Microstack">
<UniqueIdentifier>{24205618-7a0a-4260-916f-f08e93a87031}</UniqueIdentifier>
</Filter>
<Filter Include="LMS">
<UniqueIdentifier>{83d6353d-960a-4869-9928-e164bcfa5c22}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
Micro LMS
------------------------------------------
Introduction
A implementation of Intel AMT LMS using Microstack.

140
microlms/console/main.c Normal file
View File

@@ -0,0 +1,140 @@
/*
Copyright 2006 - 2013 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if defined(WIN32) || defined (_WIN32_WCE)
#ifndef MICROSTACK_NO_STDAFX
#include "stdafx.h"
#endif
#endif
#if defined(WIN32)
#define _CRTDBG_MAP_ALLOC
#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
#endif
#if defined(WINSOCK2)
#include <winsock2.h>
#include <ws2tcpip.h>
#elif defined(WINSOCK1)
#include <winsock.h>
#include <wininet.h>
#endif
#include <signal.h>
#include "../../microstack/ILibParsers.h"
#include "../lms/ILibLMS.h"
#if defined(WIN32) & !defined(_CONSOLE)
#include "resource.h"
#endif
#if defined(WIN32) && defined (_DEBUG)
#include <crtdbg.h>
#endif
// The following macros set and clear, respectively, given bits
// of the C runtime library debug flag, as specified by a bitmask.
#ifdef _DEBUG
#define SET_CRT_DEBUG_FIELD(a) \
_CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
#define CLEAR_CRT_DEBUG_FIELD(a) \
_CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
#else
#define SET_CRT_DEBUG_FIELD(a) ((void) 0)
#define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
#endif
#ifdef MEMORY_CHECK
#ifdef WIN32
// This routine place comments at the head of a section of debug output
void OutputHeading( const char * explanation )
{
_RPT1( _CRT_WARN, "\n\n%s:\n**************************************************************************\n", explanation );
}
#endif
#endif
void *Chain = NULL;
struct ILibLMS_StateModule *MicroLMS = NULL;
extern void ctrl_SendSubscriptionEvent(char *data, int datalen);
void BreakSink(int s)
{
UNREFERENCED_PARAMETER( s );
signal(SIGINT, SIG_IGN); // To ignore any more ctrl-c interrupts
ILibStopChain(Chain);
}
#if defined(_POSIX) || defined (_CONSOLE)
int main(int argc, char **argv)
#else
DWORD WINAPI GPMain(LPVOID lpParameter)
#endif
{
// Shutdown on Ctrl + C
signal(SIGINT, BreakSink);
#ifdef _POSIX
signal(SIGPIPE, SIG_IGN);
#ifdef _DEBUG
//mtrace();
#endif
#endif
#ifdef MEMORY_CHECK
#ifdef WIN32
//SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF );
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF);
#endif
#endif
Chain = ILibCreateChain();
MicroLMS = ILibLMS_Create(Chain, NULL);
if (MicroLMS != NULL)
{
printf("Starting MicroLMS.\r\n");
ILibStartChain(Chain);
printf("Stopping MicroLMS.\r\n");
}
else
{
printf("Unable to launch MicroLMS. Check that Intel ME is present, MEI driver installed and run this executable as administrator.\r\n");
}
#ifdef MEMORY_CHECK
#ifdef WIN32
OutputHeading("Generating the final memory leak report\r\n");
_CrtCheckMemory();
_CrtDumpMemoryLeaks();
#endif
#endif
#ifdef _POSIX
#ifdef _DEBUG
//muntrace();
#endif
#endif
#ifdef _POSIX
exit(EXIT_SUCCESS);
#else
return 0;
#endif
}

58
microlms/console/makefile Normal file
View File

@@ -0,0 +1,58 @@
SOURCES = main.c ../microstack/ILibLMS.c
SOURCES += ../microstack/ILibAsyncServerSocket.c ../microstack/ILibAsyncSocket.c ../microstack/ILibWebServer.c ../microstack/ILibWebClient.c ../microstack/ILibParsers.c ../microstack/md5.c ../microstack/sha1.c
SOURCES += ../heci/HECILinux.c ../heci/LMEConnection.c ../heci/PTHICommand.c
SOURCES += $(ADDITIONALSOURCES)
OBJECTS = $(patsubst %.c,%.o, $(SOURCES))
EXENAME = microlms
# Compiler command name
CC = gcc
# need to be separate for dependency generation
INCDIRS = -I. -I../../microstack -I../../core
CFLAGS ?= -g -Wall -D_POSIX -D_DEBUG -DMICROSTACK_NOTLS -fno-strict-aliasing $(INCDIRS)
LDFLAGS ?= -g -L. -lpthread -ldl -lutil -lrt
.PHONY: all clean
all: $(EXENAME)
$(EXENAME): $(OBJECTS)
$(V)$(CC) $^ $(LDFLAGS) -o $@
release:
$(MAKE) $(MAKEFILE) CFLAGS="-O2 -Wall -D_POSIX -D_DEBUG -DMICROSTACK_NOTLS -D_DEBUGLMS -fno-strict-aliasing $(INCDIRS)" LDFLAGS="-L. -lpthread -ldl -lutil"
strip ./$(EXENAME)
linux32:
$(MAKE) $(MAKEFILE) CFLAGS="-m32 -O2 -Wall -D_POSIX -D_DEBUG -DMICROSTACK_NOTLS -D_DEBUGLMS -fno-strict-aliasing $(INCDIRS)" LDFLAGS="-L. -lpthread -ldl -lutil -lrt -m32"
strip ./$(EXENAME)
linux64:
$(MAKE) $(MAKEFILE) CFLAGS="-O2 -Wall -D_POSIX -D_DEBUG -DMICROSTACK_NOTLS -D_DEBUGLMS -fno-strict-aliasing $(INCDIRS)" LDFLAGS="-L. -lpthread -ldl -lrt -lutil"
strip ./$(EXENAME)
clean:
rm -f *.o
rm -f *.o *~ microlms
rm -f ../heci/*.o
rm -f ../microstack/*.o
depend: $(SOURCES)
$(CC) -M $(CFLAGS) $(SOURCES) $(HEADERS) > depend
run:all
rm -f mtrax
set MALLOC_TRACE=mtrax
export MALLOC_TRACE;
./$(EXENAME)
mtrace ./$(EXENAME) mtrax
vrun:all
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes ./signer_linux
trace:
mtrace ./$(EXENAME) mtrax

View File

@@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MeshMessenger.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// TinyMesh.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

15
microlms/console/stdafx.h Normal file
View File

@@ -0,0 +1,15 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here

View File

@@ -0,0 +1,13 @@
#pragma once
// The following macros define the minimum required platform. The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
// your application. The macros work by enabling all features available on platform versions up to and
// including the version specified.
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif

437
microlms/heci/HECILinux.c Normal file
View File

@@ -0,0 +1,437 @@
/******************************************************************************
* Intel Management Engine Interface (Intel MEI) Linux driver
* Intel MEI Interface Header
*
* This file is provided under a dual BSD/GPLv2 license. When using or
* redistributing this file, you may do so under either license.
*
* GPL LICENSE SUMMARY
*
* Copyright(c) 2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
* USA
*
* The full GNU General Public License is included in this distribution
* in the file called LICENSE.GPL.
*
* Contact Information:
* Intel Corporation.
* linux-mei@linux.intel.com
* http://www.intel.com
*
* BSD LICENSE
*
* Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <stdbool.h>
#include "HECILinux.h"
//#include "../core/utils.h"
/*****************************************************************************
* Intel Management Engine Interface
*****************************************************************************/
#ifdef _HECIDEBUG
#define mei_msg(_me, fmt, ARGS...) do { printf(fmt, ##ARGS); } while (0)
#define mei_err(_me, fmt, ARGS...) do { printf(fmt, ##ARGS); } while (0)
#else
#define mei_msg(_me, fmt, ARGS...)
#define mei_err(_me, fmt, ARGS...)
#endif
static void mei_deinit(struct mei *cl)
{
// mei_err(cl, "mei_deinit()\n");
if (cl->initialized == false) return;
cl->initialized = false;
if (cl->fd != -1) close(cl->fd);
cl->fd = -1;
cl->buf_size = 0;
cl->prot_ver = 0;
sem_destroy(&(cl->Lock));
}
static bool mei_init(struct mei *me, const uuid_le *guid, unsigned char req_protocol_version, bool verbose)
{
int result;
struct mei_client *cl;
struct mei_connect_client_data data;
mei_deinit(me);
me->verbose = verbose;
me->fd = open("/dev/mei", O_RDWR);
if (me->fd == -1) {
me->fd = open("/dev/mei0", O_RDWR);
if (me->fd == -1) {
// mei_err(me, "Cannot establish a handle to the Intel MEI driver\n");
goto err;
}
}
memcpy(&me->guid, guid, sizeof(*guid));
memset(&data, 0, sizeof(data));
me->initialized = true;
memcpy(&data.in_client_uuid, &me->guid, sizeof(me->guid));
result = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT, &data);
if (result) {
mei_err(me, "IOCTL_MEI_CONNECT_CLIENT receive message. err=%d,%d\n", result, errno);
goto err;
}
cl = &data.out_client_properties;
//mei_msg(me, "max_message_length %d\n", cl->max_msg_length);
//mei_msg(me, "protocol_version %d\n", cl->protocol_version);
if ((req_protocol_version > 0) && (cl->protocol_version != req_protocol_version)) {
mei_err(me, "Intel MEI protocol version not supported\n");
goto err;
}
me->buf_size = cl->max_msg_length;
me->prot_ver = cl->protocol_version;
sem_init(&(me->Lock), 0, 1);
mei_msg(me, "mei init succ");
return true;
err:
mei_deinit(me);
return false;
}
static ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer, ssize_t len, unsigned long timeout)
{
ssize_t rc;
mei_msg(me, "call read length = %zd\n", len);
rc = read(me->fd, buffer, len);
if (rc < 0) {
mei_err(me, "read failed with status %zd %s\n", rc, strerror(errno));
mei_deinit(me);
} else {
mei_msg(me, "read succeeded with result %zd\n", rc);
}
return rc;
}
static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, ssize_t len, unsigned long timeout)
{
// struct timeval tv;
ssize_t written;
ssize_t rc;
// fd_set set;
// tv.tv_sec = timeout / 1000;
// tv.tv_usec = (timeout % 1000) * 1000000;
mei_msg(me, "call write length = %zd, cmd=%d\n", len, (int)buffer[0]);
sem_wait(&(me->Lock));
written = write(me->fd, buffer, len);
if (written < 0) {
rc = -errno;
mei_err(me, "write failed with status %zd %s\n", written, strerror(errno));
goto out;
}
/*
FD_ZERO(&set);
FD_SET(me->fd, &set);
rc = select(me->fd + 1 , &set, NULL, NULL, &tv);
if (rc > 0 && FD_ISSET(me->fd, &set)) {
mei_msg(me, "write success\n");
} else if (rc == 0) {
mei_err(me, "write failed on timeout with status 0, timeout = %ld, written=%ld, cmd=%d\n", timeout, written, (int)buffer[0]);
goto out;
} else { // rc < 0
mei_err(me, "write failed on select with status %zd\n", rc);
goto out;
}
*/
rc = written;
out:
sem_post(&(me->Lock));
mei_msg(me, "call write written = %zd\n", written);
if (rc < 0) mei_deinit(me);
return rc;
}
/***************************************************************************
* Intel Advanced Management Technology Host Interface
***************************************************************************/
struct amt_host_if_msg_header {
struct amt_version version;
uint16_t _reserved;
uint32_t command;
uint32_t length;
} __attribute__((packed));
struct amt_host_if_resp_header {
struct amt_host_if_msg_header header;
uint32_t status;
unsigned char data[0];
} __attribute__((packed));
const uuid_le MEI_IAMTHIF = {.b={0x28, 0x00, 0xf8, 0x12, 0xb7, 0xb4, 0x2d, 0x4b, 0xac, 0xa8, 0x46, 0xe0, 0xff, 0x65, 0x81, 0x4c}};
const uuid_le MEI_LMEIF = {.b={0xdb, 0xa4, 0x33, 0x67, 0x76, 0x04, 0x7b, 0x4e, 0xb3, 0xaf, 0xbc, 0xfc, 0x29, 0xbe, 0xe7, 0xa7}};
#define AMT_HOST_IF_CODE_VERSIONS_REQUEST 0x0400001A
#define AMT_HOST_IF_CODE_VERSIONS_RESPONSE 0x0480001A
const struct amt_host_if_msg_header CODE_VERSION_REQ = {
.version = {AMT_MAJOR_VERSION, AMT_MINOR_VERSION},
._reserved = 0,
.command = AMT_HOST_IF_CODE_VERSIONS_REQUEST,
.length = 0
};
static bool amt_host_if_init(struct amt_host_if *acmd, unsigned long send_timeout, bool verbose, int client)
{
acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
if (client == 0) { acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0, verbose); }
else if (client == 1) { acmd->initialized = mei_init(&acmd->mei_cl, &MEI_LMEIF, 0, verbose); }
return acmd->initialized;
}
static void amt_host_if_deinit(struct amt_host_if *acmd)
{
mei_deinit(&acmd->mei_cl);
acmd->initialized = false;
}
static uint32_t amt_verify_code_versions(const struct amt_host_if_resp_header *resp)
{
uint32_t status = AMT_STATUS_SUCCESS;
struct amt_code_versions *code_ver;
size_t code_ver_len;
uint32_t ver_type_cnt;
uint32_t len;
uint32_t i;
code_ver = (struct amt_code_versions *)resp->data;
/* length - sizeof(status) */
code_ver_len = resp->header.length - sizeof(uint32_t);
ver_type_cnt = code_ver_len -
sizeof(code_ver->bios) -
sizeof(code_ver->count);
if (code_ver->count != ver_type_cnt / sizeof(struct amt_version_type)) {
status = AMT_STATUS_INTERNAL_ERROR;
goto out;
}
for (i = 0; i < code_ver->count; i++) {
len = code_ver->versions[i].description.length;
if (len > AMT_UNICODE_STRING_LEN) {
status = AMT_STATUS_INTERNAL_ERROR;
goto out;
}
len = code_ver->versions[i].version.length;
if (code_ver->versions[i].version.string[len] != '\0' ||
len != strlen(code_ver->versions[i].version.string)) {
status = AMT_STATUS_INTERNAL_ERROR;
goto out;
}
}
out:
return status;
}
static uint32_t amt_verify_response_header(uint32_t command, const struct amt_host_if_msg_header *resp_hdr, uint32_t response_size)
{
if (response_size < sizeof(struct amt_host_if_resp_header)) {
return AMT_STATUS_INTERNAL_ERROR;
} else if (response_size != (resp_hdr->length +
sizeof(struct amt_host_if_msg_header))) {
return AMT_STATUS_INTERNAL_ERROR;
} else if (resp_hdr->command != command) {
return AMT_STATUS_INTERNAL_ERROR;
} else if (resp_hdr->_reserved != 0) {
return AMT_STATUS_INTERNAL_ERROR;
} else if (resp_hdr->version.major != AMT_MAJOR_VERSION ||
resp_hdr->version.minor < AMT_MINOR_VERSION) {
return AMT_STATUS_INTERNAL_ERROR;
}
return AMT_STATUS_SUCCESS;
}
static uint32_t amt_host_if_call(struct amt_host_if *acmd, const unsigned char *command, ssize_t command_sz, uint8_t **read_buf, uint32_t rcmd, unsigned int expected_sz)
{
uint32_t in_buf_sz;
uint32_t out_buf_sz;
ssize_t written;
uint32_t status;
struct amt_host_if_resp_header *msg_hdr;
in_buf_sz = acmd->mei_cl.buf_size;
*read_buf = (uint8_t *)malloc(sizeof(uint8_t) * in_buf_sz);
if (*read_buf == NULL) return AMT_STATUS_SDK_RESOURCES;
memset(*read_buf, 0, in_buf_sz);
msg_hdr = (struct amt_host_if_resp_header *)*read_buf;
written = mei_send_msg(&acmd->mei_cl, command, command_sz, acmd->send_timeout);
if (written != command_sz)
return AMT_STATUS_INTERNAL_ERROR;
out_buf_sz = mei_recv_msg(&acmd->mei_cl, *read_buf, in_buf_sz, 2000);
if (out_buf_sz <= 0)
return AMT_STATUS_HOST_IF_EMPTY_RESPONSE;
status = msg_hdr->status;
if (status != AMT_STATUS_SUCCESS)
return status;
status = amt_verify_response_header(rcmd, &msg_hdr->header, out_buf_sz);
if (status != AMT_STATUS_SUCCESS)
return status;
if (expected_sz && expected_sz != out_buf_sz)
return AMT_STATUS_INTERNAL_ERROR;
return AMT_STATUS_SUCCESS;
}
static uint32_t amt_get_code_versions(struct amt_host_if *cmd, struct amt_code_versions *versions)
{
struct amt_host_if_resp_header *response = NULL;
uint32_t status;
status = amt_host_if_call(cmd,
(const unsigned char *)&CODE_VERSION_REQ,
sizeof(CODE_VERSION_REQ),
(uint8_t **)&response,
AMT_HOST_IF_CODE_VERSIONS_RESPONSE, 0);
if (status != AMT_STATUS_SUCCESS)
goto out;
status = amt_verify_code_versions(response);
if (status != AMT_STATUS_SUCCESS)
goto out;
memcpy(versions, response->data, sizeof(struct amt_code_versions));
out:
if (response != NULL)
free(response);
return status;
}
/************************** end of amt_host_if_command ***********************/
int MEI_globalSetup = 0;
struct MEImodule MEI_global;
bool heci_Init(struct MEImodule* module, int client)
{
if (module == NULL && client != 0) return false;
if (module == NULL) { module = &MEI_global; if (MEI_globalSetup == 1) return true; }
memset(module, 0 , sizeof(struct MEImodule));
if (!amt_host_if_init(&(module->acmd), 5000, module->verbose, client)) return false;
if (module == &MEI_global) MEI_globalSetup = 1;
module->inited = true;
if (client == 0) module->status = amt_get_code_versions(&(module->acmd), &(module->ver));
return true;
}
void heci_Deinit(struct MEImodule* module)
{
if (module == NULL) { module = &MEI_global; MEI_globalSetup = 0; }
amt_host_if_deinit(&(module->acmd));
memset(module, 0, sizeof(struct MEImodule));
}
int heci_ReceiveMessage(struct MEImodule* module, unsigned char *buffer, int len, unsigned long timeout) // Timeout default is 2000
{
if (module == NULL) module = &MEI_global;
return mei_recv_msg(&(module->acmd.mei_cl), buffer, len, timeout);
}
int heci_SendMessage(struct MEImodule* module, const unsigned char *buffer, int len, unsigned long timeout) // Timeout default is 2000
{
if (module == NULL) module = &MEI_global;
return mei_send_msg(&(module->acmd.mei_cl), buffer, len, timeout);
}
unsigned int heci_GetBufferSize(struct MEImodule* module)
{
if (module == NULL) module = &MEI_global;
if (module->inited) return module->acmd.mei_cl.buf_size;
return -1;
}
unsigned char heci_GetProtocolVersion(struct MEImodule* module)
{
if (module == NULL) module = &MEI_global;
if (module->inited) return module->acmd.mei_cl.prot_ver;
return 0;
}
// Get the version of MEI from the last MEI init.
bool heci_GetHeciVersion(struct MEImodule* module, HECI_VERSION *version)
{
version->major = AMT_MAJOR_VERSION;
version->minor = AMT_MINOR_VERSION;
return true;
}
bool heci_IsInitialized(struct MEImodule* module)
{
return module->inited;
}

120
microlms/heci/HECILinux.h Normal file
View File

@@ -0,0 +1,120 @@
/*******************************************************************************
* Copyright (C) 2004-2008 Intel Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corp. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef __HECI_LINUX_H__
#define __HECI_LINUX_H__
#include "HECI_if.h"
#include "mei.h"
#include <semaphore.h>
#include <stdint.h>
#ifndef bool
#define bool int
#endif
/***************************************************************************
* Intel Advanced Management Technology ME Client
***************************************************************************/
#define AMT_MAJOR_VERSION 1
#define AMT_MINOR_VERSION 1
#define AMT_STATUS_SUCCESS 0x0
#define AMT_STATUS_INTERNAL_ERROR 0x1
#define AMT_STATUS_NOT_READY 0x2
#define AMT_STATUS_INVALID_AMT_MODE 0x3
#define AMT_STATUS_INVALID_MESSAGE_LENGTH 0x4
#define AMT_STATUS_HOST_IF_EMPTY_RESPONSE 0x4000
#define AMT_STATUS_SDK_RESOURCES 0x1004
#define AMT_BIOS_VERSION_LEN 65
#define AMT_VERSIONS_NUMBER 50
#define AMT_UNICODE_STRING_LEN 20
struct amt_unicode_string {
uint16_t length;
char string[AMT_UNICODE_STRING_LEN];
} __attribute__((packed));
struct amt_version_type {
struct amt_unicode_string description;
struct amt_unicode_string version;
} __attribute__((packed));
struct amt_version {
uint8_t major;
uint8_t minor;
} __attribute__((packed));
struct amt_code_versions {
uint8_t bios[AMT_BIOS_VERSION_LEN];
uint32_t count;
struct amt_version_type versions[AMT_VERSIONS_NUMBER];
} __attribute__((packed));
struct mei {
uuid_le guid;
bool initialized;
bool verbose;
unsigned int buf_size;
unsigned char prot_ver;
int fd;
sem_t Lock;
};
struct amt_host_if {
struct mei mei_cl;
unsigned long send_timeout;
bool initialized;
};
struct MEImodule
{
struct amt_code_versions ver;
struct amt_host_if acmd;
unsigned int i;
unsigned int status;
bool verbose;
bool inited;
};
bool heci_Init(struct MEImodule* module, int client);
void heci_Deinit(struct MEImodule* module);
int heci_ReceiveMessage(struct MEImodule* module, unsigned char *buffer, int len, unsigned long timeout); // Timeout default is 2000
int heci_SendMessage(struct MEImodule* module, const unsigned char *buffer, int len, unsigned long timeout); // Timeout default is 2000
unsigned int heci_GetBufferSize(struct MEImodule* module);
unsigned char heci_GetProtocolVersion(struct MEImodule* module);
bool heci_GetHeciVersion(struct MEImodule* module, HECI_VERSION *version);
bool heci_IsInitialized(struct MEImodule* module);
#endif // __HECI_LINUX_H__

399
microlms/heci/HECIWin.c Normal file
View File

@@ -0,0 +1,399 @@
/*******************************************************************************
* Copyright (C) 2004-2008 Intel Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corp. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
#include <windows.h>
#include <setupapi.h>
#include <initguid.h>
#include <winioctl.h>
#include "HECIWin.h"
#include "heci_if.h"
#define false 0
#define true 1
#define HECI_MAX_LINE_LEN 300
DEFINE_GUID(GUID_DEVINTERFACE_HECI, 0xE2D1FF34, 0x3458, 0x49A9, 0x88, 0xDA, 0x8E, 0x69, 0x15, 0xCE, 0x9B, 0xE5);
DEFINE_GUID(HECI_PTHI_GUID , 0x12F80028, 0xB4B7, 0x4b2d, 0xAC, 0xA8, 0x46, 0xE0, 0xFF, 0x65, 0x81, 0x4c);
DEFINE_GUID(LME_GUID , 0x6733a4db, 0x0476, 0x4e7b, 0xb3, 0xaf, 0xbc, 0xfc, 0x29, 0xbe, 0xe7, 0xa7);
//VOID _displayHECIError(UINT32 errorCode,DWORD lastError);
//VOID _displayHECIData(UINT32 messageId);
int heci_doIoctl(struct MEImodule* module, DWORD code, void *inbuf, int inlen, void *outbuf, int outlen);
struct MEImodule MEI_global;
/***************************** public functions *****************************/
unsigned int heci_GetBufferSize(struct MEImodule* module) { if (module != NULL) return module->_bufSize; else return MEI_global._bufSize; }
unsigned char heci_GetProtocolVersion(struct MEImodule* module) { if (module != NULL) return module->_protocolVersion; else return MEI_global._protocolVersion; }
bool heci_IsInitialized(struct MEImodule* module) { if (module != NULL) return module->_initialized; else return MEI_global._initialized; }
bool heci_GetHeciVersion(struct MEImodule* module, HECI_VERSION *version)
{
if (module == NULL) module = &MEI_global;
if (module->m_haveHeciVersion)
{
memcpy_s(version, sizeof(HECI_VERSION), &(module->m_heciVersion), sizeof(HECI_VERSION));
return true;
}
return false;
}
bool heci_Init(struct MEImodule* module, int client)
{
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceDetail = NULL;
HDEVINFO hDeviceInfo;
DWORD bufferSize;
SP_DEVICE_INTERFACE_DATA interfaceData;
LONG ii = 0;
int result;
HECI_CLIENT properties;
GUID guid;
if (client == 0) guid = HECI_PTHI_GUID;
if (client == 1) guid = LME_GUID;
if (module == NULL) module = &MEI_global;
module->_verbose = false;
if (module->_initialized) {
heci_Deinit(module);
}
// Find all devices that have our interface
hDeviceInfo = SetupDiGetClassDevs((LPGUID)&GUID_DEVINTERFACE_HECI, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hDeviceInfo == INVALID_HANDLE_VALUE) {
if (module->_verbose) {
//_displayHECIError(GET_CLASS_DEVS,GetLastError());
}
return false; //GET_CLASS_DEVS;
}
// Setup the interface data struct
interfaceData.cbSize = sizeof(interfaceData);
for (ii = 0;
SetupDiEnumDeviceInterfaces(hDeviceInfo, NULL, (LPGUID)&GUID_DEVINTERFACE_HECI, ii, &interfaceData);
++ii) {
// Found our device instance
if (!SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &interfaceData, NULL, 0, &bufferSize, NULL)) {
DWORD err = GetLastError();
if (err != ERROR_INSUFFICIENT_BUFFER) {
if (module->_verbose) {
//_displayHECIError(GET_INTERFACE_DETAIL,err);
}
continue;
}
}
// Allocate a big enough buffer to get detail data
deviceDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(bufferSize);
if (deviceDetail == NULL) {
if (module->_verbose) {
//_displayHECIError(ALLOCATE_MEMORY_ERROR,0);
}
continue;
}
// Setup the device interface struct
deviceDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
// Try again to get the device interface detail info
if (!SetupDiGetDeviceInterfaceDetail(hDeviceInfo, &interfaceData, deviceDetail, bufferSize, NULL, NULL))
{
/*
if (_verbose)
{
DWORD err = GetLastError();
_displayHECIError(GET_INTERFACE_DETAIL,err);
}
*/
free(deviceDetail);
deviceDetail = NULL;
continue;
}
break;
}
SetupDiDestroyDeviceInfoList(hDeviceInfo);
if (deviceDetail == NULL) {
if (module->_verbose) {
//_displayHECIError(FIND_HECI_FAILURE,0);
}
return false; //FIND_HECI_FAILURE;
}
module->_handle = CreateFile(deviceDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
free(deviceDetail);
if (module->_handle == INVALID_HANDLE_VALUE) {
if (module->_verbose) {
//_displayHECIError(CREATE_HECI_FILE_FAILURE,GetLastError());
}
return false; //CREATE_HECI_FILE_FAILURE;
}
module->_initialized = true;
result = heci_doIoctl(module, (DWORD)IOCTL_HECI_GET_VERSION, NULL, 0, &(module->m_heciVersion), sizeof(HECI_VERSION));
if (result != sizeof(HECI_VERSION)) {
if (module->_verbose) {
//_displayHECIError(GET_HECI_DRIVER_VERSION_FAILURE,0);
}
heci_Deinit(module);
return false; //GET_HECI_DRIVER_VERSION_FAILURE;
}
module->m_haveHeciVersion = true;
if (module->_verbose) {
//_displayHECIData(HECI_DRIVER_VERSION);
//_ftprintf(stdout,_T("%d.%d.%d.%d\n"), (m_heciVersion).major, (m_heciVersion).minor, (m_heciVersion).hotfix, (m_heciVersion).build);
}
memset(&properties, 0, sizeof(properties));
result = heci_doIoctl(module, (DWORD)IOCTL_HECI_CONNECT_CLIENT, (void*)(&guid), sizeof(GUID), &properties, sizeof(properties));
if (result != sizeof(properties))
{
if (module->_verbose) {
//_displayHECIError(HECI_CONNECT_TO_PTHI_CLIENT_FAILURE,0);
}
//Deinit();
return false; //HECI_CONNECT_TO_PTHI_CLIENT_FAILURE;
}
module->_bufSize = properties.MaxMessageLength;
return true;
}
void heci_Deinit(struct MEImodule* module)
{
if (module == NULL) module = &MEI_global;
if (module->_initialized == false) return;
module->_initialized = false;
module->_bufSize = 0;
if (module->_handle != INVALID_HANDLE_VALUE)
{
CloseHandle(module->_handle);
module->_handle = INVALID_HANDLE_VALUE;
}
}
int heci_ReceiveMessage(struct MEImodule* module, unsigned char *buffer, int len, unsigned long timeout) // Timeout default is 2000
{
DWORD bytesRead = 0;
int res;
HANDLE h_event = NULL;
OVERLAPPED overlapped;
DWORD error;
DWORD eventRes;
if (module == NULL) module = &MEI_global;
if ((h_event = CreateEvent(NULL, FALSE, FALSE, NULL)) == 0) goto out;
overlapped.hEvent = h_event;
overlapped.Offset = 0;
overlapped.OffsetHigh = 0;
res = ReadFile(module->_handle, buffer, len, &bytesRead, &overlapped);
error = GetLastError();
if ((0 == res) && (ERROR_IO_PENDING != error)) {
if (module->_verbose) {
//_displayHECIError(READ_FILE,GetLastError());
}
bytesRead = (DWORD)-1;
goto out;
}
eventRes = WaitForSingleObject(h_event, timeout);
if (eventRes == WAIT_TIMEOUT) {
bytesRead = 0;
goto out;
}
res = GetOverlappedResult(module->_handle, &overlapped, &bytesRead, true);
if (res == 0) {
if (module->_verbose) {
//_displayHECIError(READ_FILE,GetLastError());
}
bytesRead = (DWORD)-1;
goto out;
}
out:
if (h_event != NULL) CloseHandle(h_event);
if (bytesRead <= 0) heci_Deinit(module);
return bytesRead;
}
int heci_SendMessage(struct MEImodule* module, const unsigned char *buffer, int len, unsigned long timeout) // Timeout default is 2000
{
DWORD bytesWritten = 0;
int res;
HANDLE h_event = NULL;
OVERLAPPED overlapped;
DWORD lastError;
DWORD eventRes;
if (module == NULL) module = &MEI_global;
if ((h_event = CreateEvent(NULL, FALSE, FALSE, NULL)) == 0) goto out;
overlapped.hEvent = h_event;
overlapped.Offset = 0;
overlapped.OffsetHigh = 0;
res = WriteFile(module->_handle, buffer, len, &bytesWritten, &overlapped);
lastError = GetLastError();
if ((0 == res) && (ERROR_IO_PENDING !=lastError )) {
if (module->_verbose) {
//_displayHECIError(WRITE_FILE,GetLastError());
}
bytesWritten = (DWORD)-1;
goto out;
}
eventRes = WaitForSingleObject(h_event, timeout);
if (eventRes == WAIT_TIMEOUT) {
if (module->_verbose) {
//_displayHECIError(WRITE_FILE_TIME_OUT,0);
}
bytesWritten = 0;
goto out;
}
res = GetOverlappedResult(module->_handle, &overlapped, &bytesWritten, false);
if (res == 0) {
if (module->_verbose) {
//_displayHECIError(WRITE_FILE,GetLastError());
}
bytesWritten = (DWORD)-1;
goto out;
}
out:
if (h_event != NULL) CloseHandle(h_event);
if (bytesWritten <= 0) heci_Deinit(module);
return bytesWritten;
}
int heci_doIoctl(struct MEImodule* module, DWORD code, void *inbuf, int inlen, void *outbuf, int outlen)
{
int res;
DWORD bytesRead = 0;
HANDLE h_event = NULL;
OVERLAPPED overlapped;
if (module == NULL) module = &MEI_global;
if (!module->_initialized) return -1;
if ((h_event = CreateEvent(NULL, FALSE, FALSE, NULL)) == 0) goto out;
overlapped.hEvent = h_event;
overlapped.Offset = 0;
overlapped.OffsetHigh = 0;
res = DeviceIoControl(module->_handle, code, inbuf, inlen, outbuf, outlen, &bytesRead, &overlapped);
if ((0 == res) && (ERROR_IO_PENDING != GetLastError())) {
if (module->_verbose) {
//_displayHECIError(IOCTL_COMMAND,GetLastError());
}
bytesRead = (DWORD)-1;
goto out;
}
WaitForSingleObject(h_event, INFINITE);
res = GetOverlappedResult(module->_handle, &overlapped, &bytesRead, true);
if (res == 0) {
if (module->_verbose) {
//_displayHECIError(IOCTL_COMMAND,GetLastError());
}
bytesRead = (DWORD)-1;
goto out;
}
out:
if (h_event != NULL) CloseHandle(h_event);
if (bytesRead == (DWORD)-1) heci_Deinit(module);
return bytesRead;
}
TCHAR *_getErrMsg(DWORD err)
{
static TCHAR buffer[1024];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
err,
0,
buffer,
sizeof(buffer) - 1,
0);
return buffer;
}
/*
// Display a HECI error message
void _displayHECIError(UINT32 errorCode, DWORD lastError)
{
TCHAR str[HECI_MAX_LINE_LEN];
TCHAR *msg;
LoadString(GetModuleHandle(NULL), HECI_ERROR_MESSAGE, str, sizeof(str)/sizeof(TCHAR));
_ftprintf(stderr, _T("%s"), str);
_ftprintf(stderr, _T("%s"), L" ");
LoadString(GetModuleHandle(NULL), errorCode , str, sizeof(str)/sizeof(TCHAR));
if(0!= lastError)
{
msg = _getErrMsg(lastError);
_ftprintf(stderr, _T("%s (%d): %s\n"),str, lastError, msg);
}
else
{
_ftprintf(stderr, _T("%s\n"),str);
}
}
// Display a HECI data message
void _displayHECIData(UINT32 messageId)
{
TCHAR str[HECI_MAX_LINE_LEN];
LoadString(GetModuleHandle(NULL), messageId , str, sizeof(str)/sizeof(TCHAR));
_ftprintf(stdout,_T("%s"),str);
_ftprintf(stdout,_T("%s"),L" ");
}
*/
#endif

66
microlms/heci/HECIWin.h Normal file
View File

@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (C) 2004-2008 Intel Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corp. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
#ifndef __HECI_WIN_H__
#define __HECI_WIN_H__
#include "HECI_if.h"
#include <stdio.h>
#include <windows.h>
#define bool int
struct MEImodule
{
bool _initialized;
bool _verbose;
unsigned int _bufSize;
unsigned char _protocolVersion;
int _fd;
bool m_haveHeciVersion;
HECI_VERSION m_heciVersion;
HANDLE _handle;
OVERLAPPED overlapped;
};
bool heci_Init(struct MEImodule* module, int client);
void heci_Deinit(struct MEImodule* module);
int heci_ReceiveMessage(struct MEImodule* module, unsigned char *buffer, int len, unsigned long timeout); // Timeout default is 2000
int heci_SendMessage(struct MEImodule* module, const unsigned char *buffer, int len, unsigned long timeout); // Timeout default is 2000
unsigned int heci_GetBufferSize(struct MEImodule* module);
unsigned char heci_GetProtocolVersion(struct MEImodule* module);
bool heci_GetHeciVersion(struct MEImodule* module, HECI_VERSION *version);
bool heci_IsInitialized(struct MEImodule* module);
#endif // __HECI_WIN_H__
#endif

223
microlms/heci/HECI_if.h Normal file
View File

@@ -0,0 +1,223 @@
/*******************************************************************************
* Copyright (C) 2004-2008 Intel Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corp. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
#ifndef __HECI_INTRFACE_H__
#define __HECI_INTRFACE_H__
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef char CHAR;
typedef unsigned long ULONG;
typedef UINT32 AMT_STATUS;
typedef UINT32 AMT_BOOLEAN;
typedef enum _HECI_STATUS {
HECI_STATUS_OK = 0x0,
HECI_STATUS_GENERAL_ERROR = 0x2000,
HECI_STATUS_LOCATE_DEVICE_ERROR,
HECI_STATUS_MEMORY_ACCESS_ERROR,
HECI_STATUS_WRITE_REGISTER_ERROR,
HECI_STATUS_MEMORY_ALLOCATION_ERROR,
HECI_STATUS_BUFFER_OVEREFLOW_ERROR,
HECI_STATUS_NOT_ENOUGH_MEMORY,
HECI_STATUS_MSG_TRANSMISSION_ERROR,
HECI_STATUS_VERSION_MISMATCH,
HECI_STATUS_UNEXPECTED_INTERRUPT_REASON,
HECI_STATUS_TIMEOUT_ERROR,
HECI_STATUS_UNEXPECTED_RESPONSE,
HECI_STATUS_UNKNOWN_MESSAGE,
HECI_STATUS_CANNOT_FOUND_HOST_CLIENT,
HECI_STATUS_CANNOT_FOUND_ME_CLIENT,
HECI_STATUS_CLIENT_ALREADY_CONNECTED,
HECI_STATUS_NO_FREE_CONNECTION,
HECI_STATUS_ILLEGAL_PARAMETER,
HECI_STATUS_FLOW_CONTROL_ERROR,
HECI_STATUS_NO_MESSAGE,
HECI_STATUS_BUFFER_TOO_LARGE,
HECI_STATUS_BUFFER_TOO_SMALL,
HECI_STATUS_BUFFER_NOT_EMPTY,
NUM_OF_HECI_STATUSES
} HECI_STATUS;
#ifdef WIN32
// Win32 code
#define AMT_LOCAL_AGENT_STATUS_SUCCESS 0
#define USAGE 1
#define ERROR_MESSAGE 2
#define VERSION_MESSAGE 3
#define HECI_ERROR_MESSAGE 4
#define UNKNOWN 5
#define HECI_CONNECT_TO_FWU_CLIENT_FAILURE 6
#define WRITE_FILE_TIME_OUT 7
#define ME_FW_INFO 8
#define ME_MODE 9
#define IOCTL_COMMAND 10
#define WRITE_FILE 11
#define READ_FILE 12
#define GET_CLASS_DEVS 13
#define GET_INTERFACE_DETAIL 14
#define ICH_VERSION 15
#define FIND_HECI_FAILURE 16
#define CREATE_HECI_FILE 17
#define CREATE_HECI_FILE_FAILURE 17
#define GET_HECI_DRIVER_VERSION_FAILURE 18
#define LA_STATUS_INTERNAL_ERROR 19
#define HECI_CONNECT_TO_PTHI_CLIENT_FAILURE 20
#define LA_HECI_ERROR 21
#define ALLOCATE_MEMORY_ERROR 22
#define LA_HECI_NOT_INSTALLED_ERROR 23
#define FW_BUFFER_IS_TO_SMALL 24
#define SEND_DATA_TO_FW_FAILURE 25
#define RECEIVE_DATA_FROM_FW_FAILURE 26
#define GET_INFO_FROM_HECI_FAILURE 27
#define MCH_VERSION 28
#define OEM_VENDOR 29
#define HECI_DRIVER_VERSION 30
#define CODE_MAJOR_VERSION 31
#define CODE_MINOR_VERSION 32
#define CODE_HOTFIX_VERSION 33
#define CODE_BUID_VERSION 34
#define BIOS_VERSION 35
#define AMT_CODE_VERSION 36
#define AMT_MODE 37
#define AMT_MODE_1 38
#define IDS_STRING39 39
#define AMT_MODE_2 39
#define PROVISIONING_STATE 40
#define STATE_PRE 41
#define STATE_IN 42
#define STATE_POST 43
#define IDS_STRING44 44
#define PARSE_KEYWORD_DISCOVERY_TEST 44
#define DISCOVERY_PASS 45
#define IDS_STRING46 46
#define DISCOVERY_FAILED 46
#define IDS_STRING47 47
#define PARSE_KEYWORD_ACTIVATE 47
#define PARSE_KEYWORD_OTP 48
#define PARSE_KEYWORD_DNS 49
#define PARSE_KEYWORD_VERBOSE 50
#define INVALID_PARAM_INPUT 51
#define USAGE_LOCAL_AGENT 52
#define USAGE_OPTIONS 53
#define USAGE_OPTIONS_OTP 54
#define USAGE_OPTIONS_DNS 55
#define USAGE_OPTIONS_DISCOVERY 56
#define USAGE_OPTIONS_ACTIVATE 57
#define USAGE_OPTIONS_VERBOSE 58
#define WORD_ZTC 59
#define WORD_ENABLED 60
#define WORD_DISABLED 61
#define WORD_PROVISIONING_TLS_MODE 62
#define WORD_PKI 63
#define WORD_PSK 64
#define WORD_RNG_SEED_STATUS 65
#define WORD_EXIST 66
#define WORD_IN_PROGRESS 67
#define WORD_NOT_EXIST 68
#define WORD_AMT_CONFIG_ACTIVATE 69
#define WORD_SUCCESS 70
#define IDS_STRING71 71
#define WORD_FAILURE 71
#define WORD_NOT_READY 72
#define IDS_STRING73 73
#define HASH_ENTRY 73
#define HECI_CONNECT_TO_WD_CLIENT_FAILURE 74
#define CHANGE_TO_AMT_FAILURE 75
#define IDS_STRING76 76
#define WORD_CHANGE_TO_AMT 76
#define FOUND 77
#define CERT_HASHES_IN_FW 78
#define NO_HANDLES_FOUND 79
#define CERT_HASH 80
#define FRIENDLY_NAME 81
#define FILE_DEVICE_HECI 0x8000
#define HECI_IOCTL(index) CTL_CODE(FILE_DEVICE_HECI, index, METHOD_BUFFERED, FILE_READ_DATA)
#define IOCTL_HECI_GET_VERSION CTL_CODE(FILE_DEVICE_HECI, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS)
#define IOCTL_HECI_CONNECT_CLIENT CTL_CODE(FILE_DEVICE_HECI, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS)
#define IOCTL_HECI_WD CTL_CODE(FILE_DEVICE_HECI, 0x802, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS)
#endif
#pragma pack(1)
typedef struct _HECI_VERSION {
UINT8 major;
UINT8 minor;
UINT8 hotfix;
UINT16 build;
} HECI_VERSION;
typedef struct _HECI_CLIENT {
UINT32 MaxMessageLength;
UINT8 ProtocolVersion;
} HECI_CLIENT;
typedef union _MEFWCAPS_SKU
{
UINT32 Data;
struct {
UINT32 Reserved :1; //Legacy
UINT32 Qst :1; //QST
UINT32 Asf :1; //ASF2
UINT32 Amt :1; //AMT Professional
UINT32 AmtFund :1; //AMT Fundamental
UINT32 Tpm :1; //TPM
UINT32 Dt :1;
UINT32 Fps :1; //Fingerprint Sensor
UINT32 HomeIT :1; //Home IT
UINT32 Mctp :1; //MCTP
UINT32 WoX :1;
UINT32 PmcPatch :1; //PMC Patch
UINT32 Ve :1; //VE
UINT32 Tdt :1; //Theft Deterrent Technology
UINT32 Corp :1; //Corporate
UINT32 Reserved2 :17;
} Fields;
} MEFWCAPS_SKU;
typedef enum _MEFWCAPS_MANAGEABILITY_SUPP
{
MEFWCAPS_MANAGEABILITY_SUPP_NONE = 0,
MEFWCAPS_MANAGEABILITY_SUPP_AMT,
MEFWCAPS_MANAGEABILITY_SUPP_ASF,
MEFWCAPS_MANAGEABILITY_SUPP_CP
} MEFWCAPS_MANAGEABILITY_SUPP;
#pragma pack()
#endif // __HECI_INTRFACE_H__
#endif

View File

@@ -0,0 +1,559 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _MINCORE
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "LMEConnection.h"
#include "LMS_if.h"
#include "../../microstack/ILibParsers.h"
#define MEI_IO_TIMEOUT 1000
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
const unsigned int LME_RX_WINDOW_SIZE = 4096;
int LME_sendMessage(struct LMEConnection* module, unsigned char *buffer, int len);
void LME_doRX(struct LMEConnection* module, unsigned char *rxBuffer, unsigned int bytesRead);
void LME_apfGlobalRequest(struct LMEConnection* module, unsigned char *rxBuffer, unsigned int bytesRead, int *status);
void LME_Deinit(struct LMEConnection* module);
bool LME_IsInitialized(struct LMEConnection* module)
{
// Lock il(_initLock);
bool ret = (bool)(module->initState == INIT_STATE_CONNECTED);
return ret;
}
#ifdef WIN32
DWORD WINAPI LME_Thread(void* obj)
#else
void LME_Thread(void* obj)
#endif
{
#ifdef WIN32
HECI_VERSION version;
#endif
int len = 0;
int bufsize = 0;
unsigned char* data = NULL;
struct LMEConnection* module = (struct LMEConnection*)obj;
//printf("LMS THREAD START\r\n");
do {
bufsize = heci_GetBufferSize(&(module->mei));
if ((data = (unsigned char*)malloc(bufsize)) == NULL) ILIBCRITICALEXIT(254);
do {
len = heci_ReceiveMessage(&(module->mei), data, bufsize, 0xFFFFFFFF);
//printf("LMS THREAD READ LEN=%d\r\n", len);
if (len > 0 && data != NULL) LME_doRX(module, data, len);
} while (len >= 0);
module->cb(module, module->cbParam, NULL, 0);
module->initState = INIT_STATE_DISCONNECTED;
free(data);
// printf("LMS TRYING RECONNECT\r\n");
while (module->exit == 0 && module->initState == INIT_STATE_DISCONNECTED)
{
// Setup the MEI interface with the LME GUID
#ifdef WIN32
if (heci_Init(&(module->mei), 1) == TRUE && heci_GetHeciVersion(&(module->mei), &version) == TRUE && version.major >= LMS_PROTOCOL_VERSION) { module->initState = INIT_STATE_CONNECTED; }
#else
if (heci_Init(&(module->mei), 1) == TRUE && heci_GetProtocolVersion(&(module->mei)) >= LMS_PROTOCOL_VERSION) { module->initState = INIT_STATE_CONNECTED; }
#endif
if (module->exit == 0 && module->initState == INIT_STATE_DISCONNECTED)
{
// printf("LMS THREAD SLEEP\r\n");
#ifdef WIN32
Sleep(2000);
#else
sleep(2);
#endif
}
//if (module->initState == INIT_STATE_CONNECTED) printf("LMS THREAD RECONNECT\r\n");
}
}
while (module->exit == 0);
// printf("LMS THREAD QUIT\r\n");
module->exit = 2;
#ifdef WIN32
return 0;
#endif
}
// Setup the LME connection
bool LME_Init(struct LMEConnection* module, MEICallback cb, void *param)
{
#ifdef WIN32
HECI_VERSION version;
#endif
// Setup the state object
memset(module, 0, sizeof(struct LMEConnection));
module->initState = INIT_STATE_DISCONNECTED;
module->cb = cb;
module->cbParam = param;
// Setup the MEI interface with the LME GUID
#ifdef WIN32
if (heci_Init(&(module->mei), 1) == FALSE || heci_GetHeciVersion(&(module->mei), &version) == FALSE || version.major < LMS_PROTOCOL_VERSION) { module->initState = INIT_STATE_DISCONNECTED; return FALSE; }
#else
if (heci_Init(&(module->mei), 1) == FALSE || heci_GetProtocolVersion(&(module->mei)) < LMS_PROTOCOL_VERSION) { module->initState = INIT_STATE_DISCONNECTED; return FALSE; }
#endif
module->initState = INIT_STATE_CONNECTED;
if ((module->txBuffer = (unsigned char*)malloc(LME_GetMeiBufferSize(module))) == NULL) ILIBCRITICALEXIT(254);
// Create the thread that will read the MEI/LME stream
ILibSpawnNormalThread((voidfp1)(&LME_Thread), module);
return TRUE;
}
// Disconnect the LME connection
void LME_Deinit(struct LMEConnection* module)
{
//printf("LME_Deinit()\r\n");
if (module == NULL) return;
if (module->initState == INIT_STATE_CONNECTED) { heci_Deinit(&(module->mei)); }
module->initState = INIT_STATE_DISCONNECTED;
}
// Exit LME
void LME_Exit(struct LMEConnection* module)
{
int l = 0;
//printf("LME_Exit()\r\n");
if (module == NULL) return;
if (module->exit == 0) module->exit = 1;
LME_Deinit(module);
#ifdef WIN32
while (module->exit != 2 && l < 40) { Sleep(100); l++; }
#else
/*
while (module->exit != 2 && l < 4)
{
printf("LME_Holding %d\r\n", l);
Sleep(1);
l++;
}
*/
#endif
if (module->txBuffer != NULL && l < 40) { free(module->txBuffer); module->txBuffer = NULL; }
}
// Send the APF disconnect message to the MEI
bool LME_Disconnect(struct LMEConnection* module, APF_DISCONNECT_REASON_CODE reasonCode)
{
unsigned char buf[sizeof(APF_DISCONNECT_MESSAGE)];
APF_DISCONNECT_MESSAGE *disconnectMessage = (APF_DISCONNECT_MESSAGE *)buf;
memset(disconnectMessage, 0, sizeof(buf));
disconnectMessage->MessageType = APF_DISCONNECT;
disconnectMessage->ReasonCode = htonl(reasonCode);
return (LME_sendMessage(module, buf, sizeof(buf)) == sizeof(buf));
}
// Send the AFP service accept message to the MEI
bool LME_ServiceAccept(struct LMEConnection* module, char* serviceName)
{
int len;
int res;
int servicenamelen = (int)strnlen_s(serviceName, 65535);
unsigned char *buf;
unsigned char *pCurrent;
if (!LME_IsInitialized(module)) return FALSE;
if ((buf = (unsigned char*)malloc(sizeof(APF_SERVICE_ACCEPT_MESSAGE) + servicenamelen)) == NULL) ILIBCRITICALEXIT(254);
pCurrent = buf;
*pCurrent = APF_SERVICE_ACCEPT;
++pCurrent;
*((unsigned int *)pCurrent) = htonl(servicenamelen);
pCurrent += 4;
memcpy_s(pCurrent, servicenamelen, serviceName, servicenamelen);
pCurrent += servicenamelen;
len = (int)(pCurrent - buf);
res = LME_sendMessage(module, buf, len);
free(buf);
return (res == len);
}
bool LME_ProtocolVersion(struct LMEConnection* module, unsigned int majorversion, unsigned int minorversion, unsigned int triggerreason)
{
APF_PROTOCOL_VERSION_MESSAGE protVersion;
memset(&protVersion, 0, sizeof(protVersion));
protVersion.MessageType = APF_PROTOCOLVERSION;
protVersion.MajorVersion = htonl(majorversion);
protVersion.MinorVersion = htonl(minorversion);
protVersion.TriggerReason = htonl(triggerreason);
return (LME_sendMessage(module, (unsigned char *)&protVersion, sizeof(protVersion)) == sizeof(protVersion));
}
bool LME_TcpForwardReplySuccess(struct LMEConnection* module, unsigned int port)
{
APF_TCP_FORWARD_REPLY_MESSAGE message;
memset(&message, 0, sizeof(message));
message.MessageType = APF_REQUEST_SUCCESS;
message.PortBound = htonl(port);
return (LME_sendMessage(module, (unsigned char *)&message, sizeof(message)) == sizeof(message));
}
bool LME_SendShortMessage(struct LMEConnection* module, unsigned char buf)
{
return (LME_sendMessage(module, &buf, sizeof(buf)) == sizeof(buf));
}
bool LME_ChannelOpenForwardedRequest(struct LMEConnection* module, unsigned int senderChannel, char* connectedIP, unsigned int connectedPort, char* originatorIP, unsigned int originatorPort)
{
int res;
int connectedIPlen = (int)strnlen_s(connectedIP, 65535);
int originatorIPlen = (int)strnlen_s(originatorIP, 65535);
unsigned char *buf;
unsigned char *pCurrent;
if (!LME_IsInitialized(module)) return FALSE;
if ((buf = (unsigned char*)malloc(5 + APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_FORWARDED) + 16 + connectedIPlen + 8 + originatorIPlen + 4)) == NULL) ILIBCRITICALEXIT(254);
pCurrent = buf;
if (strnlen_s(originatorIP, 65535) > 63) { free(buf); return FALSE; }
*pCurrent = APF_CHANNEL_OPEN;
++pCurrent;
*((unsigned int *)pCurrent) = htonl(APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_FORWARDED));
pCurrent += sizeof(unsigned int);
memcpy_s(pCurrent, APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_FORWARDED), APF_OPEN_CHANNEL_REQUEST_FORWARDED, APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_FORWARDED));
pCurrent += APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_FORWARDED);
*((unsigned int *)pCurrent) = htonl(senderChannel);
pCurrent += sizeof(unsigned int);
*((unsigned int *)pCurrent) = htonl(LME_RX_WINDOW_SIZE);
pCurrent += sizeof(unsigned int);
*((unsigned int *)pCurrent) = 0xFFFFFFFF;
pCurrent += sizeof(unsigned int);
*((unsigned int *)pCurrent) = htonl(connectedIPlen);
pCurrent += sizeof(unsigned int);
memcpy_s(pCurrent, connectedIPlen, connectedIP, connectedIPlen);
pCurrent += connectedIPlen;
*((unsigned int *)pCurrent) = htonl(connectedPort);
pCurrent += sizeof(unsigned int);
*((unsigned int *)pCurrent) = htonl((unsigned int)originatorIPlen);
pCurrent += sizeof(unsigned int);
memcpy_s(pCurrent, originatorIPlen, originatorIP, originatorIPlen);
pCurrent += originatorIPlen;
*((unsigned int *)pCurrent) = htonl(originatorPort);
pCurrent += sizeof(unsigned int);
res = LME_sendMessage(module, buf, (int)(pCurrent - buf));
free(buf);
return (res == pCurrent - buf);
}
bool LME_ChannelOpenReplySuccess(struct LMEConnection* module, unsigned int recipientChannel, unsigned int senderChannel)
{
APF_CHANNEL_OPEN_CONFIRMATION_MESSAGE message;
message.MessageType = APF_CHANNEL_OPEN_CONFIRMATION;
message.RecipientChannel = htonl(recipientChannel);
message.SenderChannel = htonl(senderChannel);
message.InitialWindowSize = htonl(LME_RX_WINDOW_SIZE);
message.Reserved = 0xFFFFFFFF;
return (LME_sendMessage(module, (unsigned char*)&message, sizeof(message)) == sizeof(message));
}
bool LME_ChannelOpenReplyFailure(struct LMEConnection* module, unsigned int recipientChannel, unsigned int reason)
{
APF_CHANNEL_OPEN_FAILURE_MESSAGE message;
message.MessageType = APF_CHANNEL_OPEN_FAILURE;
message.RecipientChannel = htonl(recipientChannel);
message.ReasonCode = htonl(reason);
message.Reserved = 0x00000000;
message.Reserved2 = 0x00000000;
return (LME_sendMessage(module, (unsigned char*)&message, sizeof(message)) == sizeof(message));
}
bool LME_ChannelClose(struct LMEConnection* module, unsigned int recipientChannel, unsigned int senderChannel )
{
APF_CHANNEL_CLOSE_MESSAGE message;
UNREFERENCED_PARAMETER( senderChannel );
message.MessageType = APF_CHANNEL_CLOSE;
message.RecipientChannel = htonl(recipientChannel);
return (LME_sendMessage(module, (unsigned char*)&message, sizeof(message)) == sizeof(message));
}
int LME_ChannelData(struct LMEConnection* module, unsigned int recipientChannel, unsigned int len, unsigned char *buffer)
{
APF_CHANNEL_DATA_MESSAGE *message;
if (len > (LME_GetMeiBufferSize(module) - sizeof(APF_CHANNEL_DATA_MESSAGE)) || module->txBuffer == NULL) return -1;
message = (APF_CHANNEL_DATA_MESSAGE*)module->txBuffer;
message->MessageType = APF_CHANNEL_DATA;
message->RecipientChannel = htonl(recipientChannel);
message->DataLength = htonl(len);
memcpy_s(module->txBuffer + sizeof(APF_CHANNEL_DATA_MESSAGE), len, buffer, len);
return LME_sendMessage(module, (unsigned char *)message, sizeof(APF_CHANNEL_DATA_MESSAGE) + len) - sizeof(APF_CHANNEL_DATA_MESSAGE);
}
bool LME_ChannelWindowAdjust(struct LMEConnection* module, unsigned int recipientChannel, unsigned int len)
{
APF_WINDOW_ADJUST_MESSAGE message;
message.MessageType = APF_CHANNEL_WINDOW_ADJUST;
message.RecipientChannel = htonl(recipientChannel);
message.BytesToAdd = htonl(len);
return (LME_sendMessage(module, (unsigned char *)&message, sizeof(message)) == sizeof(message));
}
int LME_sendMessage(struct LMEConnection* module, unsigned char *buffer, int len)
{
int result;
if (!LME_IsInitialized(module)) { return -1; }
result = heci_SendMessage(&(module->mei), buffer, len, MEI_IO_TIMEOUT);
if (result < 0) LME_Deinit(module);
return result;
}
bool LME_checkMinMsgSize(unsigned char *buf, unsigned int bytesRead)
{
switch (buf[0]) {
case APF_DISCONNECT:
if (bytesRead < sizeof(APF_DISCONNECT_MESSAGE)) { return FALSE; }
break;
case APF_SERVICE_REQUEST:
if (bytesRead < sizeof(APF_SERVICE_REQUEST)) { return FALSE; }
if (bytesRead < (sizeof(APF_SERVICE_REQUEST) + ntohl(((APF_SERVICE_REQUEST_MESSAGE *)buf)->ServiceNameLength))) { return FALSE; }
break;
case APF_USERAUTH_REQUEST:
if (bytesRead < (3 * sizeof(unsigned int))) { return FALSE; }
break;
case APF_GLOBAL_REQUEST:
if (bytesRead < (sizeof(APF_GENERIC_HEADER) + sizeof(UINT8))) { return FALSE; }
if (bytesRead < (sizeof(APF_GENERIC_HEADER) + sizeof(UINT8) + ntohl(((APF_GENERIC_HEADER *)buf)->StringLength))) { return FALSE; }
break;
case APF_CHANNEL_OPEN:
if (bytesRead < sizeof(APF_GENERIC_HEADER)) { return FALSE; }
if (bytesRead < (sizeof(APF_GENERIC_HEADER) + ntohl(((APF_GENERIC_HEADER *)buf)->StringLength))) { return FALSE; }
break;
case APF_CHANNEL_OPEN_CONFIRMATION:
if (bytesRead < sizeof(APF_CHANNEL_OPEN_CONFIRMATION_MESSAGE)) { return FALSE; }
break;
case APF_CHANNEL_OPEN_FAILURE:
if (bytesRead < sizeof(APF_CHANNEL_OPEN_FAILURE_MESSAGE)) { return FALSE; }
break;
case APF_CHANNEL_CLOSE:
if (bytesRead < sizeof(APF_CHANNEL_CLOSE_MESSAGE)) { return FALSE; }
break;
case APF_CHANNEL_DATA:
if (bytesRead < sizeof(APF_CHANNEL_DATA_MESSAGE)) { return FALSE; }
if (bytesRead < (sizeof(APF_CHANNEL_DATA_MESSAGE) + ntohl(((APF_CHANNEL_DATA_MESSAGE *)buf)->DataLength))) { return FALSE; }
break;
case APF_CHANNEL_WINDOW_ADJUST:
if (bytesRead < sizeof(APF_WINDOW_ADJUST_MESSAGE)) { return FALSE; }
break;
case APF_PROTOCOLVERSION:
if (bytesRead < sizeof(APF_PROTOCOL_VERSION_MESSAGE)) { return FALSE; }
break;
default:
return FALSE;
}
return TRUE;
}
void LME_doRX(struct LMEConnection* module, unsigned char *rxBuffer, unsigned int bytesRead)
{
if (bytesRead == 0) return;
if (!LME_checkMinMsgSize(rxBuffer, bytesRead)) { LME_Deinit(module); return; }
module->cb(module, module->cbParam, rxBuffer, bytesRead);
}
/*
void LME_apfChannelOpen(struct LMEConnection* module, unsigned char *rxBuffer, unsigned int bytesRead, int *status)
{
APF_GENERIC_HEADER *pHeader = (APF_GENERIC_HEADER *)rxBuffer;
if (_strnicmp((char *)pHeader->String, APF_OPEN_CHANNEL_REQUEST_DIRECT, APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_DIRECT)) == 0)
{
unsigned int senderChannel = 0;
LME_apfChannelOpenDirect(module, rxBuffer, bytesRead, &senderChannel, status);
if (LME_IsInitialized(module) && (*status == 1)) {
if (plugin.retry(rxBuffer, bytesRead) != LMS_DROPPED) { LME_apfChannelOpenDirect(module, rxBuffer, bytesRead, NULL, status); }
}
if (LME_IsInitialized(module) && (*status == 1)) {
LME_ChannelOpenReplyFailure(module, senderChannel, OPEN_FAILURE_REASON_CONNECT_FAILED);
}
}
}
void LME_apfChannelOpenDirect(struct LMEConnection* module, unsigned char *rxBuffer, unsigned int bytesRead, unsigned int *senderChannel, int *status)
{
unsigned char *pCurrent;
APF_GENERIC_HEADER *pHeader = (APF_GENERIC_HEADER *)rxBuffer;
if (bytesRead < sizeof(APF_GENERIC_HEADER) +
ntohl(pHeader->StringLength) +
7 + (5 * sizeof(unsigned int))) {
ILIBMESSAGE("apfChannelOpenDirect: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
pCurrent = rxBuffer + sizeof(APF_GENERIC_HEADER) +
APF_STR_SIZE_OF(APF_OPEN_CHANNEL_REQUEST_DIRECT);
LMEChannelOpenRequestMessage channelOpenRequest;
channelOpenRequest.ChannelType = APF_CHANNEL_DIRECT;
channelOpenRequest.SenderChannel = ntohl(*((unsigned int *)pCurrent));
if (senderChannel) {
*senderChannel = channelOpenRequest.SenderChannel;
}
pCurrent += sizeof(unsigned int);
channelOpenRequest.InitialWindow = ntohl(*((unsigned int *)pCurrent));
pCurrent += 2 * sizeof(unsigned int);
unsigned int len = ntohl(*((unsigned int *)pCurrent));
pCurrent += sizeof(unsigned int);
channelOpenRequest.Address.append((char *)pCurrent, len);
pCurrent += len;
channelOpenRequest.Port = ntohl(*((unsigned int *)pCurrent));
pCurrent += sizeof(unsigned int);
module->_cb(module, module->_cbParam, &channelOpenRequest, sizeof(channelOpenRequest), status);
}
*/
/*
void LME_apfUserAuthRequest(struct LMEConnection* module, unsigned char *rxBuffer, unsigned int bytesRead, int *status)
{
unsigned char *pCurrent = rxBuffer;
++pCurrent;
LMEUserAuthRequestMessage userAuthRequest;
unsigned int len = ntohl(*((unsigned int *)pCurrent));
pCurrent += sizeof(unsigned int);
if ((bytesRead - (pCurrent - rxBuffer)) < len) {
ILIBMESSAGE("_apfUserAuthRequest1: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
userAuthRequest.Username.append((char *)pCurrent, len);
pCurrent += len;
if ((unsigned int)(bytesRead - (pCurrent - rxBuffer)) < sizeof(unsigned int)) {
ILIBMESSAGE("_apfUserAuthRequest2: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
len = ntohl(*((unsigned int *)pCurrent));
pCurrent += sizeof(unsigned int);
if ((bytesRead - (pCurrent - rxBuffer)) < len) {
ILIBMESSAGE("_apfUserAuthRequest3: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
userAuthRequest.ServiceName.append((char *)pCurrent, len);
pCurrent += len;
if ((unsigned int)(bytesRead - (pCurrent - rxBuffer)) < sizeof(unsigned int)) {
ILIBMESSAGE("_apfUserAuthRequest4: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
len = ntohl(*((unsigned int *)pCurrent));
pCurrent += sizeof(unsigned int);
if ((bytesRead - (pCurrent - rxBuffer)) < len) {
ILIBMESSAGE("_apfUserAuthRequest5: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
userAuthRequest.MethodName.append((char *)pCurrent, len);
pCurrent += len;
if (_strnicmp(userAuthRequest.MethodName.c_str(), APF_AUTH_PASSWORD,
userAuthRequest.MethodName.size()) == 0) {
if ((unsigned int)(bytesRead - (pCurrent - rxBuffer)) < sizeof(unsigned int) + 1) {
ILIBMESSAGE("_apfUserAuthRequest6: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
++pCurrent;
len = ntohl(*((unsigned int *)pCurrent));
pCurrent += sizeof(unsigned int);
if ((bytesRead - (pCurrent - rxBuffer)) < len) {
ILIBMESSAGE("_apfUserAuthRequest7: Error receiving data from MEI\n");
LME_Deinit(module);
return;
}
AuthPasswordData authData;
authData.Password.append((char *)pCurrent, len);
pCurrent += len;
userAuthRequest.MethodData = &authData;
}
module->_cb(module, module->_cbParam, &userAuthRequest, sizeof(userAuthRequest), status);
}
*/
unsigned int LME_GetMeiBufferSize(struct LMEConnection* module)
{
return heci_GetBufferSize(&(module->mei));
}
#endif

View File

@@ -0,0 +1,195 @@
/*
Copyright 2006 - 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _MINCORE
#ifndef __LME_CONNECTION_H__
#define __LME_CONNECTION_H__
#ifdef WIN32
#include "HECIWin.h"
#else
#include "HECILinux.h"
#endif
#include "LMS_if.h"
enum INIT_STATES {
INIT_STATE_DISCONNECTED = 0,
INIT_STATE_CONNECTING,
INIT_STATE_CONNECTED
};
struct LMEConnection;
typedef void (*MEICallback)(struct LMEConnection* module, void *param, void *buffer, unsigned int len);
struct LMEConnection
{
unsigned char reqID;
unsigned char *txBuffer;
MEICallback cb;
void* cbParam;
enum INIT_STATES initState;
unsigned char protocolVer;
struct MEImodule mei;
unsigned char exit;
};
struct LMEDisconnectMessage
{
APF_MESSAGE_TYPE MessageType;
APF_DISCONNECT_REASON_CODE ReasonCode;
};
struct LMEServiceRequestMessage
{
APF_MESSAGE_TYPE MessageType;
char* ServiceName;
};
typedef enum APF_REQUEST_ENUM {
TCP_FORWARD_REQUEST,
TCP_FORWARD_CANCEL_REQUEST,
UDP_SEND_TO
} APF_REQUEST_TYPE;
struct LMEGlobalRequestMessage
{
APF_MESSAGE_TYPE MessageType;
APF_REQUEST_TYPE RequestType;
};
struct LMEProtocolVersionMessage
{
APF_MESSAGE_TYPE MessageType;
unsigned int MajorVersion;
unsigned int MinorVersion;
APF_TRIGGER_REASON TriggerReason;
};
struct LMEUserAuthRequestMessage
{
APF_MESSAGE_TYPE MessageType;
char* Username;
char* ServiceName;
char* MethodName;
char* MethodData;
};
struct LMETcpForwardRequestMessage
{
APF_MESSAGE_TYPE MessageType;
APF_REQUEST_TYPE RequestType;
char* Address;
unsigned int Port;
};
struct LMETcpForwardCancelRequestMessage {
APF_MESSAGE_TYPE MessageType;
APF_REQUEST_TYPE RequestType;
char* Address;
unsigned int Port;
};
struct LMEUdpSendToMessage
{
APF_MESSAGE_TYPE MessageType;
APF_REQUEST_TYPE RequestType;
char* Address;
unsigned int Port;
unsigned int DataLength;
unsigned char *Data;
};
typedef enum APF_CHANNEL_ENUM {
APF_CHANNEL_FORWARDED,
APF_CHANNEL_DIRECT
} APF_CHANNEL_TYPE;
struct LMEChannelOpenRequestMessage
{
APF_MESSAGE_TYPE MessageType;
APF_CHANNEL_TYPE ChannelType;
unsigned int SenderChannel;
unsigned int InitialWindow;
char* Address;
unsigned int Port;
};
struct LMEChannelOpenReplySuccessMessage
{
APF_MESSAGE_TYPE MessageType;
unsigned int RecipientChannel;
unsigned int SenderChannel;
unsigned int InitialWindow;
};
struct LMEChannelOpenReplyFailureMessage
{
APF_MESSAGE_TYPE MessageType;
unsigned int RecipientChannel;
OPEN_FAILURE_REASON ReasonCode;
};
struct LMEChannelCloseMessage
{
APF_MESSAGE_TYPE MessageType;
unsigned int RecipientChannel;
};
struct LMEChannelDataMessage
{
APF_MESSAGE_TYPE MessageType;
unsigned int RecipientChannel;
unsigned int DataLength;
unsigned char *Data;
};
struct LMEChannelWindowAdjustMessage
{
APF_MESSAGE_TYPE MessageType;
unsigned int RecipientChannel;
unsigned int BytesToAdd;
};
bool LME_Init(struct LMEConnection* module, MEICallback cb, void *param);
void LME_Deinit(struct LMEConnection* module);
bool LME_IsInitialized(struct LMEConnection* module);
bool LME_Disconnect(struct LMEConnection* module, APF_DISCONNECT_REASON_CODE reasonCode);
bool LME_ServiceAccept(struct LMEConnection* module, char* serviceName);
bool LME_ProtocolVersion(struct LMEConnection* module, unsigned int majorversion, unsigned int minorversion, unsigned int triggerreason);
bool LME_TcpForwardReplySuccess(struct LMEConnection* module, unsigned int port);
bool LME_SendShortMessage(struct LMEConnection* module, unsigned char buf);
bool LME_ChannelOpenForwardedRequest(struct LMEConnection* module, unsigned int sender, char* connectedIP, unsigned int connectedPort, char* originatorIP, unsigned int originatorPort);
bool LME_ChannelOpenReplySuccess(struct LMEConnection* module, unsigned int recipient, unsigned int sender);
bool LME_ChannelOpenReplyFailure(struct LMEConnection* module, unsigned int recipient, unsigned int reason);
bool LME_ChannelClose(struct LMEConnection* module, unsigned int recipient, unsigned int sender);
int LME_ChannelData(struct LMEConnection* module, unsigned int recipient, unsigned int len, unsigned char *buffer);
bool LME_ChannelWindowAdjust(struct LMEConnection* module, unsigned int recipient, unsigned int len);
void LME_Deinit(struct LMEConnection* module);
void LME_Exit(struct LMEConnection* module);
unsigned int LME_GetMeiBufferSize(struct LMEConnection* module);
#define LME_UserAuthSuccess(module) LME_SendShortMessage(module, APF_USERAUTH_SUCCESS)
#define LME_TcpForwardReplyFailure(module) LME_SendShortMessage(module, APF_REQUEST_FAILURE)
#define LME_TcpForwardCancelReplySuccess(module) LME_SendShortMessage(module, APF_REQUEST_SUCCESS)
#define LME_TcpForwardCancelReplyFailure(module) LME_SendShortMessage(module, APF_REQUEST_FAILURE)
#endif
#endif

197
microlms/heci/LMS_if.h Normal file
View File

@@ -0,0 +1,197 @@
/*******************************************************************************
* Copyright (C) 2004-2011 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corporation. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
#ifndef _LMS_IF_H_
#define _LMS_IF_H_
#include "LMS_if_constants.h"
#pragma pack(1)
typedef struct {
unsigned char MessageType;
} APF_MESSAGE_HEADER;
/**
* APF_GENERIC_HEADER - generic request header (note that its not complete header per protocol (missing WantReply)
*
* @MessageType:
* @RequestStringLength: length of the string identifies the request
* @RequestString: the string that identifies the request
**/
typedef struct {
unsigned char MessageType;
unsigned int StringLength;
unsigned char String[0];
} APF_GENERIC_HEADER;
/**
* TCP forward reply message
* @MessageType - Protocol's Major version
* @PortBound - the TCP port was bound on the server
**/
typedef struct {
unsigned char MessageType;
unsigned int PortBound;
} APF_TCP_FORWARD_REPLY_MESSAGE;
/**
* response to ChannelOpen when channel open succeed
* @MessageType - APF_CHANNEL_OPEN_CONFIRMATION
* @RecipientChannel - channel number given in the open request
* @SenderChannel - channel number assigned by the sender
* @InitialWindowSize - Number of bytes in the window
* @Reserved - Reserved
**/
typedef struct {
unsigned char MessageType;
unsigned int RecipientChannel;
unsigned int SenderChannel;
unsigned int InitialWindowSize;
unsigned int Reserved;
} APF_CHANNEL_OPEN_CONFIRMATION_MESSAGE;
/**
* response to ChannelOpen when a channel open failed
* @MessageType - APF_CHANNEL_OPEN_FAILURE
* @RecipientChannel - channel number given in the open request
* @ReasonCode - code for the reason channel could not be open
* @Reserved - Reserved
**/
typedef struct {
unsigned char MessageType;
unsigned int RecipientChannel;
unsigned int ReasonCode;
unsigned int Reserved;
unsigned int Reserved2;
} APF_CHANNEL_OPEN_FAILURE_MESSAGE;
/**
* close channel message
* @MessageType - APF_CHANNEL_CLOSE
* @RecipientChannel - channel number given in the open request
**/
typedef struct {
unsigned char MessageType;
unsigned int RecipientChannel;
} APF_CHANNEL_CLOSE_MESSAGE;
/**
* used to send/receive data.
* @MessageType - APF_CHANNEL_DATA
* @RecipientChannel - channel number given in the open request
* @Length - Length of the data in the message
* @Data - The data in the message
**/
typedef struct {
unsigned char MessageType;
unsigned int RecipientChannel;
unsigned int DataLength;
// unsigned char Data[0];
} APF_CHANNEL_DATA_MESSAGE;
/**
* used to adjust receive window size.
* @MessageType - APF_WINDOW_ADJUST
* @RecipientChannel - channel number given in the open request
* @BytesToAdd - number of bytes to add to current window size value
**/
typedef struct {
unsigned char MessageType;
unsigned int RecipientChannel;
unsigned int BytesToAdd;
} APF_WINDOW_ADJUST_MESSAGE;
/**
* This message causes immediate termination of the connection with AMT.
* @ReasonCode - A Reason code for the disconnection event
* @Reserved - Reserved must be set to 0
**/
typedef struct {
unsigned char MessageType;
unsigned int ReasonCode;
unsigned short Reserved;
} APF_DISCONNECT_MESSAGE;
/**
* Used to request a service identified by name
* @ServiceNameLength - The length of the service name string.
* @ServiceName - The name of the service being requested.
**/
typedef struct {
unsigned char MessageType;
unsigned int ServiceNameLength;
unsigned char ServiceName[0];
} APF_SERVICE_REQUEST_MESSAGE;
/**
* Used to send a service accept identified by name
* @ServiceNameLength - The length of the service name string.
* @ServiceName - The name of the service being requested.
**/
typedef struct {
unsigned char MessageType;
unsigned int ServiceNameLength;
unsigned char ServiceName[0];
} APF_SERVICE_ACCEPT_MESSAGE;
/**
* holds the protocl major and minor version implemented by AMT.
* @MajorVersion - Protocol's Major version
* @MinorVersion - Protocol's Minor version
* @Trigger - The open session reason
* @UUID - System Id
**/
typedef struct {
unsigned char MessageType;
unsigned int MajorVersion;
unsigned int MinorVersion;
unsigned int TriggerReason;
unsigned char UUID[16];
unsigned char Reserved[64];
} APF_PROTOCOL_VERSION_MESSAGE;
/**
* holds the user authentication request success reponse.
**/
typedef struct {
unsigned char MessageType;
} APF_USERAUTH_SUCCESS_MESSAGE;
#pragma pack()
#endif
#endif

View File

@@ -0,0 +1,116 @@
/*******************************************************************************
* Copyright (C) 2004-2011 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corporation. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
#ifndef _LMS_IF_CONSTANTS_H_
#define _LMS_IF_CONSTANTS_H_
#define LMS_PROTOCOL_VERSION 4
//
// messages opcodes
//
typedef enum {
APF_DISCONNECT = 1,
APF_SERVICE_REQUEST = 5,
APF_SERVICE_ACCEPT = 6,
APF_USERAUTH_REQUEST = 50,
APF_USERAUTH_FAILURE = 51,
APF_USERAUTH_SUCCESS = 52,
APF_GLOBAL_REQUEST = 80,
APF_REQUEST_SUCCESS = 81,
APF_REQUEST_FAILURE = 82,
APF_CHANNEL_OPEN = 90,
APF_CHANNEL_OPEN_CONFIRMATION = 91,
APF_CHANNEL_OPEN_FAILURE = 92,
APF_CHANNEL_WINDOW_ADJUST = 93,
APF_CHANNEL_DATA = 94,
APF_CHANNEL_CLOSE = 97,
APF_PROTOCOLVERSION = 192
} APF_MESSAGE_TYPE;
typedef enum {
APF_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1,
APF_DISCONNECT_PROTOCOL_ERROR = 2,
APF_DISCONNECT_KEY_EXCHANGE_FAILED = 3,
APF_DISCONNECT_RESERVED = 4,
APF_DISCONNECT_MAC_ERROR = 5,
APF_DISCONNECT_COMPRESSION_ERROR = 6,
APF_DISCONNECT_SERVICE_NOT_AVAILABLE = 7,
APF_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8,
APF_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9,
APF_DISCONNECT_CONNECTION_LOST = 10,
APF_DISCONNECT_BY_APPLICATION = 11,
APF_DISCONNECT_TOO_MANY_CONNECTIONS = 12,
APF_DISCONNECT_AUTH_CANCELLED_BY_USER = 13,
APF_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14,
APF_DISCONNECT_ILLEGAL_USER_NAME = 15
} APF_DISCONNECT_REASON_CODE;
//
//strings used in global messages
//
#define APF_GLOBAL_REQUEST_STR_TCP_FORWARD_REQUEST "tcpip-forward"
#define APF_GLOBAL_REQUEST_STR_TCP_FORWARD_CANCEL_REQUEST "cancel-tcpip-forward"
#define APF_GLOBAL_REQUEST_STR_UDP_SEND_TO "udp-send-to@amt.intel.com"
#define APF_OPEN_CHANNEL_REQUEST_FORWARDED "forwarded-tcpip"
#define APF_OPEN_CHANNEL_REQUEST_DIRECT "direct-tcpip"
// APF service names
#define APF_SERVICE_PFWD "pfwd@amt.intel.com"
#define APF_SERVICE_AUTH "auth@amt.intel.com"
// APF Authentication method
#define APF_AUTH_NONE "none"
#define APF_AUTH_PASSWORD "password"
//calculate string length without the NULL terminator
#define APF_STR_SIZE_OF(s) (sizeof(s)-1)
// Trigger reason code
typedef enum {
USER_INITIATED_REQUEST = 1,
ALERT_REQUEST = 2,
HIT_PROVISIONING_REQUEST = 3,
PERIODIC_REQUEST = 4,
LME_REQUEST = 254
} APF_TRIGGER_REASON;
typedef enum {
OPEN_FAILURE_REASON_ADMINISTRATIVELY_PROHIBITED = 1,
OPEN_FAILURE_REASON_CONNECT_FAILED = 2,
OPEN_FAILURE_REASON_UNKNOWN_CHANNEL_TYPE = 3,
OPEN_FAILURE_REASON_RESOURCE_SHORTAGE = 4
} OPEN_FAILURE_REASON;
#endif
#endif

1440
microlms/heci/PTHICommand.c Normal file

File diff suppressed because it is too large Load Diff

825
microlms/heci/PTHICommand.h Normal file
View File

@@ -0,0 +1,825 @@
/*******************************************************************************
* Copyright (C) 2004-2008 Intel Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corp. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
//----------------------------------------------------------------------------
//
// File: PTHICommand.h
//
// Contents: header file of PTHICommand class
//
//----------------------------------------------------------------------------
#ifndef __PTHI_COMMAND_H__
#define __PTHI_COMMAND_H__
#include "StatusCodeDefinitions.h"
#ifdef WIN32
#include <windows.h>
#include "HECIwin.h"
#endif
#ifdef _POSIX
#include "HECILinux.h"
#endif
#define CERT_HASH_MAX_LENGTH 64
#define CERT_HASH_MAX_NUMBER 23
#define NET_TLS_CERT_PKI_MAX_SERIAL_NUMS 3
#define NET_TLS_CERT_PKI_MAX_SERIAL_NUM_LENGTH 16
#define MPS_HOSTNAME_LENGTH 256
#define CFG_MAX_ACL_USER_LENGTH 33
#define CFG_MAX_ACL_PWD_LENGTH 33
#pragma pack(1)
typedef struct _LOCAL_SYSTEM_ACCOUNT
{
// contain null terminated string
char username[CFG_MAX_ACL_USER_LENGTH];
// contain null terminated string
char password[CFG_MAX_ACL_PWD_LENGTH];
}LOCAL_SYSTEM_ACCOUNT;
#pragma pack()
/*
* Constants
*/
/*
static #define IDER_LOG_ENTRIES = 16;
const UINT8 MAJOR_VERSION = 1;
const UINT8 MINOR_VERSION = 1;
const UINT8 AMT_MAJOR_VERSION = 1;
const UINT8 AMT_MINOR_VERSION = 1;
*/
#define IDER_LOG_ENTRIES 16
#define MAJOR_VERSION 1
#define MINOR_VERSION 1
#define AMT_MAJOR_VERSION 1
#define AMT_MINOR_VERSION 1
typedef enum _CFG_PROVISIONING_MODE
{
CFG_PROVISIONING_MODE_NONE = 0,
CFG_PROVISIONING_MODE_ENTERPRISE,
CFG_PROVISIONING_MODE_SMALL_BUSINESS,
CFG_PROVISIONING_MODE_REMOTE_ASSISTANCE
} CFG_PROVISIONING_MODE;
typedef enum _AMT_PROVISIONING_STATE
{
PROVISIONING_STATE_PRE = 0,
PROVISIONING_STATE_IN = 1,
PROVISIONING_STATE_POST = 2
} AMT_PROVISIONING_STATE;
typedef enum _AMT_EHBC_STATE
{
EHBC_STATE_DISABLED = 0,
EHBC_STATE_ENABLED = 1
} AMT_EHBC_STATE;
typedef enum _AMT_FEATURE_STATE_REQUEST
{
REDIRECTION_SESSION = 0,
SYSTEM_DEFENSE = 1,
WEB_UI = 2
} AMT_FEATURE_STATE_REQUEST;
typedef enum _AMT_LAST_HOST_RESET_REASON
{
RemoteControl = 0,
Other = 1
} AMT_LAST_HOST_RESET_REASON;
typedef enum _AMT_INTERFACE_INDEX
{
WIRED = 0,
WIRELESS = 1
} AMT_INTERFACE_INDEX;
typedef enum _AMT_DHCP_IP_ADDRESS
{
ACTIVE = 1,
PASSIVE = 2
} AMT_DHCP_IP_MODE;
//typedef UINT32 CFG_IPv4_ADDRESS
#define CFG_IPv4_ADDRESS UINT32
/*
static #define BIOS_VERSION_LEN = 65;
static #define VERSIONS_NUMBER = 50;
static #define UNICODE_STRING_LEN = 20;
*/
#define BIOS_VERSION_LEN 65
#define VERSIONS_NUMBER 50
#define UNICODE_STRING_LEN 20
typedef enum _AMT_PROVISIONING_TLS_MODE
{
NOT_READY = 0,
PSK = 1,
PKI = 2
} AMT_PROVISIONING_TLS_MODE;
typedef enum _AMT_RNG_STATUS
{
RNG_STATUS_EXIST = 0,
RNG_STATUS_IN_PROGRESS = 1,
RNG_STATUS_NOT_EXIST = 2
} AMT_RNG_STATUS;
#pragma pack(1)
typedef struct _AMT_UNICODE_STRING
{
UINT16 Length;
UINT8 String[UNICODE_STRING_LEN];
} AMT_UNICODE_STRING;
typedef struct _AMT_VERSION_TYPE
{
AMT_UNICODE_STRING Description;
AMT_UNICODE_STRING Version;
} AMT_VERSION_TYPE;
typedef struct _PTHI_VERSION
{
UINT8 MajorNumber;
UINT8 MinorNumber;
} PTHI_VERSION;
typedef struct _CODE_VERSIONS
{
UINT8 BiosVersion[BIOS_VERSION_LEN];
UINT32 VersionsCount;
AMT_VERSION_TYPE Versions[VERSIONS_NUMBER];
} CODE_VERSIONS;
typedef struct _COMMAND_FMT
{
union
{
UINT32 val;
struct
{
UINT32 Operation : 23;
UINT32 IsResponse : 1;
UINT32 Class : 8;
} fields;
} cmd;
} COMMAND_FMT;
typedef struct _AMT_ANSI_STRING
{
UINT16 Length;
CHAR *Buffer;
} AMT_ANSI_STRING;
typedef struct _PTHI_MESSAGE_HEADER
{
PTHI_VERSION Version;
UINT16 Reserved;
COMMAND_FMT Command;
UINT32 Length;
} PTHI_MESSAGE_HEADER;
typedef struct _PTHI_RESPONSE_MESSAGE_HEADER
{
PTHI_MESSAGE_HEADER Header;
AMT_STATUS Status;
} PTHI_RESPONSE_MESSAGE_HEADER;
typedef struct _CFG_GET_CODE_VERSIONS_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
CODE_VERSIONS CodeVersions;
} CFG_GET_CODE_VERSIONS_RESPONSE;
typedef struct _CFG_GET_PROVISIONING_MODE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
CFG_PROVISIONING_MODE ProvisioningMode;
AMT_BOOLEAN LegacyMode;
} CFG_GET_PROVISIONING_MODE_RESPONSE;
typedef struct _CFG_GET_PROVISIONING_STATE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_PROVISIONING_STATE ProvisioningState;
} CFG_GET_PROVISIONING_STATE_RESPONSE;
typedef struct _CFG_GET_MAC_ADDRESSES_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
UINT8 DedicatedMac[6];
UINT8 HostMac[6];
} CFG_GET_MAC_ADDRESSES_RESPONSE;
typedef struct _CFG_GET_FEATURES_STATE_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT32 RequestID;
} CFG_GET_FEATURES_STATE_REQUEST;
typedef struct _GET_FEATURES_REDIRECTION_SESSION_STATUS
{
AMT_BOOLEAN IderOpen;
AMT_BOOLEAN SolOpen;
AMT_BOOLEAN Reserved;
} GET_FEATURES_REDIRECTION_SESSION_STATUS;
typedef struct _GET_FEATURES_SYSTEM_DEFENSE_STATE_RESPONSE
{
AMT_BOOLEAN SystemDefenseActivated;
} GET_FEATURES_SYSTEM_DEFENSE_STATUS_RESPONSE;
typedef struct _GET_FEATURES_WEB_UI_STATE_RESPONSE
{
AMT_BOOLEAN WebUiEnabled;
} GET_FEATURES_WEB_UI_STATUS_RESPONSE;
typedef union _FEATURES_STATUS_DATA
{
GET_FEATURES_REDIRECTION_SESSION_STATUS rs;
GET_FEATURES_SYSTEM_DEFENSE_STATUS_RESPONSE sd;
GET_FEATURES_WEB_UI_STATUS_RESPONSE webUI;
} FEATURES_STATUS_DATA;
typedef struct _CFG_GET_FEATURES_STATE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
UINT32 RequestID;
FEATURES_STATUS_DATA Data;
} CFG_GET_FEATURES_STATE_RESPONSE;
typedef struct _CFG_GET_CURRENT_POWER_POLICY_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GET_CURRENT_POWER_POLICY_REQUEST;
typedef struct _CFG_GET_CURRENT_POWER_POLICY_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_ANSI_STRING PolicyName;
} CFG_GET_CURRENT_POWER_POLICY_RESPONSE;
typedef struct _CFG_GET_LAST_HOST_RESET_REASON_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GET_LAST_HOST_RESET_REASON_REQUEST;
typedef struct _CFG_GET_LAST_HOST_RESET_REASON_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
UINT32 Reason;
UINT32 RemoteControlTimeStamp;
} CFG_GET_LAST_HOST_RESET_REASON_RESPONSE;
typedef struct _LAN_SETTINGS
{
AMT_BOOLEAN Enabled;
CFG_IPv4_ADDRESS Ipv4Address;
AMT_BOOLEAN DhcpEnabled;
UINT8 DhcpIpMode;
UINT8 LinkStatus;
UINT8 MacAddress[6];
} LAN_SETTINGS;
typedef struct _CFG_GET_LAN_INTERFACE_SETTINGS_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT32 InterfaceIndex;
} CFG_GET_LAN_INTERFACE_SETTINGS_REQUEST;
typedef struct _CFG_GET_LAN_INTERFACE_SETTINGS_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_BOOLEAN Enabled;
CFG_IPv4_ADDRESS Ipv4Address;
AMT_BOOLEAN DhcpEnabled;
UINT8 DhcpIpMode;
UINT8 LinkStatus;
UINT8 MacAddress[6];
} CFG_GET_LAN_INTERFACE_SETTINGS_RESPONSE;
typedef struct _CFG_GET_SECURITY_PARAMETERS_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GET_SECURITY_PARAMETERS_REQUEST;
typedef struct _CFG_GET_SECURITY_PARAMETERS_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_BOOLEAN EnterpriseMode;
AMT_BOOLEAN TLSEnabled;
AMT_BOOLEAN HWCryptoEnabled;
AMT_PROVISIONING_STATE ProvisioningState;
AMT_BOOLEAN NetworkInterfaceEnabled;
AMT_BOOLEAN SOLEnabled;
AMT_BOOLEAN IDEREnabled;
AMT_BOOLEAN FWUpdateEnabled;
AMT_BOOLEAN LinkIsUp;
AMT_BOOLEAN Reserved[8];
} CFG_GET_SECURITY_PARAMETERS_RESPONSE;
typedef struct _CFG_GET_DNS_SUFFIX_LIST_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GET_DNS_SUFFIX_LIST_REQUEST;
typedef struct _CFG_GET_DNS_SUFFIX_LIST_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
UINT16 DataLength;
UINT8 Data[0];
} CFG_GET_DNS_SUFFIX_LIST_RESPONSE;
/**
* CFG_SET_ENTERPRISE_ACCESS_REQUEST
*
* Flags Bit 0 - If this bit is set then HostIPAddress is IPv6, otherwise HostIPAddress is IPv4 address.
* Bits 1..7 - Reserved, should be zero.
* HostIPAddress IPv4 / IPv6 address
* EnterpriseAccess 1 if LMS has access to enterprise network, otherwise 0.
*/
typedef struct _CFG_SET_ENTERPRISE_ACCESS_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT8 Flags;
UINT8 HostIPAddress[16];
UINT8 EnterpriseAccess;
} CFG_SET_ENTERPRISE_ACCESS_REQUEST;
typedef struct _CFG_SET_ENTERPRISE_ACCESS_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_SET_ENTERPRISE_ACCESS_RESPONSE;
typedef struct _CFG_OPEN_USER_INITIATED_CONNECTION_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_OPEN_USER_INITIATED_CONNECTION_REQUEST;
typedef struct _CFG_OPEN_USER_INITIATED_CONNECTION_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_OPEN_USER_INITIATED_CONNECTION_RESPONSE;
typedef struct _CFG_CLOSE_USER_INITIATED_CONNECTION_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_CLOSE_USER_INITIATED_CONNECTION_REQUEST;
typedef struct _CFG_CLOSE_USER_INITIATED_CONNECTION_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_CLOSE_USER_INITIATED_CONNECTION_RESPONSE;
typedef enum
{
AMT_NETWORK_CONNECTION_DIRECT = 0,
AMT_NETWORK_CONNECTION_VPN,
AMT_NETWORK_CONNECTION_OUTSIDE_ENTERPRISE
} AMT_NETWORK_CONNECTION_STATUS;
typedef enum
{
REMOTE_ACCESS_CONNECTION_STATUS_NOT_CONNECTED = 0,
REMOTE_ACCESS_CONNECTION_STATUS_CONNECTING,
REMOTE_ACCESS_CONNECTION_STATUS_CONNECTED
} REMOTE_ACCESS_CONNECTION_STATUS;
typedef enum
{
REMOTE_ACCESS_CONNECTION_TRIGGER_USER_INITIATED = 0,
REMOTE_ACCESS_CONNECTION_TRIGGER_ALERT,
REMOTE_ACCESS_CONNECTION_TRIGGER_PROVISIONING,
REMOTE_ACCESS_CONNECTION_TRIGGER_PERIODIC
} REMOTE_ACCESS_CONNECTION_TRIGGER;
typedef struct _CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_REQUEST;
typedef struct _CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_NETWORK_CONNECTION_STATUS AmtNetworkConnectionStatus;
REMOTE_ACCESS_CONNECTION_STATUS RemoteAccessConnectionStatus;
REMOTE_ACCESS_CONNECTION_TRIGGER RemoteAccessConnectionTrigger;
AMT_ANSI_STRING MpsHostname;
} CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE;
typedef struct _REMOTE_ACCESS_STATUS
{
AMT_NETWORK_CONNECTION_STATUS AmtNetworkConnectionStatus;
REMOTE_ACCESS_CONNECTION_STATUS RemoteAccessConnectionStatus;
REMOTE_ACCESS_CONNECTION_TRIGGER RemoteAccessConnectionTrigger;
AMT_ANSI_STRING MpsHostname;
} REMOTE_ACCESS_STATUS;
typedef UINT8 AMT_UUID[16];
//const AMT_UUID AMT_UUID_LINK_STATE;
typedef struct _STATE_DATA
{
UINT8 LinkStatus; // (0 - down; 1 - up)
UINT8 HardSKU;
UINT8 CryptoFuse; // (0 - disabled; 1 - enabled)
UINT8 FlashProtaction; // (0 - disabled; 1 - enabled)
UINT8 LastMEResetReason;
} STATE_DATA;
typedef struct _STATE_GET_AMT_STATE_REQUEST
{
PTHI_MESSAGE_HEADER Header;
AMT_UUID StateVariableIdentifier;
} STATE_GET_AMT_STATE_REQUEST;
typedef struct _STATE_GET_AMT_STATE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_UUID StateDataIdentifier;
UINT32 ByteCount;
STATE_DATA StateData;
} STATE_GET_AMT_STATE_RESPONSE;
typedef struct _AMT_HASH_HANDLES
{
UINT32 Length;
UINT32 Handles[CERT_HASH_MAX_NUMBER];
} AMT_HASH_HANDLES;
typedef struct _CERTHASH_ENTRY
{
AMT_BOOLEAN IsDefault;
AMT_BOOLEAN IsActive;
UINT8 CertificateHash[CERT_HASH_MAX_LENGTH];
UINT8 HashAlgorithm;
AMT_ANSI_STRING Name;
} CERTHASH_ENTRY;
typedef enum
{
CERT_HASH_ALGORITHM_MD5 = 0, // 16 bytes
CERT_HASH_ALGORITHM_SHA1, // 20 bytes
CERT_HASH_ALGORITHM_SHA256, // 32 bytes
CERT_HASH_ALGORITHM_SHA512, // 64 bytes
} CERT_HASH_ALGORITHM;
typedef struct
{
UINT16 Year;
UINT16 Month;
UINT16 DayOfWeek;
UINT16 Day;
UINT16 Hour;
UINT16 Minute;
UINT16 Second;
} TIME_DATE;
typedef struct _AMT_PROV_AUDIT_RECORD
{
UINT8 ProvisioningTLSMode;
AMT_BOOLEAN SecureDNS;
AMT_BOOLEAN HostInitiated;
CERT_HASH_ALGORITHM SelectedHashType;
UINT8 SelectedHashData[CERT_HASH_MAX_LENGTH];
UINT8 CaCertificateSerials[NET_TLS_CERT_PKI_MAX_SERIAL_NUMS*NET_TLS_CERT_PKI_MAX_SERIAL_NUM_LENGTH];
AMT_BOOLEAN AdditionalCaSerialNums;
AMT_BOOLEAN IsOemDefault;
AMT_BOOLEAN IsTimeValid;
UINT32 ProvServerIP;
TIME_DATE TlsStartTime;
AMT_ANSI_STRING ProvServerFQDN;
} AMT_PROV_AUDIT_RECORD;
typedef struct _CFG_GENERATE_RNG_SEED_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_GENERATE_RNG_SEED_RESPONSE;
typedef struct _CFG_GET_RNG_SEED_STATUS_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_RNG_STATUS RngStatus;
} CFG_GET_RNG_SEED_STATUS_RESPONSE;
typedef struct _CFG_GET_ZERO_TOUCH_ENABLED_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_BOOLEAN ZeroTouchEnabled;
} CFG_GET_ZERO_TOUCH_ENABLED_RESPONSE;
typedef struct _CFG_GET_PROVISIONING_TLS_MODE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_PROVISIONING_TLS_MODE ProvisioningTlsMode;
} CFG_GET_PROVISIONING_TLS_MODE_RESPONSE;
typedef struct _CFG_START_CONFIGURATION_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_START_CONFIGURATION_RESPONSE;
typedef struct _CFG_STOP_CONFIGURATION_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_STOP_CONFIGURATION_RESPONSE;
typedef struct _CFG_SET_PROVISIONING_SERVER_OTP_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_SET_PROVISIONING_SERVER_OTP_RESPONSE;
typedef struct _CFG_SET_DNS_SUFFIX_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
} CFG_SET_DNS_SUFFIX_RESPONSE;
typedef struct _CFG_GET_HASH_HANDLES_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_HASH_HANDLES HashHandles;
} CFG_GET_HASH_HANDLES_RESPONSE;
typedef struct _CFG_GET_CERTHASH_ENTRY_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT32 HashHandle;
} CFG_GET_CERTHASH_ENTRY_REQUEST;
typedef struct _CFG_GET_CERTHASH_ENTRY_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
CERTHASH_ENTRY Hash;
} CFG_GET_CERTHASH_ENTRY_RESPONSE;
typedef struct _CFG_GET_PKI_FQDN_SUFFIX_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_ANSI_STRING Suffix;
} CFG_GET_PKI_FQDN_SUFFIX_RESPONSE;
typedef struct CFG_SET_HOST_FQDN_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT16 FQDNL;
char FQDN[256];
}CFG_SET_HOST_FQDN_REQUEST;
typedef struct _CFG_SET_HOST_FQDN_RESPONSE
{
PTHI_MESSAGE_HEADER Header;
AMT_STATUS Status;
} CFG_SET_HOST_FQDN_RESPONSE;
typedef struct _CFG_GET_LOCAL_SYSTEM_ACCOUNT_RESPONSE
{
PTHI_MESSAGE_HEADER Header;
AMT_STATUS Status;
LOCAL_SYSTEM_ACCOUNT Account;
} CFG_GET_LOCAL_SYSTEM_ACCOUNT_RESPONSE;
typedef struct _CFG_GET_LOCAL_SYSTEM_ACCOUNT_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT8 Reserved[40];
} CFG_GET_LOCAL_SYSTEM_ACCOUNT_REQUEST;
typedef struct _CFG_UNPROVISION_RESPONSE
{
PTHI_MESSAGE_HEADER Header;
AMT_STATUS Status;
} CFG_UNPROVISION_RESPONSE;
typedef struct _CFG_UNPROVISION_REQUEST
{
PTHI_MESSAGE_HEADER Header;
UINT32 Mode;
} CFG_UNPROVISION_REQUEST;
typedef struct _CFG_GETEHBPSTATE_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GETEHBPSTATE_REQUEST;
typedef struct _CFG_GETEHBPSTATE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
AMT_EHBC_STATE EHBCState;
} CFG_GETEHBPSTATE_RESPONSE;
typedef struct _CFG_GET_CONTROL_MODE_REQUEST
{
PTHI_MESSAGE_HEADER Header;
} CFG_GET_CONTROL_MODE_REQUEST;
typedef struct _CFG_GET_CONTROL_MODE_RESPONSE
{
PTHI_RESPONSE_MESSAGE_HEADER Header;
int state;
} CFG_GET_CONTROL_MODE_RESPONSE;
#pragma pack()
AMT_STATUS pthi_GetCodeVersions(CODE_VERSIONS *codeVersions);
AMT_STATUS pthi_GetProvisioningMode(CFG_PROVISIONING_MODE *provisioningMode, AMT_BOOLEAN *legacy);
AMT_STATUS pthi_GetProvisioningState(AMT_PROVISIONING_STATE *state);
AMT_STATUS pthi_GetMacAddresses(UINT8 DedicatedMac[6], UINT8 HostMac[6]);
AMT_STATUS pthi_GetFeaturesState(UINT32 requestID, AMT_BOOLEAN (*requestStatus)[2]);
AMT_STATUS pthi_GetLastHostResetReason(UINT32 *Reason, UINT32 *RemoteControlTimeStamp);
AMT_STATUS pthi_GetCurrentPowerPolicy(AMT_ANSI_STRING *policyName);
AMT_STATUS pthi_GetLanInterfaceSettings(UINT32 interfaceSettings, LAN_SETTINGS *lanSettings);
AMT_STATUS pthi_GetHeciVersion(HECI_VERSION *hecVersion);
AMT_STATUS pthi_GetTLSEnabled(AMT_BOOLEAN *tlsEnabled);
//AMT_STATUS pthi_GetDNSSuffixList(std::list<std::string> *dnsSuffixList);
AMT_STATUS pthi_SetEnterpriseAccess(UINT8 Flags, UINT8 HostIPAddress[16], UINT8 EnterpriseAccess);
AMT_STATUS pthi_GetFWResetReason(UINT8 *MEResetReason);
AMT_STATUS pthi_OpenUserInitiatedConnection();
AMT_STATUS pthi_CloseUserInitiatedConnection();
AMT_STATUS pthi_GetRemoteAccessConnectionStatus(REMOTE_ACCESS_STATUS *remoteAccessStatus);
AMT_STATUS pthi_GenerateRngKey();
AMT_STATUS pthi_GetRngSeedStatus(AMT_RNG_STATUS *rngStatus);
AMT_STATUS pthi_GetZeroTouchEnabled(AMT_BOOLEAN *zeroTouchEnabled);
AMT_STATUS pthi_GetProvisioningTlsMode(AMT_PROVISIONING_TLS_MODE *provisioningTlsMode);
AMT_STATUS pthi_StartConfiguration();
AMT_STATUS pthi_StopConfiguration();
AMT_STATUS pthi_SetProvisioningServerOTP(AMT_ANSI_STRING passwordOTP);
AMT_STATUS pthi_SetDnsSuffix(AMT_ANSI_STRING dnsSuffix);
AMT_STATUS pthi_EnumerateHashHandles(AMT_HASH_HANDLES *hashHandles);
AMT_STATUS pthi_GetCertificateHashEntry(UINT32 hashHandle, CERTHASH_ENTRY *hashEntry);
AMT_STATUS pthi_GetDnsSuffix(AMT_ANSI_STRING *dnsSuffix);
AMT_STATUS pthi_SetHostFQDN(char* str);
AMT_STATUS pthi_GetLocalSystemAccount(LOCAL_SYSTEM_ACCOUNT *localAccount);
AMT_STATUS pthi_Unprovision(CFG_PROVISIONING_MODE provisionMode);
AMT_STATUS pthi_GetStateEHBC(AMT_EHBC_STATE *state);
AMT_STATUS pthi_GetControlMode(int *state);
#define PROVISIONING_MODE_REQUEST 0x04000008
#define PROVISIONING_MODE_RESPONSE 0x04800008
const PTHI_MESSAGE_HEADER GET_PROVISIONING_MODE_HEADER;
#define UNPROVISION_REQUEST 0x04000010
#define UNPROVISION_RESPONSE 0x04800010
const PTHI_MESSAGE_HEADER UNPROVISION_HEADER;
#define PROVISIONING_STATE_REQUEST 0x04000011
#define PROVISIONING_STATE_RESPONSE 0x04800011
const PTHI_MESSAGE_HEADER GET_PROVISIONING_STATE_HEADER;
#define CODE_VERSIONS_REQUEST 0x0400001A
#define CODE_VERSIONS_RESPONSE 0x0480001A
const PTHI_MESSAGE_HEADER GET_CODE_VERSION_HEADER;
#define GET_SECURITY_PARAMETERS_REQUEST 0x0400001B
#define GET_SECURITY_PARAMETERS_RESPONSE 0x0480001B
//const PTHI_MESSAGE_HEADER GET_SECURITY_PARAMETERS_HEADER;
#define GET_MAC_ADDRESSES_REQUEST 0x04000025
#define GET_MAC_ADDRESSES_RESPONSE 0x04800025
const PTHI_MESSAGE_HEADER GET_MAC_ADDRESSES_HEADER;
#define GENERATE_RNG_SEED_REQUEST 0x04000028
#define GENERATE_RNG_SEED_RESPONSE 0x04800028
//const PTHI_MESSAGE_HEADER GENERATE_RNG_SEED_HEADER;
#define SET_PROVISIONING_SERVER_OTP_REQUEST 0x0400002A
#define SET_PROVISIONING_SERVER_OTP_RESPONSE 0x0480002A
#define SET_DNS_SUFFIX_REQUEST 0x0400002F
#define SET_DNS_SUFFIX_RESPONSE 0x0480002F
#define ENUMERATE_HASH_HANDLES_REQUEST 0x0400002C
#define ENUMERATE_HASH_HANDLES_RESPONSE 0x0480002C
//const PTHI_MESSAGE_HEADER ENUMERATE_HASH_HANDLES_HEADER;
#define GET_RNG_SEED_STATUS_REQUEST 0x0400002E
#define GET_RNG_SEED_STATUS_RESPONSE 0x0480002E
//const PTHI_MESSAGE_HEADER GET_RNG_SEED_STATUS_HEADER;
#define GET_DNS_SUFFIX_LIST_REQUEST 0x0400003E
#define GET_DNS_SUFFIX_LIST_RESPONSE 0x0480003E
//const PTHI_MESSAGE_HEADER GET_DNS_SUFFIX_LIST_HEADER;
#define SET_ENTERPRISE_ACCESS_REQUEST 0x0400003F
#define SET_ENTERPRISE_ACCESS_RESPONSE 0x0480003F
//const PTHI_MESSAGE_HEADER SET_ENTERPRISE_ACCESS_HEADER;
#define OPEN_USER_INITIATED_CONNECTION_REQUEST 0x04000044
#define OPEN_USER_INITIATED_CONNECTION_RESPONSE 0x04800044
//const PTHI_MESSAGE_HEADER OPEN_USER_INITIATED_CONNECTION_HEADER;
#define CLOSE_USER_INITIATED_CONNECTION_REQUEST 0x04000045
#define CLOSE_USER_INITIATED_CONNECTION_RESPONSE 0x04800045
//const PTHI_MESSAGE_HEADER CLOSE_USER_INITIATED_CONNECTION_HEADER;
#define GET_REMOTE_ACCESS_CONNECTION_STATUS_REQUEST 0x04000046
#define GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE 0x04800046
//const PTHI_MESSAGE_HEADER GET_REMOTE_ACCESS_CONNECTION_STATUS_HEADER;
#define GET_CURRENT_POWER_POLICY_REQUEST 0x04000047
#define GET_CURRENT_POWER_POLICY_RESPONSE 0x04800047
const PTHI_MESSAGE_HEADER GET_CURRENT_POWER_POLICY_HEADER;
#define GET_LAN_INTERFACE_SETTINGS_REQUEST 0x04000048
#define GET_LAN_INTERFACE_SETTINGS_RESPONSE 0x04800048
//const PTHI_MESSAGE_HEADER GET_LAN_INTERFACE_SETTINGS_HEADER;
#define GET_FEATURES_STATE_REQUEST 0x04000049
#define GET_FEATURES_STATE_RESPONSE 0x04800049
const PTHI_MESSAGE_HEADER GET_FEATURES_STATE_HEADER;
#define GET_LAST_HOST_RESET_REASON_REQUEST 0x0400004A
#define GET_LAST_HOST_RESET_REASON_RESPONSE 0x0480004A
//const PTHI_MESSAGE_HEADER GET_LAST_HOST_RESET_REASON_HEADER;
#define GET_AMT_STATE_REQUEST 0x01000001
#define GET_AMT_STATE_RESPONSE 0x01800001
//const PTHI_MESSAGE_HEADER GET_AMT_STATE_HEADER;
#define GET_ZERO_TOUCH_ENABLED_REQUEST 0x04000030
#define GET_ZERO_TOUCH_ENABLED_RESPONSE 0x04800030
//const PTHI_MESSAGE_HEADER GET_ZERO_TOUCH_ENABLED_HEADER;
#define GET_PROVISIONING_TLS_MODE_REQUEST 0x0400002B
#define GET_PROVISIONING_TLS_MODE_RESPONSE 0x0480002B
//const PTHI_MESSAGE_HEADER GET_PROVISIONING_TLS_MODE_HEADER;
#define START_CONFIGURATION_REQUEST 0x04000029
#define START_CONFIGURATION_RESPONSE 0x04800029
//const PTHI_MESSAGE_HEADER START_CONFIGURATION_HEADER;
#define GET_CERTHASH_ENTRY_REQUEST 0x0400002D
#define GET_CERTHASH_ENTRY_RESPONSE 0x0480002D
//const PTHI_MESSAGE_HEADER GET_CERTHASH_ENTRY_HEADER;
#define GET_PKI_FQDN_SUFFIX_REQUEST 0x04000036
#define GET_PKI_FQDN_SUFFIX_RESPONSE 0x04800036
//
#define SET_HOST_FQDN_REQUEST 0x0400005b
#define SET_HOST_FQDN_RESPONSE 0x0480005b
//const PTHI_MESSAGE_HEADER GET_PKI_FQDN_SUFFIX_HEADER;
#define GET_LOCAL_SYSTEM_ACCOUNT_REQUEST 0x04000067
#define GET_LOCAL_SYSTEM_ACCOUNT_RESPONSE 0x04800067
//const PTHI_MESSAGE_HEADER GET_LOCAL_SYSTEM_ACCOUNT_HEADER;
#define GET_EHBC_STATE_REQUEST 0x4000084
#define GET_EHBC_STATE_RESPONSE 0x4800084
const PTHI_MESSAGE_HEADER GET_EHBC_STATE_HEADER;
#define GET_CONTROL_MODE_REQUEST 0x400006b
#define GET_CONTROL_MODE_RESPONSE 0x480006b
const PTHI_MESSAGE_HEADER GET_CONTROL_MODE_HEADER;
#define STOP_CONFIGURATION_REQUEST 0x400005e
#define STOP_CONFIGURATION_RESPONSE 0x480005e
#endif
#endif

View File

@@ -0,0 +1,427 @@
/*******************************************************************************
* Copyright (C) 2004-2008 Intel Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corp. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef _MINCORE
//----------------------------------------------------------------------------
//
// File: StatusCodeDefinitions.h
//
// Notes: This file contains the definitions of the status codes
// as defined in the Intel<65> AMT Network Design Guide.
//
//----------------------------------------------------------------------------
#ifndef STATUS_CODE_DEFINITIONS_H
#define STATUS_CODE_DEFINITIONS_H
typedef unsigned int PT_STATUS;
//typedef unsigned int AMT_STATUS;
//Request succeeded
#define PT_STATUS_SUCCESS 0x0
#define AMT_STATUS_SUCCESS 0x0
//An internal error in the Intel<65> AMT device has occurred
#define PT_STATUS_INTERNAL_ERROR 0x1
#define AMT_STATUS_INTERNAL_ERROR 0x1
//Intel<65> AMT device has not progressed far enough in its
//initialization to process the command.
#define PT_STATUS_NOT_READY 0x2
#define AMT_STATUS_NOT_READY 0x2
//Command is not permitted in current operating mode.
#define PT_STATUS_INVALID_PT_MODE 0x3
#define AMT_STATUS_INVALID_PT_MODE 0x3
//Length field of header is invalid.
#define PT_STATUS_INVALID_MESSAGE_LENGTH 0x4
#define AMT_STATUS_INVALID_MESSAGE_LENGTH 0x4
//The requested hardware asset inventory table
//checksum is not available.
#define PT_STATUS_TABLE_FINGERPRINT_NOT_AVAILABLE 0x5
#define AMT_STATUS_TABLE_FINGERPRINT_NOT_AVAILABLE 0x5
//The Integrity Check Value field of the request
//message sent by Intel<65> AMT enabled device is invalid.
#define PT_STATUS_INTEGRITY_CHECK_FAILED 0x6
#define AMT_STATUS_INTEGRITY_CHECK_FAILED 0x6
//The specified ISV version is not supported
#define PT_STATUS_UNSUPPORTED_ISVS_VERSION 0x7
#define AMT_STATUS_UNSUPPORTED_ISVS_VERSION 0x7
//The specified queried application is not registered.
#define PT_STATUS_APPLICATION_NOT_REGISTERED 0x8
#define AMT_STATUS_APPLICATION_NOT_REGISTERED 0x8
//Either an invalid name or a not previously registered
//<2F>Enterprise<73> name was specified
#define PT_STATUS_INVALID_REGISTRATION_DATA 0x9
#define AMT_STATUS_INVALID_REGISTRATION_DATA 0x9
//The application handle provided in the request
//message has never been allocated.
#define PT_STATUS_APPLICATION_DOES_NOT_EXIST 0xA
#define AMT_STATUS_APPLICATION_DOES_NOT_EXIST 0xA
//The requested number of bytes cannot be allocated in ISV storage.
#define PT_STATUS_NOT_ENOUGH_STORAGE 0xB
#define AMT_STATUS_NOT_ENOUGH_STORAGE 0xB
//The specified name is invalid.
#define PT_STATUS_INVALID_NAME 0xC
#define AMT_STATUS_INVALID_NAME 0xC
//The specified block does not exist.
#define PT_STATUS_BLOCK_DOES_NOT_EXIST 0xD
#define AMT_STATUS_BLOCK_DOES_NOT_EXIST 0xD
//The specified byte offset is invalid.
#define PT_STATUS_INVALID_BYTE_OFFSET 0xE
#define AMT_STATUS_INVALID_BYTE_OFFSET 0xE
//The specified byte count is invalid.
#define PT_STATUS_INVALID_BYTE_COUNT 0xF
#define AMT_STATUS_INVALID_BYTE_COUNT 0xF
//The requesting application is not
//permitted to request execution of the specified operation.
#define PT_STATUS_NOT_PERMITTED 0x10
#define AMT_STATUS_NOT_PERMITTED 0x10
//The requesting application is not the owner of the block
//as required for the requested operation.
#define PT_STATUS_NOT_OWNER 0x11
#define AMT_STATUS_NOT_OWNER 0x11
//The specified block is locked by another application.
#define PT_STATUS_BLOCK_LOCKED_BY_OTHER 0x12
#define AMT_STATUS_BLOCK_LOCKED_BY_OTHER 0x12
//The specified block is not locked.
#define PT_STATUS_BLOCK_NOT_LOCKED 0x13
#define AMT_STATUS_BLOCK_NOT_LOCKED 0x13
//The specified group permission bits are invalid.
#define PT_STATUS_INVALID_GROUP_PERMISSIONS 0x14
#define AMT_STATUS_INVALID_GROUP_PERMISSIONS 0x14
//The specified group does not exist.
#define PT_STATUS_GROUP_DOES_NOT_EXIST 0x15
#define AMT_STATUS_GROUP_DOES_NOT_EXIST 0x15
//The specified member count is invalid.
#define PT_STATUS_INVALID_MEMBER_COUNT 0x16
#define AMT_STATUS_INVALID_MEMBER_COUNT 0x16
//The request cannot be satisfied because a maximum
//limit associated with the request has been reached.
#define PT_STATUS_MAX_LIMIT_REACHED 0x17
#define AMT_STATUS_MAX_LIMIT_REACHED 0x17
//specified key algorithm is invalid.
#define PT_STATUS_INVALID_AUTH_TYPE 0x18
#define AMT_STATUS_INVALID_AUTH_TYPE 0x18
//Not Used
#define PT_STATUS_AUTHENTICATION_FAILED 0x19
#define AMT_STATUS_AUTHENTICATION_FAILED 0x19
//The specified DHCP mode is invalid.
#define PT_STATUS_INVALID_DHCP_MODE 0x1A
#define AMT_STATUS_INVALID_DHCP_MODE 0x1A
//The specified IP address is not a valid IP unicast address.
#define PT_STATUS_INVALID_IP_ADDRESS 0x1B
#define AMT_STATUS_INVALID_IP_ADDRESS 0x1B
//The specified domain name is not a valid domain name.
#define PT_STATUS_INVALID_DOMAIN_NAME 0x1C
#define AMT_STATUS_INVALID_DOMAIN_NAME 0x1C
//Not Used
#define PT_STATUS_UNSUPPORTED_VERSION 0x1D
#define AMT_STATUS_UNSUPPORTED_VERSION 0x1D
//The requested operation cannot be performed because a
//prerequisite request message has not been received.
#define PT_STATUS_REQUEST_UNEXPECTED 0x1E
#define AMT_STATUS_REQUEST_UNEXPECTED 0x1E
//Not Used
#define PT_STATUS_INVALID_TABLE_TYPE 0x1F
#define AMT_STATUS_INVALID_TABLE_TYPE 0x1F
//The specified provisioning mode code is undefined.
#define PT_STATUS_INVALID_PROVISIONING_STATE 0x20
#define AMT_STATUS_INVALID_PROVISIONING_STATE 0x20
//Not Used
#define PT_STATUS_UNSUPPORTED_OBJECT 0x21
#define AMT_STATUS_UNSUPPORTED_OBJECT 0x21
//The specified time was not accepted by the Intel<65> AMT device
//since it is earlier than the baseline time set for the device.
#define PT_STATUS_INVALID_TIME 0x22
#define AMT_STATUS_INVALID_TIME 0x22
//StartingIndex is invalid.
#define PT_STATUS_INVALID_INDEX 0x23
#define AMT_STATUS_INVALID_INDEX 0x23
//A parameter is invalid.
#define PT_STATUS_INVALID_PARAMETER 0x24
#define AMT_STATUS_INVALID_PARAMETER 0x24
//An invalid netmask was supplied
//(a valid netmask is an IP address in which all <20>1<EFBFBD>s are before
//the <20>0<EFBFBD> <20> e.g. FFFC0000h is valid, FF0C0000h is invalid).
#define PT_STATUS_INVALID_NETMASK 0x25
#define AMT_STATUS_INVALID_NETMASK 0x25
//The operation failed because the Flash wear-out
//protection mechanism prevented a write to an NVRAM sector.
#define PT_STATUS_FLASH_WRITE_LIMIT_EXCEEDED 0x26
#define AMT_STATUS_FLASH_WRITE_LIMIT_EXCEEDED 0x26
//ME FW did not receive the entire image file.
#define PT_STATUS_INVALID_IMAGE_LENGTH 0x27
#define AMT_STATUS_INVALID_IMAGE_LENGTH 0x27
//ME FW received an image file with an invalid signature.
#define PT_STATUS_INVALID_IMAGE_SIGNATURE 0x28
#define AMT_STATUS_INVALID_IMAGE_SIGNATURE 0x28
//LME can not support the requested version.
#define PT_STATUS_PROPOSE_ANOTHER_VERSION 0x29
#define AMT_STATUS_PROPOSE_ANOTHER_VERSION 0x29
//The PID must be a 64 bit quantity made up of ASCII codes
//of some combination of 8 characters <20>
//capital alphabets (A<>Z), and numbers (0<>9).
#define PT_STATUS_INVALID_PID_FORMAT 0x2A
#define AMT_STATUS_INVALID_PID_FORMAT 0x2A
//The PPS must be a 256 bit quantity made up of ASCII codes
//of some combination of 32 characters <20>
//capital alphabets (A<>Z), and numbers (0<>9).
#define PT_STATUS_INVALID_PPS_FORMAT 0x2B
#define AMT_STATUS_INVALID_PPS_FORMAT 0x2B
//Full BIST test has been blocked
#define PT_STATUS_BIST_COMMAND_BLOCKED 0x2C
#define AMT_STATUS_BIST_COMMAND_BLOCKED 0x2C
//A TCP/IP connection could not be opened on with the selected port.
#define PT_STATUS_CONNECTION_FAILED 0x2D
#define AMT_STATUS_CONNECTION_FAILED 0x2D
//Max number of connection reached.
//LME can not open the requested connection.
#define PT_STATUS_CONNECTION_TOO_MANY 0x2E
#define AMT_STATUS_CONNECTION_TOO_MANY 0x2E
//Random key generation is in progress.
#define PT_STATUS_RNG_GENERATION_IN_PROGRESS 0x2F
#define AMT_STATUS_RNG_GENERATION_IN_PROGRESS 0x2F
//A randomly generated key does not exist.
#define PT_STATUS_RNG_NOT_READY 0x30
#define AMT_STATUS_RNG_NOT_READY 0x30
//Self-generated AMT certificate does not exist.
#define PT_STATUS_CERTIFICATE_NOT_READY 0x31
#define AMT_STATUS_CERTIFICATE_NOT_READY 0x31
//This code establishes a dividing line between
//status codes which are common to host interface and
//network interface and status codes which are used by
//network interface only.
#define PT_STATUS_NETWORK_IF_ERROR_BASE 0x800
#define AMT_STATUS_NETWORK_IF_ERROR_BASE 0x800
//The OEM number specified in the remote control
//command is not supported by the Intel<65> AMT device
#define PT_STATUS_UNSUPPORTED_OEM_NUMBER 0x801
#define AMT_STATUS_UNSUPPORTED_OEM_NUMBER 0x801
//The boot option specified in the remote control command
//is not supported by the Intel<65> AMT device
#define PT_STATUS_UNSUPPORTED_BOOT_OPTION 0x802
#define AMT_STATUS_UNSUPPORTED_BOOT_OPTION 0x802
//The command specified in the remote control command
//is not supported by the Intel<65> AMT device
#define PT_STATUS_INVALID_COMMAND 0x803
#define AMT_STATUS_INVALID_COMMAND 0x803
//The special command specified in the remote control command
//is not supported by the Intel<65> AMT device
#define PT_STATUS_INVALID_SPECIAL_COMMAND 0x804
#define AMT_STATUS_INVALID_SPECIAL_COMMAND 0x804
//The handle specified in the command is invalid
#define PT_STATUS_INVALID_HANDLE 0x805
#define AMT_STATUS_INVALID_HANDLE 0x805
//The password specified in the User ACL is invalid
#define PT_STATUS_INVALID_PASSWORD 0x806
#define AMT_STATUS_INVALID_PASSWORD 0x806
//The realm specified in the User ACL is invalid
#define PT_STATUS_INVALID_REALM 0x807
#define AMT_STATUS_INVALID_REALM 0x807
//The FPACL or EACL entry is used by an active
//registration and cannot be removed or modified.
#define PT_STATUS_STORAGE_ACL_ENTRY_IN_USE 0x808
#define AMT_STATUS_STORAGE_ACL_ENTRY_IN_USE 0x808
//Essential data is missing on CommitChanges command.
#define PT_STATUS_DATA_MISSING 0x809
#define AMT_STATUS_DATA_MISSING 0x809
//The parameter specified is a duplicate of an existing value.
//Returned for a case where duplicate entries are added to FPACL
//(Factory Partner Allocation Control List) or EACL
//(Enterprise Access Control List) lists.
#define PT_STATUS_DUPLICATE 0x80A
#define AMT_STATUS_DUPLICATE 0x80A
//Event Log operation failed due to the current freeze status of the log.
#define PT_STATUS_EVENTLOG_FROZEN 0x80B
#define AMT_STATUS_EVENTLOG_FROZEN 0x80B
//The device is missing private key material.
#define PT_STATUS_PKI_MISSING_KEYS 0x80C
#define AMT_STATUS_PKI_MISSING_KEYS 0x80C
//The device is currently generating a keypair.
//Caller may try repeating this operation at a later time.
#define PT_STATUS_PKI_GENERATING_KEYS 0x80D
#define AMT_STATUS_PKI_GENERATING_KEYS 0x80D
//An invalid Key was entered.
#define PT_STATUS_INVALID_KEY 0x80E
#define AMT_STATUS_INVALID_KEY 0x80E
//An invalid X.509 certificate was entered.
#define PT_STATUS_INVALID_CERT 0x80F
#define AMT_STATUS_INVALID_CERT 0x80F
//Certificate Chain and Private Key do not match.
#define PT_STATUS_CERT_KEY_NOT_MATCH 0x810
#define AMT_STATUS_CERT_KEY_NOT_MATCH 0x810
//The request cannot be satisfied because the maximum
//number of allowed Kerberos domains has been reached.
//(The domain is determined by the first 24 Bytes of the SID.)
#define PT_STATUS_MAX_KERB_DOMAIN_REACHED 0x811
#define AMT_STATUS_MAX_KERB_DOMAIN_REACHED 0x811
// The requested configuration is unsupported
#define PT_STATUS_UNSUPPORTED 0x812
#define AMT_STATUS_UNSUPPORTED 0x812
// A profile with the requested priority already exists
#define PT_STATUS_INVALID_PRIORITY 0x813
#define AMT_STATUS_INVALID_PRIORITY 0x813
// Unable to find specified element
#define PT_STATUS_NOT_FOUND 0x814
#define AMT_STATUS_NOT_FOUND 0x814
// Invalid User credentials
#define PT_STATUS_INVALID_CREDENTIALS 0x815
#define AMT_STATUS_INVALID_CREDENTIALS 0x815
// Passphrase is invalid
#define PT_STATUS_INVALID_PASSPHRASE 0x816
#define AMT_STATUS_INVALID_PASSPHRASE 0x816
// A certificate handle must be chosen before the
// operation can be completed.
#define PT_STATUS_NO_ASSOCIATION 0x818
#define AMT_STATUS_NO_ASSOCIATION 0x818
// The command is defined as Audit Log event and can not be
// logged.
#define PT_STATUS_AUDIT_FAIL 0x81B
#define AMT_STATUS_AUDIT_FAIL 0x81B
// One of the ME components is not ready for unprovisioning.
#define PT_STATUS_BLOCKING_COMPONENT 0x81C
#define AMT_STATUS_BLOCKING_COMPONENT 0x81C
//The application has identified an internal error
#define PTSDK_STATUS_INTERNAL_ERROR 0x1000
//An ISV operation was called while the library is not
//initialized
#define PTSDK_STATUS_NOT_INITIALIZED 0x1001
//The requested library I/F is not supported by the current library
//implementation.
#define PTSDK_STATUS_LIB_VERSION_UNSUPPORTED 0x1002
//One of the parameters is invalid (usually indicates a
//NULL pointer or an invalid session handle is specified)
#define PTSDK_STATUS_INVALID_PARAM 0x1003
//The SDK could not allocate sufficient resources to complete the operation.
#define PTSDK_STATUS_RESOURCES 0x1004
//The Library has identified a HW Internal error.
#define PTSDK_STATUS_HARDWARE_ACCESS_ERROR 0x1005
//The application that sent the request message is not registered.
//Usually indicates the registration timeout has elapsed.
//The caller should reregister with the Intel AMT enabled device.
#define PTSDK_STATUS_REQUESTOR_NOT_REGISTERED 0x1006
//A network error has occurred while processing the call.
#define PTSDK_STATUS_NETWORK_ERROR 0x1007
//Specified container can not hold the requested string
#define PTSDK_STATUS_PARAM_BUFFER_TOO_SHORT 0x1008
//For Windows only.
//ISVS_InitializeCOMinThread was not called by the current thread.
#define PTSDK_STATUS_COM_NOT_INITIALIZED_IN_THREAD 0x1009
//The URL parameter was not optional in current configuration.
#define PTSDK_STATUS_URL_REQUIRED 0x100A
#endif
#endif

57
microlms/heci/mei.h Normal file
View File

@@ -0,0 +1,57 @@
/****************************************************************************
****************************************************************************
***
*** This header was automatically generated from a Linux kernel header
*** of the same name, to make information necessary for userspace to
*** call into the kernel available to libc. It contains only constants,
*** structures, and macros generated from the original header, and thus,
*** contains no copyrightable information.
***
*** To edit the content of this header, modify the corresponding
*** source file (e.g. under external/kernel-headers/original/) then
*** run bionic/libc/kernel/tools/update_all.py
***
*** Any manual change here will be lost the next time this script will
*** be run. You've been warned!
***
****************************************************************************
****************************************************************************/
#ifndef _LINUX_MEI_H
#define _LINUX_MEI_H
// #include <linux/types.h>
// #include <linux/string.h>
typedef struct {
unsigned char b[16];
} uuid_le;
#define IOCTL_MEI_CONNECT_CLIENT _IOWR('H' , 0x01, struct mei_connect_client_data)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct mei_client {
unsigned int max_msg_length;
unsigned char protocol_version;
unsigned char reserved[3];
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
};
struct mei_connect_client_data {
union {
uuid_le in_client_uuid;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct mei_client out_client_properties;
};
};
#define IOCTL_MEI_SETUP_DMA_BUF _IOWR('H' , 0x02, struct mei_client_dma_data)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define IOCTL_MEI_UNSET_DMA_BUF _IOW('H' , 0x03, struct mei_client_dma_handle)
struct mei_client_dma_data {
union {
unsigned long userptr;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
};
unsigned int length;
unsigned int handle;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct mei_client_dma_handle {
unsigned int handle;
};
#endif
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */

File diff suppressed because it is too large Load Diff

2012
microlms/lms/ILibLMS.c Normal file

File diff suppressed because it is too large Load Diff

86
microlms/lms/ILibLMS.h Normal file
View File

@@ -0,0 +1,86 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if !defined(_NOHECI)
#ifndef __ILibLMS__
#define __ILibLMS__
#include "../../microstack/ILibAsyncServerSocket.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WIN32
void __fastcall ILibLMS_setregistryA(char* name, char* value);
int __fastcall ILibLMS_getregistryA(char* name, char** value);
int __fastcall ILibLMS_deleteregistryA(char* name);
#endif
struct cimString {
char *data;
int dataLen;
};
struct cimAlertIndication {
struct cimString MessageID;
struct cimString MessageArguments;
struct cimString IndicationTime;
/*
int AlertType;
struct cimString AlertingManagedElement;
int AlertingElementFormat;
struct cimString CorrelatedIndications;
struct cimString Description;
struct cimString EventID;
struct cimString EventTime;
struct cimString IndicationFilterName;
struct cimString IndicationIdentifier;
struct cimString OtherAlertType;
struct cimString OtherAlertingElementFormat;
struct cimString OtherSeverity;
struct cimString OwningEntity;
int PerceivedSeverity;
int ProbableCause;
struct cimString ProbableCauseDescription;
struct cimString ProviderName;
struct cimString RecommendedActions;
struct cimString SequenceContext;
long SequenceNumber;
struct cimString SystemCreationClassName;
struct cimString SystemName;
int Trending;
struct cimString __any;
struct cimString __anyAttribute;
*/
};
extern int ILibMemory_ILibLMS_CONTAINERSIZE;
typedef void(*ILibLMS_OnNotification)(void *module, struct cimAlertIndication *values, char* xml, int xmllen);
void *ILibLMS_CreateEx(void *Chain, char* SelfExe, ILibLMS_OnNotification callback, int extraMemorySize);
#define ILibLMS_Create(Chain, SelfExe, callback) ILibLMS_CreateEx(Chain, SelfExe, callback, 0)
int ILibLMS_GetMeInformation(char** data, int loginmode);
int ILibLMS_GetAmtVersion();
#ifdef __cplusplus
}
#endif
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,108 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "MeshController.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,4,4,0
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Mesh Agent Service"
VALUE "FileVersion", "0.4.4.0"
VALUE "InternalName", "MeshAgent"
VALUE "OriginalFilename", "MeshAgent.exe"
VALUE "ProductName", "Mesh Agent Service"
VALUE "ProductVersion", "0, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,266 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CE5AD78C-DBDF-4D81-9A69-41B1DF683115}</ProjectGuid>
<RootNamespace>MeshConsole</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>MicroLMSService</ProjectName>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</PostBuildEventUseInBuild>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectName)</TargetName>
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</PostBuildEventUseInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSERVICE;_DEBUG;_CONSOLE;MEMORY_CHECK;__STDC__;WINSOCK2;ILibWebServer_SESSION_TRACKING;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);%(PreprocessorDefinitions);MICROSTACK_NO_STDAFX;MICROSTACK_NOTLS;NOCOMMANDER;_XLMSDEBUG</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;DbgHelp.lib;Setupapi.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<Profile>false</Profile>
<OptimizeReferences>true</OptimizeReferences>
<GenerateMapFile>
</GenerateMapFile>
<MapExports>
</MapExports>
<AssemblyDebug>true</AssemblyDebug>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<Manifest>
<AdditionalManifestFiles>$(ProjectDir)dpiaware.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;WIN64;_DEBUG;_CONSOLE;MEMORY_CHECK;MICROSTACK_NO_STDAFX;__STDC__;_CRT_SECURE_NO_WARNINGS;WINSOCK2;MICROSTACK_NOTLS;ILibWebServer_SESSION_TRACKING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;DbgHelp.lib;Setupapi.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
<Profile>true</Profile>
</Link>
<PostBuildEvent>
<Command>REM signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshService" /du "http://opentools.homeip.net" "$(TargetPath)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>Full</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSERVICE;NDEBUG;_CONSOLE;WINSOCK2;_MSC_PLATFORM_TOOLSET_$(PlatformToolset);%(PreprocessorDefinitions);_LINKVM;_XDEBUGLMS;MICROSTACK_NO_STDAFX;MICROSTACK_NOTLS;NOCOMMANDER</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CallingConvention>Cdecl</CallingConvention>
<OmitFramePointers>true</OmitFramePointers>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;DbgHelp.lib;Setupapi.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
<Manifest>
<AdditionalManifestFiles>$(ProjectDir)dpiaware.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>MinSpace</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;WIN64;_WINSERVICE;NDEBUG;_CONSOLE;MICROSTACK_NO_STDAFX;WINSOCK2;MICROSTACK_NOTLS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;DbgHelp.lib;Setupapi.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX64</TargetMachine>
</Link>
<PostBuildEvent>
<Command>signtool.exe sign /sha1 fd5940d8fd585545614fea6da455f25d224b00c9 /d "MeshService" /du "http://opentools.homeip.net" /t http://timestamp.comodoca.com/authenticode "$(TargetPath)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\microstack\ILibCrypto.c" />
<ClCompile Include="..\heci\LMEConnection.c" />
<ClCompile Include="..\..\microstack\ILibAsyncServerSocket.c" />
<ClCompile Include="..\..\microstack\ILibAsyncSocket.c" />
<ClCompile Include="..\..\microstack\ILibParsers.c" />
<ClCompile Include="..\heci\HECIWin.c" />
<ClCompile Include="..\heci\PTHICommand.c" />
<ClCompile Include="..\..\microstack\ILibWebClient.c" />
<ClCompile Include="..\..\microstack\ILibWebServer.c" />
<ClCompile Include="..\..\microstack\md5.c" />
<ClCompile Include="..\..\microstack\sha1.c" />
<ClCompile Include="..\lms\ILibLMS.c" />
<ClCompile Include="ServiceMain.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\microstack\ILibCrypto.h" />
<ClInclude Include="..\heci\LMEConnection.h" />
<ClInclude Include="..\heci\LMS_if.h" />
<ClInclude Include="..\heci\LMS_if_constants.h" />
<ClInclude Include="..\..\microstack\ILibWebClient.h" />
<ClInclude Include="..\..\microstack\ILibWebServer.h" />
<ClInclude Include="..\lms\ILibLMS-WebSite.h" />
<ClInclude Include="..\lms\ILibLMS.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="..\..\microstack\ILibAsyncServerSocket.h" />
<ClInclude Include="..\..\microstack\ILibAsyncSocket.h" />
<ClInclude Include="..\..\microstack\ILibParsers.h" />
<ClInclude Include="..\heci\HECI_if.h" />
<ClInclude Include="..\heci\HECIWin.h" />
<ClInclude Include="..\heci\PTHICommand.h" />
<ClInclude Include="..\heci\StatusCodeDefinitions.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MicroLMSService.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\media\MeshController.ico" />
<Image Include="MeshController.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="microstack">
<UniqueIdentifier>{1b4b4360-c108-47a8-80ae-f3dfa0a7812e}</UniqueIdentifier>
</Filter>
<Filter Include="LMS">
<UniqueIdentifier>{a455730f-2a1c-4da6-97db-902d9bd2ab59}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\heci\LMEConnection.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\heci\HECIWin.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\heci\PTHICommand.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ServiceMain.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibAsyncServerSocket.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibAsyncSocket.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibParsers.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibWebClient.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibWebServer.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\md5.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\sha1.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\..\microstack\ILibCrypto.c">
<Filter>microstack</Filter>
</ClCompile>
<ClCompile Include="..\lms\ILibLMS.c">
<Filter>LMS</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\LMEConnection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\LMS_if.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\LMS_if_constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\HECI_if.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\HECIWin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\PTHICommand.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\heci\StatusCodeDefinitions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibCrypto.h">
<Filter>microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibAsyncServerSocket.h">
<Filter>microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibAsyncSocket.h">
<Filter>microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibParsers.h">
<Filter>microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibWebClient.h">
<Filter>microstack</Filter>
</ClInclude>
<ClInclude Include="..\..\microstack\ILibWebServer.h">
<Filter>microstack</Filter>
</ClInclude>
<ClInclude Include="..\lms\ILibLMS.h">
<Filter>LMS</Filter>
</ClInclude>
<ClInclude Include="..\lms\ILibLMS-WebSite.h">
<Filter>LMS</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MicroLMSService.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\media\MeshController.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="MeshController.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,153 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "..\\..\\media\\MeshController.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,57,4
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Mesh Agent Service"
VALUE "FileVersion", "0.1.57.4"
VALUE "InternalName", "MeshAgent"
VALUE "OriginalFilename", "MeshAgent.exe"
VALUE "ProductName", "Mesh Agent Service"
VALUE "ProductVersion", "0, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_INSTALLDIALOG DIALOGEX 0, 100, 316, 133
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION
CAPTION "Mesh Agent Installer"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Close",IDCANCEL,259,112,50,14
LTEXT "Click the buttons below to install or uninstall the peer-to-peer mesh agent. When installed, the mesh agent runs as a background service, linking up to other computers. The agents facilitates computer management and other applications.",IDC_STATIC,7,7,275,28
GROUPBOX "Installation Information",IDC_STATIC,7,38,302,65
PUSHBUTTON "Install / Update",IDC_INSTALLBUTTON,7,112,77,14
PUSHBUTTON "Uninstall",IDC_UNINSTALLBUTTON,87,112,77,14
ICON IDI_ICON1,IDC_STATIC,288,7,21,20
LTEXT "Current Service Status",IDC_STATIC,14,51,74,8
LTEXT "Unknown",IDC_STATUSTEXT,127,51,175,8,0,WS_EX_RIGHT
LTEXT "New Service Version",IDC_STATIC,14,63,66,8
LTEXT "Unknown",IDC_VERSIONTEXT,127,63,175,8,0,WS_EX_RIGHT
LTEXT "New Trusted Hash",IDC_STATIC,14,87,60,8
LTEXT "Unknown",IDC_HASHTEXT,127,87,175,8,0,WS_EX_RIGHT
LTEXT "New Trusted Policy",IDC_STATIC,14,75,62,8
LTEXT "Unknown",IDC_POLICYTEXT,127,75,175,8,0,WS_EX_RIGHT
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_INSTALLDIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 309
TOPMARGIN, 7
BOTTOMMARGIN, 126
END
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,622 @@
/*
Copyright (c) 2016, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(WINSOCK2)
#include <winsock2.h>
#include <ws2tcpip.h>
#elif defined(WINSOCK1)
#include <winsock.h>
#include <wininet.h>
#endif
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <windows.h>
#include "resource.h"
#include "../../microstack/ILibParsers.h"
#include "../lms/ILibLMS.h"
#if defined(WIN32) && defined (_DEBUG) && !defined(_MINCORE)
#include <crtdbg.h>
#define _CRTDBG_MAP_ALLOC
#endif
void *Chain = NULL;
struct ILibLMS_StateModule *MicroLMS = NULL;
#define VERSION "0.4.4" // Remember to change in the resources as well
int serviceId = 0; // 0 = MicroLMS, 1 = IntelLMS
TCHAR* serviceFile[2] = { TEXT("MicroLMS"), TEXT("LMS") };
TCHAR* serviceName[2] = { TEXT("MicroLMS Service for Intel(R) AMT"), TEXT("Intel(R) Management and Security Application Local Management Service") };
TCHAR* serviceDesc[2] = { TEXT("Provides Intel(R) Active Management Technology (Intel AMT) with local network connectivity and services."), TEXT("Intel(R) Management and Security Application Local Management Service - Provides OS-related Intel(R) ME functionality.") };
SERVICE_STATUS serviceStatus;
SERVICE_STATUS_HANDLE serviceStatusHandle = 0;
void BreakSink(int s)
{
UNREFERENCED_PARAMETER(s);
signal(SIGINT, SIG_IGN); // To ignore any more ctrl-c interrupts
ILibStopChain(Chain);
}
BOOL IsAdmin()
{
BOOL admin;
PSID AdministratorsGroup;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
if ((admin = AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup)) != 0)
{
if (!CheckTokenMembership(NULL, AdministratorsGroup, &admin)) admin = FALSE;
FreeSid(AdministratorsGroup);
}
return admin;
}
void WINAPI ServiceControlHandler(DWORD controlCode)
{
switch (controlCode)
{
case SERVICE_CONTROL_INTERROGATE:
break;
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
SetServiceStatus(serviceStatusHandle, &serviceStatus);
if (Chain != NULL) ILibStopChain(Chain);
Chain = NULL;
return;
default:
break;
}
SetServiceStatus(serviceStatusHandle, &serviceStatus);
}
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
char selfexe[_MAX_PATH];
size_t selfexelen = 0;
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
// Find directory of our own executable
selfexelen = GetModuleFileNameA(NULL, selfexe, _MAX_PATH);
// Initialise service status
serviceStatus.dwServiceType = SERVICE_WIN32;
serviceStatus.dwCurrentState = SERVICE_STOPPED;
serviceStatus.dwControlsAccepted = 0;
serviceStatus.dwWin32ExitCode = NO_ERROR;
serviceStatus.dwServiceSpecificExitCode = NO_ERROR;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
serviceStatusHandle = RegisterServiceCtrlHandler(serviceName[serviceId], ServiceControlHandler);
if (serviceStatusHandle)
{
// Service is starting
serviceStatus.dwCurrentState = SERVICE_START_PENDING;
SetServiceStatus(serviceStatusHandle, &serviceStatus);
// Service running
serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
serviceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(serviceStatusHandle, &serviceStatus);
// Run the MicroLMS Service
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
Chain = ILibCreateChain();
MicroLMS = ILibLMS_Create(Chain, selfexe);
if (MicroLMS != NULL)
{
printf("Starting MicroLMS.\r\n");
ILibStartChain(Chain);
printf("Stopping MicroLMS.\r\n");
}
else
{
printf("Unable to launch MicroLMS. Check that Intel ME is present, MEI driver installed and run this executable as administrator.\r\n");
}
CoUninitialize();
// Service was stopped
serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
SetServiceStatus(serviceStatusHandle, &serviceStatus);
// Service is now stopped
serviceStatus.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
serviceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(serviceStatusHandle, &serviceStatus);
}
}
int RunService()
{
SERVICE_TABLE_ENTRY serviceTable[2];
serviceTable[0].lpServiceName = serviceName[serviceId];
serviceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
serviceTable[1].lpServiceName = NULL;
serviceTable[1].lpServiceProc = NULL;
return StartServiceCtrlDispatcher(serviceTable);
}
BOOL InstallService()
{
SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);
SERVICE_DESCRIPTION sd;
SERVICE_DELAYED_AUTO_START_INFO as;
SERVICE_FAILURE_ACTIONS fa;
SC_ACTION failactions[3];
BOOL r = FALSE;
if (serviceControlManager)
{
char path[1024];
if (GetModuleFileName(0, (LPTSTR)path, 1024) > 0)
{
// Install the service
SC_HANDLE service = CreateService(
serviceControlManager,
serviceFile[serviceId],
serviceName[serviceId],
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_IGNORE,
(LPCTSTR)path,
0, 0, 0, 0, 0);
if (service)
{
// Update the service description
sd.lpDescription = serviceDesc[serviceId];
ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &sd);
// Update the service auto-start
as.fDelayedAutostart = FALSE;
ChangeServiceConfig2(service, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, &as);
// Update the faliure action
failactions[0].Type = SC_ACTION_RESTART;
failactions[0].Delay = 120000; // Wait 2 minutes before faliure restart (milliseconds)
failactions[1].Type = SC_ACTION_RESTART;
failactions[1].Delay = 120000; // Wait 2 minutes before faliure restart (milliseconds)
failactions[2].Type = SC_ACTION_NONE;
failactions[2].Delay = 120000;
memset(&fa, 0, sizeof(SERVICE_FAILURE_ACTIONS));
fa.dwResetPeriod = 86400; // After 1 days, reset the faliure counters (seconds)
fa.cActions = 3;
fa.lpsaActions = failactions;
r = ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS, &fa);
// Cleanup
CloseServiceHandle(service);
#ifdef _DEBUG
//ILIBMESSAGE("MicroLMS service installed successfully");
#endif
}
else
{
#ifdef _DEBUG
if (GetLastError() == ERROR_SERVICE_EXISTS)
{
ILIBMESSAGE("MicroLMS service already exists.");
}
else
{
ILIBMESSAGE2("MicroLMS service was not installed successfully.", (int)GetLastError());
}
#endif
}
}
CloseServiceHandle(serviceControlManager);
}
return r;
}
int UninstallService()
{
int r = 0;
SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
if (serviceControlManager)
{
SC_HANDLE service = OpenService(serviceControlManager, serviceFile[serviceId], SERVICE_QUERY_STATUS | DELETE);
if (service)
{
SERVICE_STATUS serviceStatus;
if (QueryServiceStatus(service, &serviceStatus))
{
if (serviceStatus.dwCurrentState == SERVICE_STOPPED)
{
if (DeleteService(service))
{
#ifdef _DEBUG
//ILIBMESSAGE("MicroLMS service removed successfully");
#endif
r = 1;
}
else
{
#ifdef _DEBUG
DWORD dwError = GetLastError();
if (dwError == ERROR_ACCESS_DENIED) {
ILIBMESSAGE("Access denied while trying to remove MicroLMS service");
}
else if (dwError == ERROR_INVALID_HANDLE) {
ILIBMESSAGE("Handle invalid while trying to remove MicroLMS service");
}
else if (dwError == ERROR_SERVICE_MARKED_FOR_DELETE) {
ILIBMESSAGE("MicroLMS service already marked for deletion");
}
#endif
}
}
else
{
r = 2;
#ifdef _DEBUG
ILIBMESSAGE("MicroLMS service is still running");
#endif
}
}
CloseServiceHandle(service);
}
CloseServiceHandle(serviceControlManager);
}
return r;
}
int GetServiceState(LPCWSTR servicename)
{
int r = 0;
SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
if (serviceControlManager)
{
SC_HANDLE service = OpenService(serviceControlManager, servicename, SERVICE_QUERY_STATUS | DELETE);
if (service)
{
SERVICE_STATUS serviceStatus;
if (QueryServiceStatus(service, &serviceStatus))
{
r = serviceStatus.dwCurrentState;
}
CloseServiceHandle(service);
}
else
{
r = 100;
}
CloseServiceHandle(serviceControlManager);
}
return r;
}
int LaunchService(LPCWSTR servicename)
{
int r = 0;
SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SERVICE_QUERY_STATUS | SERVICE_START);
if (serviceControlManager)
{
SC_HANDLE service = OpenService(serviceControlManager, servicename, SERVICE_QUERY_STATUS | SERVICE_START);
if (service)
{
SERVICE_STATUS serviceStatus;
if (QueryServiceStatus(service, &serviceStatus))
{
if (serviceStatus.dwCurrentState == SERVICE_STOPPED) { if (StartService(service, 0, NULL) == TRUE) { r = 1; } }
else { r = 2; }
}
CloseServiceHandle(service);
}
CloseServiceHandle(serviceControlManager);
}
return r;
}
int StopService(LPCWSTR servicename)
{
int r = 0;
SERVICE_STATUS ServiceStatus;
SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SERVICE_QUERY_STATUS | SERVICE_STOP);
if (serviceControlManager)
{
SC_HANDLE service = OpenService(serviceControlManager, servicename, SERVICE_QUERY_STATUS | SERVICE_STOP);
if (service)
{
SERVICE_STATUS serviceStatus;
if (QueryServiceStatus(service, &serviceStatus))
{
if (serviceStatus.dwCurrentState != SERVICE_STOPPED)
{
if (ControlService(service, SERVICE_CONTROL_STOP, &ServiceStatus) == FALSE)
{
// TODO: Unable to stop service
#ifdef _DEBUG
ILIBMESSAGE("Unable to stop service");
#endif
}
else
{
Sleep(3000);
r = 1;
}
}
}
CloseServiceHandle(service);
}
CloseServiceHandle(serviceControlManager);
}
return r;
}
int RunProcess(char* exe)
{
BOOL r;
int count = 50;
DWORD exitcode;
STARTUPINFOA info = { sizeof(info) };
PROCESS_INFORMATION processInfo;
if (CreateProcessA(NULL, exe, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &info, &processInfo) == 0) return 0;
do
{
Sleep(100);
r = GetExitCodeProcess(processInfo.hProcess, &exitcode);
if (exitcode == STILL_ACTIVE) r = 0;
} while (r == 0 && count-- > 0);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
return r;
}
#ifdef EXCLUSESERVICE
char *helpString = "MicroLMS v" VERSION " available switches : \r\n -run Run LMS as a console application.\r\n -json Output Intel AMT information in JSON format.\r\n -install Install the service from this location.\r\n -uninstall Remove the service from this location.\r\n start Start the service.\r\n stop Stop the service.\r\n auth [user] [pass] Set LMS authentication.\r\n clearauth Clear LMS authentication.\r\n version Display Intel(R) AMT version.\r\n check Check if Intel(R) AMT requires a firmware update.\r\n";
#else
char *helpString = "MicroLMS v" VERSION " available switches : \r\n -run Run LMS as a console application.\r\n version Display Intel(R) AMT version.\r\n check Check if Intel(R) AMT requires a firmware update.\r\n";
#endif
char *lmsStartStrings[3] = { "Failed to start MicroLMS", "Started MicroLMS", "MicroLMS already running" };
char *lmsUninstallStrings[3] = { "Failed to uninstall MicroLMS", "MicroLMS uninstalled", "MicroLMS still running" };
int main(int argc, char* argv[])
{
int returnCode = 0;
char selfexe[_MAX_PATH];
size_t selfexelen = 0;
//CoInitializeEx(NULL, COINIT_MULTITHREADED);
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// Find directory of our own executable
selfexelen = GetModuleFileNameA(NULL, selfexe, _MAX_PATH);
if (argc == 2 && ((strcasecmp(argv[1], "-?") == 0) || (strcasecmp(argv[1], "/?") == 0)))
{
printf(helpString);
return 0;
}
#ifdef EXCLUSESERVICE
else if (argc > 1 && (strcasecmp(argv[1], "start") == 0 || strcasecmp(argv[1], "-start") == 0))
{
// Ask the service manager to launch the service
printf(lmsStartStrings[LaunchService(serviceFile[serviceId])]);
}
else if (argc > 1 && (strcasecmp(argv[1], "stop") == 0 || strcasecmp(argv[1], "-stop") == 0))
{
// Ask the service manager to stop the service
if (StopService(serviceFile[serviceId]) == 1) { printf("Stopped MicroLMS"); }
else { printf("Failed to stop MicroLMS"); }
}
else if (argc > 1 && strcasecmp(argv[1], "-install") == 0)
{
// Setup the service
StopService(serviceFile[serviceId]);
UninstallService();
if (InstallService() == TRUE)
{
printf("MicroLMS installed\r\n");
printf(lmsStartStrings[LaunchService(serviceFile[serviceId])]); // Ask the service manager to launch the service
}
else
{
printf("Failed to install MicroLMS");
}
}
else if (argc > 1 && ((strcasecmp(argv[1], "-remove") == 0) || (strcasecmp(argv[1], "-uninstall") == 0)))
{
// Ask the service manager to stop the service
StopService(serviceFile[serviceId]);
// Remove the service
printf(lmsUninstallStrings[UninstallService()]);
}
else if (argc > 1 && (strcasecmp(argv[1], "intelstart") == 0 || strcasecmp(argv[1], "-intelstart") == 0))
{
// Ask the service manager to launch the service
serviceId = 1; // Set to Intel
printf(lmsStartStrings[LaunchService(serviceFile[serviceId])]);
}
else if (argc > 1 && (strcasecmp(argv[1], "intelstop") == 0 || strcasecmp(argv[1], "-intelstop") == 0))
{
// Ask the service manager to stop the service
serviceId = 1; // Set to Intel
if (StopService(serviceFile[serviceId]) == 1) { printf("Stopped MicroLMS"); }
else { printf("Failed to stop MicroLMS"); }
}
else if (argc > 1 && strcasecmp(argv[1], "-intelinstall") == 0)
{
// Setup the service
serviceId = 1; // Set to Intel
StopService(serviceFile[serviceId]);
UninstallService();
if (InstallService() == TRUE)
{
printf("MicroLMS installed\r\n");
printf(lmsStartStrings[LaunchService(serviceFile[serviceId])]); // Ask the service manager to launch the service
}
else
{
printf("Failed to install MicroLMS");
}
}
else if (argc > 1 && ((strcasecmp(argv[1], "-intelremove") == 0) || (strcasecmp(argv[1], "-inteluninstall") == 0)))
{
// Ask the service manager to stop the service
serviceId = 1; // Set to Intel
StopService(serviceFile[serviceId]);
// Remove the service
printf(lmsUninstallStrings[UninstallService()]);
}
else if (argc == 4 && ((strcasecmp(argv[1], "auth") == 0) || (strcasecmp(argv[1], "-auth") == 0)))
{
// Set authentication user/pass
ILibLMS_setregistryA("username", argv[2]);
ILibLMS_setregistryA("password", argv[3]);
printf("Credentials set");
}
else if (argc == 2 && strcasecmp(argv[1], "clearauth") == 0)
{
// Remote authentication user/pass
ILibLMS_deleteregistryA("username");
ILibLMS_deleteregistryA("password");
printf("Credentials cleared");
}
else if (argc > 1 && ((strcasecmp(argv[1], "json") == 0) || (strcasecmp(argv[1], "-json") == 0)))
{
// Ask the service manager to stop the service
char* data;
int len = info_GetMeInformation(&data, 0);
if (len == 2)
{
printf("Unable to launch MicroLMS. Check that Intel ME is present, MEI driver installed and running as administrator.\r\n");
returnCode = 1;
}
else
{
printf(data + 2);
}
free(data);
}
#endif
else if (argc > 1 && ((strcasecmp(argv[1], "version") == 0) || (strcasecmp(argv[1], "-version") == 0)))
{
// Check to see what version of Intel AMT is present and if it needs to be updates
int version = info_GetAmtVersion();
if (version == 0)
{
printf("Unable to launch MicroLMS. Check that Intel ME is present, MEI driver installed and running as administrator.\r\n");
returnCode = 1;
}
else
{
printf("Intel(R) AMT version %d.%d.%d\r\n", (version >> 16), ((version >> 8) & 0xFF), (version & 0xFF));
}
}
else if (argc > 1 && ((strcasecmp(argv[1], "check") == 0) || (strcasecmp(argv[1], "-check") == 0)))
{
// Check to see what version of Intel AMT is present and if it needs to be updates
int version = info_GetAmtVersion();
if (version == 0)
{
printf("Unable to launch MicroLMS. Check that Intel ME is present, MEI driver installed and running as administrator.\r\n");
returnCode = 1;
}
else
{
// Check if this is a correct version of Intel AMT
int v1 = (version >> 16), v2 = (version >> 8) & 0xFF, v3 = version & 0xFF, vx = ((v2 * 1000) + v3), ok = 0;
printf("Intel(R) AMT version %d.%d.%d\r\n", v1, v2, v3);
if ((v1 <= 5) || (v1 >= 12)) { ok = 1; } // Intel AMT less then v5 and v12 and beyond, all ok.
else if ((v1 == 6) && (vx >= 2061)) { ok = 1; } // 1st Gen Core
else if ((v1 == 7) && (vx >= 1091)) { ok = 1; } // 2st Gen Core
else if ((v1 == 8) && (vx >= 1071)) { ok = 1; } // 3st Gen Core
else if ((v1 == 9)) { if ((v2 < 5) && (vx >= 1041)) { ok = 1; } else if (vx >= 5061) { ok = 1; } } // 4st Gen Core
else if ((v1 == 10) && (vx >= 55)) { ok = 1; } // 5st Gen Core
else if (v1 == 11) {
if ((v2 < 5) && (vx >= 25)) { ok = 1; } // 6st Gen Core
else if (vx >= 6027) { ok = 1; } // 7st Gen Core
}
if (ok == 0) {
printf("This computer requires a firmware update.\r\nPlease check: https://security-center.intel.com/advisory.aspx?intelid=INTEL-SA-00075&languageid=en-fr\r\nExit code 2\r\n");
returnCode = 2;
}
}
}
else if (argc > 1 && (strcasecmp(argv[1], "run") == 0 || strcasecmp(argv[1], "-run") == 0))
{
// Run as an command line application
Chain = ILibCreateChain();
MicroLMS = ILibLMS_Create(Chain, selfexe);
if (MicroLMS != NULL)
{
#ifdef NOCOMMANDER
printf("Starting MicroLMS-lite v" VERSION ", CTRL-C to stop.\r\n");
#elif
printf("Starting MicroLMS v" VERSION ", CTRL-C to stop.\r\nWeb Application at http://127.0.0.1:16994.\r\n");
#endif
ILibStartChain(Chain);
printf("Stopping MicroLMS.\r\n");
}
else
{
printf("Unable to launch MicroLMS. Check that Intel ME is present, MEI driver installed and running as administrator.\r\n");
returnCode = 1;
}
}
#ifdef EXCLUSESERVICE
else
{
if (RunService() == 0 && GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
{
// Shutdown on Ctrl + C
signal(SIGINT, BreakSink);
printf(helpString);
return 0;
}
}
#else
else
{
printf(helpString);
}
#endif
CoUninitialize();
return returnCode;
}

View File

@@ -0,0 +1,8 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View File

@@ -0,0 +1,203 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,20 @@
MicroLMS 0.0.7
--------------
This is an alternative "Local Management Service" (LMS) for Intel AMT. If provides the very basic function of relaying localhost port 16992 & 16993 to Intel AMT, but also offers a web server on port 16994 with a local version of Web Commander hosted there. To use:
-run Run LMS as a console application.
-install Install the service from this location.
-uninstall Remove the service from this location.
start Start the service.
stop Stop the service.
Once running, point a browser to
http://localhost:16992 Access Intel AMT web UI, works if Intel AMT is activated.
https://localhost:16993 Access Intel AMT web UI, works if Intel AMT is activated with TLS.
http://localhost:16994 Access Web Commander, will display Intel AMT status even if not activated.
This is an early version of the code, it's released under Apache 2.0 open source license.
Enjoy!

View File

@@ -0,0 +1,19 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MicroLMSService.rc
//
#define IDI_ICON1 101
#define IDC_BUTTON2 1002
#define IDC_BUTTON3 1004
#define IDC_HASHTEXT2 1008
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,265 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef WIN32
#include <WinSock2.h>
#include <WS2tcpip.h>
#endif
#include "microstack/ILibParsers.h"
#include "microstack/ILibAsyncServerSocket.h"
#include "ILibAsyncSocket_Duktape.h"
#include "ILibDuktape_Helpers.h"
extern char *Duktape_GetStashKey(void* value);
extern char* Duktape_GetBuffer(duk_context *ctx, duk_idx_t i, duk_size_t *bufLen);
duk_idx_t ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(duk_context *ctx, ILibAsyncSocket_SocketModule module);
typedef struct ILibAsyncSocket_Duktape_Bindings
{
duk_context *context;
void *OnData;
void *OnConnect;
void *OnDisconnect;
void *OnSendOK;
}ILibAsyncSocket_Duktape_Bindings;
void ILibAsyncSocket_Duktape_OnData(ILibAsyncSocket_SocketModule socketModule, char* buffer, int *p_beginPointer, int endPointer, ILibAsyncSocket_OnInterrupt* OnInterrupt, void **user, int *PAUSE)
{
ILibAsyncSocket_Duktape_Bindings *bindings = (ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)socketModule)->ExtraMemoryPtr;
if (bindings->OnData == NULL) { *p_beginPointer = endPointer; return; }
duk_push_heapptr(bindings->context, bindings->OnData); // [ptr]
ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(bindings->context, socketModule); // [ptr][obj]
if (duk_has_prop_string(bindings->context, -1, "BufferPtr"))
{
duk_get_prop_string(bindings->context, -1, "BufferPtr"); // [ptr][obj][buffer]
}
else
{
duk_push_external_buffer(bindings->context); // [ptr][obj][buffer]
duk_dup(bindings->context, -1); // [ptr][obj][buffer][buffer]
duk_put_prop_string(bindings->context, -3, "BufferPtr"); // [ptr][obj][buffer]
}
duk_config_buffer(bindings->context, -1, buffer + *p_beginPointer, endPointer);
duk_push_int(bindings->context, endPointer); // [ptr][obj][buffer][endPointer]
if (duk_pcall(bindings->context, 3) == 0) // [retVal]
{
if (duk_is_undefined(bindings->context, -1)) { *p_beginPointer = endPointer; duk_pop(bindings->context); }
else if (duk_is_number(bindings->context, -1))
{
int val = duk_to_int(bindings->context, -1);
if (val < 0) { *PAUSE = 1; }
else { *p_beginPointer = val; }
duk_pop(bindings->context); // ...
}
}
else
{
ILibDuktape_Process_UncaughtException(bindings->context);
duk_pop(bindings->context);
}
}
void ILibAsyncSocket_Duktape_OnConnect(ILibAsyncSocket_SocketModule socketModule, int Connected, void *user)
{
ILibAsyncSocket_Duktape_Bindings *bindings = (ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)socketModule)->ExtraMemoryPtr;
if (bindings->OnConnect != NULL)
{
duk_push_heapptr(bindings->context, bindings->OnConnect); // [ptr]
ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(bindings->context, socketModule); // [ptr][obj]
duk_push_int(bindings->context, Connected); // [ptr][obj][Connected]
if (duk_pcall(bindings->context, 2) != 0) // [retVal]
{
ILibDuktape_Process_UncaughtException(bindings->context);
}
duk_pop(bindings->context); // ...
}
}
void ILibAsyncSocket_Duktape_OnDisconnect(ILibAsyncSocket_SocketModule socketModule, void *user)
{
ILibAsyncSocket_Duktape_Bindings *bindings = (ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)socketModule)->ExtraMemoryPtr;
if (bindings->OnDisconnect != NULL)
{
duk_push_heapptr(bindings->context, bindings->OnDisconnect); // [ptr]
ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(bindings->context, socketModule); // [ptr][obj]
if (duk_pcall(bindings->context, 1) != 0) // [...]
{
ILibDuktape_Process_UncaughtException(bindings->context);
}
duk_pop(bindings->context); //
}
}
void ILibAsyncSocket_Duktape_OnSendOK(ILibAsyncSocket_SocketModule socketModule, void *user)
{
ILibAsyncSocket_Duktape_Bindings *bindings = (ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)socketModule)->ExtraMemoryPtr;
if (bindings->OnSendOK != NULL)
{
duk_push_heapptr(bindings->context, bindings->OnSendOK); // [ptr]
ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(bindings->context, socketModule); // [ptr][obj]
if (duk_pcall(bindings->context, 1) != 0) // [...]
{
ILibDuktape_Process_UncaughtException(bindings->context);
}
duk_pop(bindings->context); //
}
}
duk_ret_t ILibAsyncSocket_Duktape_Create(duk_context *ctx)
{
// ILibCreateAsyncSocketModuleWithMemory(void *Chain, int initialBufferSize, ILibAsyncSocket_OnData OnData, ILibAsyncSocket_OnConnect OnConnect, ILibAsyncSocket_OnDisconnect OnDisconnect, ILibAsyncSocket_OnSendOK OnSendOK, int UserMappedMemorySize)
void *chain;
int initialBufferSize = duk_require_int(ctx, 0);
void *OnData = duk_is_null(ctx, 1) ? NULL : duk_require_heapptr(ctx, 1);
void *OnConnect = duk_is_null(ctx, 2) ? NULL : duk_require_heapptr(ctx, 2);
void *OnDisconnect = duk_is_null(ctx, 3) ? NULL : duk_require_heapptr(ctx, 3);
void *OnSendOK = duk_is_null(ctx, 4) ? NULL : duk_require_heapptr(ctx, 4);
ILibAsyncSocket_SocketModule module;
duk_push_current_function(ctx); // [func]
duk_get_prop_string(ctx, -1, "chain"); // [func][chain]
chain = duk_to_pointer(ctx, -1);
module = ILibCreateAsyncSocketModuleWithMemory(chain, initialBufferSize, ILibAsyncSocket_Duktape_OnData, ILibAsyncSocket_Duktape_OnConnect, ILibAsyncSocket_Duktape_OnDisconnect, ILibAsyncSocket_Duktape_OnSendOK, sizeof(ILibAsyncSocket_Duktape_Bindings));
((ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)module)->ExtraMemoryPtr)->context = ctx;
((ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)module)->ExtraMemoryPtr)->OnConnect = OnConnect;
((ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)module)->ExtraMemoryPtr)->OnData = OnData;
((ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)module)->ExtraMemoryPtr)->OnDisconnect = OnDisconnect;
((ILibAsyncSocket_Duktape_Bindings*)((ILibChain_Link*)module)->ExtraMemoryPtr)->OnSendOK = OnSendOK;
ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(ctx, module); // [obj]
duk_dup(ctx, 1); // [obj][OnData]
duk_put_prop_string(ctx, -2, "OnDataPtr"); // [obj]
duk_dup(ctx, 2); // [obj][OnConnect]
duk_put_prop_string(ctx, -2, "OnConnectPtr"); // [obj]
duk_dup(ctx, 3); // [obj][OnDisconnect]
duk_put_prop_string(ctx, -2, "OnDisconnectPtr"); // [obj]
duk_dup(ctx, 4); // [obj][OnSendOK]
duk_put_prop_string(ctx, -2, "OnSendOKPtr"); // [obj]
return 1;
}
duk_ret_t ILibAsyncSocket_Duktape_Send(duk_context *ctx)
{
ILibAsyncSocket_SocketModule module;
char *buffer = Duktape_GetBuffer(ctx, 0, NULL);
int bufferLen = duk_require_int(ctx, 1);
ILibAsyncSocket_SendStatus retVal;
duk_push_this(ctx); // [obj]
duk_get_prop_string(ctx, -1, "ModulePtr"); // [obj][ptr]
module = duk_to_pointer(ctx, -1);
retVal = ILibAsyncSocket_Send(module, buffer, bufferLen, ILibAsyncSocket_MemoryOwnership_USER);
duk_push_int(ctx, retVal);
return 1;
}
duk_ret_t ILibAsyncSocket_Duktape_Disconnect(duk_context *ctx)
{
ILibAsyncSocket_SocketModule module;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "ModulePtr");
module = duk_to_pointer(ctx, -1);
ILibAsyncSocket_Disconnect(module);
return 0;
}
duk_ret_t ILibAsyncSocket_Duktape_ConnectTo(duk_context *ctx)
{
char *localAddress;
int localPort;
char *remoteAddress;
int remotePort;
struct sockaddr_in6 localAddr;
struct sockaddr_in6 remoteAddr;
ILibAsyncSocket_SocketModule module;
if (!duk_has_prop_string(ctx, 0, "IPAddress")) { duk_push_string(ctx, "Missing [Local] IPAddress Property"); duk_throw(ctx); return DUK_RET_ERROR; }
if (!duk_has_prop_string(ctx, 0, "Port")) { duk_push_string(ctx, "Missing [Local] Port Property"); duk_throw(ctx); return DUK_RET_ERROR; }
if (!duk_has_prop_string(ctx, 1, "IPAddress")) { duk_push_string(ctx, "Missing [Remote] IPAddress Property"); duk_throw(ctx); return DUK_RET_ERROR; }
if (!duk_has_prop_string(ctx, 1, "Port")) { duk_push_string(ctx, "Missing [Remote] Port Property"); duk_throw(ctx); return DUK_RET_ERROR; }
duk_get_prop_string(ctx, 0, "IPAddress");
localAddress = (char*)duk_to_string(ctx, -1);
duk_get_prop_string(ctx, 0, "Port");
localPort = duk_to_int(ctx, -1);
duk_get_prop_string(ctx, 1, "IPAddress");
remoteAddress = (char*)duk_to_string(ctx, -1);
duk_get_prop_string(ctx, 1, "Port");
remotePort = duk_to_int(ctx, -1);
memset(&localAddr, 0, sizeof(struct sockaddr_in6));
memset(&remoteAddr, 0, sizeof(struct sockaddr_in6));
((struct sockaddr_in*)&localAddr)->sin_family = AF_INET;
((struct sockaddr_in*)&localAddr)->sin_port = htons(localPort);
ILibInet_pton(AF_INET, localAddress, &(((struct sockaddr_in*)&localAddr)->sin_addr));
((struct sockaddr_in*)&remoteAddr)->sin_family = AF_INET;
((struct sockaddr_in*)&remoteAddr)->sin_port = htons(remotePort);
ILibInet_pton(AF_INET, remoteAddress, &(((struct sockaddr_in*)&remoteAddr)->sin_addr));
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "ModulePtr");
module = duk_to_pointer(ctx, -1);
ILibAsyncSocket_ConnectTo(module, (struct sockaddr*)&localAddr, (struct sockaddr*)&remoteAddr, NULL, NULL);
return 0;
}
duk_idx_t ILibAsyncSocket_Duktape_PUSH_AsyncSocketModule(duk_context *ctx, ILibAsyncSocket_SocketModule module)
{
char* key = Duktape_GetStashKey(module);
duk_push_heap_stash(ctx); // [stash]
if (duk_has_prop_string(ctx, -1, key))
{
duk_get_prop_string(ctx, -1, key); // [stash][obj]
duk_swap_top(ctx, -2); // [obj][stash]
duk_pop(ctx); // [obj]
return duk_get_top_index(ctx);
}
duk_push_object(ctx); // [stash][obj]
duk_push_pointer(ctx, module); // [stash][obj][pointer]
duk_put_prop_string(ctx, -2, "ModulePtr"); // [stash][obj]
duk_dup(ctx, -1); // [stash][obj][obj]
duk_put_prop_string(ctx, -3, key); // [stash][obj]
duk_swap_top(ctx, -2); // [obj][stash]
duk_pop(ctx); // [obj]
duk_push_c_function(ctx, ILibAsyncSocket_Duktape_Send, 2); // [obj][func]
duk_put_prop_string(ctx, -2, "Send"); // [obj]
duk_push_c_function(ctx, ILibAsyncSocket_Duktape_Disconnect, 0); // [obj][func]
duk_put_prop_string(ctx, -2, "Disconnect"); // [obj]
duk_push_c_function(ctx, ILibAsyncSocket_Duktape_ConnectTo, 2);
duk_put_prop_string(ctx, -2, "ConnectTo");
return duk_get_top_index(ctx);
}
void ILibAsyncSocket_DukTape_Init(duk_context * ctx, void * chain)
{
duk_push_global_object(ctx); // [Global]
duk_push_c_function(ctx, ILibAsyncSocket_Duktape_Create, 5); // [Global][func]
duk_push_pointer(ctx, chain); // [Global][func][chain]
duk_put_prop_string(ctx, -2, "chain"); // [Global][func]
duk_put_prop_string(ctx, -2, "ILibAsyncSocket_Create"); // [Global]
duk_pop(ctx); //
}

View File

@@ -0,0 +1,25 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef ___ILIBASYNCSOCKETDUKTAPE___
#define ___ILIBASYNCSOCKETDUKTAPE___
#include "duktape.h"
void ILibAsyncSocket_DukTape_Init(duk_context *ctx, void * chain);
#endif

View File

@@ -0,0 +1,227 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef WIN32
#include <WinSock2.h>
#include <WS2tcpip.h>
#endif
#include "ILibDuktapeModSearch.h"
#include "microstack/ILibParsers.h"
#include "microscript/ILibDuktape_Helpers.h"
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(_MINCORE)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#define ILibDuktape_ModSearch_ModuleFile "0xFF"
int ILibDuktape_ModSearch_AddModule(duk_context *ctx, char *id, char *module, int moduleLen)
{
ILibHashtable table = NULL;
int idLen = (int)strnlen_s(id, 1024);
duk_push_heap_stash(ctx); // [stash]
if (duk_has_prop_string(ctx, -1, "ModSearchTable"))
{
duk_get_prop_string(ctx, -1, "ModSearchTable"); // [stash][ptr]
table = (ILibHashtable)duk_to_pointer(ctx, -1);
duk_pop(ctx); // [stash]
}
else
{
table = ILibHashtable_Create();
duk_push_pointer(ctx, table); // [stash][ptr]
duk_put_prop_string(ctx, -2, "ModSearchTable"); // [stash]
}
duk_pop(ctx); // ...
if (ILibHashtable_Get(table, NULL, id, idLen) != NULL || ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, idLen) != NULL) { return 1; }
char *newModule = (char*)ILibDuktape_Memory_Alloc(ctx, moduleLen+1);
memcpy_s(newModule, moduleLen + 1, module, moduleLen);
newModule[moduleLen] = 0;
ILibHashtable_Put(table, ILibDuktape_ModSearch_ModuleFile, id, idLen, newModule);
return 0;
}
int ILibDuktape_ModSearch_AddHandler(duk_context *ctx, char *id, ILibDuktape_ModSearch_PUSH_Object handler)
{
ILibHashtable table = NULL;
int idLen = (int)strnlen_s(id, 1024);
duk_push_heap_stash(ctx); // [stash]
if (duk_has_prop_string(ctx, -1, "ModSearchTable"))
{
duk_get_prop_string(ctx, -1, "ModSearchTable"); // [stash][ptr]
table = (ILibHashtable)duk_to_pointer(ctx, -1);
duk_pop(ctx); // [stash]
}
else
{
table = ILibHashtable_Create();
duk_push_pointer(ctx, table); // [stash][ptr]
duk_put_prop_string(ctx, -2, "ModSearchTable"); // [stash]
}
duk_pop(ctx); // ...
if (ILibHashtable_Get(table, NULL, id, idLen) != NULL || ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, idLen) != NULL) { return 1; }
ILibHashtable_Put(table, NULL, id, idLen, handler);
return 0;
}
duk_ret_t mod_Search_Files(duk_context *ctx, char* id)
{
char fileName[255];
char *data;
int dataLen;
sprintf_s(fileName, sizeof(fileName), "%s.js", id);
dataLen = ILibReadFileFromDiskEx(&data, fileName);
if (dataLen > 0)
{
duk_push_lstring(ctx, data, dataLen);
free(data);
return 1;
//if (duk_peval_string(ctx, data) == 0)
//{
// duk_put_prop_string(ctx, 3, "exports");
// return 0;
//}
//else
//{
// snprintf(fileName, sizeof(fileName), "Module: %s (ERROR)", id);
// duk_push_string(ctx, fileName);
// duk_throw(ctx);
// return DUK_RET_ERROR;
//}
}
else
{
sprintf_s(fileName, sizeof(fileName), "Module: %s (NOT FOUND)", id);
duk_push_string(ctx, fileName);
duk_throw(ctx);
return DUK_RET_ERROR;
}
}
duk_ret_t mod_Search(duk_context *ctx)
{
duk_size_t idLen;
char *id;
ILibHashtable *table;
ILibDuktape_ModSearch_PUSH_Object func = NULL;
void *chain;
ILibSimpleDataStore mDS = NULL;
char *module;
if (!duk_is_string(ctx, 0)) { return ILibDuktape_Error(ctx, "mod_search(): Invalid 'ID' parameter"); }
id = (char*)duk_get_lstring(ctx, 0, &idLen);
duk_push_current_function(ctx); // [func]
duk_get_prop_string(ctx, -1, "chain"); // [func][chain]
chain = duk_to_pointer(ctx, -1);
duk_get_prop_string(ctx, -2, "SimpleDS"); // [func][chain][DB]
mDS = (ILibSimpleDataStore)duk_to_pointer(ctx, -1);
duk_push_heap_stash(ctx);
duk_get_prop_string(ctx, -1, "ModSearchTable");
table = (ILibHashtable)duk_to_pointer(ctx, -1);
func = (ILibDuktape_ModSearch_PUSH_Object)ILibHashtable_Get(table, NULL, id, (int)idLen);
if (func == NULL)
{
if ((module = (char*)ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, (int)idLen)) != NULL)
{
duk_push_string(ctx, module);
return(1);
}
else if (mDS == NULL)
{
return mod_Search_Files(ctx, id);
}
else
{
char key[255];
int keyLen;
char *value;
int valueLen;
keyLen = sprintf_s(key, sizeof(key), "__MODULE:%s", id);
valueLen = ILibSimpleDataStore_GetEx(mDS, key, keyLen, NULL, 0);
if (valueLen > 0)
{
value = ILibMemory_Allocate(valueLen, 0, NULL, NULL);
ILibSimpleDataStore_GetEx(mDS, key, keyLen, value, valueLen);
duk_push_lstring(ctx, value, valueLen);
return 1;
}
else
{
sprintf_s(key, sizeof(key), "Module: %s (NOT FOUND in DB)", id);
duk_push_string(ctx, key);
duk_throw(ctx);
return DUK_RET_ERROR;
}
}
}
else
{
func(ctx, chain);
duk_put_prop_string(ctx, 3, "exports");
return 0;
}
}
void ILibDuktape_ModSearch_Destroy(duk_context *ctx, void *user)
{
duk_push_heap_stash(ctx); // [stash]
if (duk_has_prop_string(ctx, -1, "ModSearchTable"))
{
duk_get_prop_string(ctx, -1, "ModSearchTable"); // [stash][ptr]
ILibHashtable_Destroy((ILibHashtable)duk_to_pointer(ctx, -1));
duk_del_prop_string(ctx, -2, "ModSearchTable");
duk_pop_2(ctx);
}
else
{
duk_pop(ctx);
}
}
void ILibDuktape_ModSearch_Init(duk_context * ctx, void * chain, ILibSimpleDataStore mDB)
{
duk_push_heap_stash(ctx); // [stash]
duk_push_pointer(ctx, chain); // [stash][chain]
duk_put_prop_string(ctx, -2, ILibDuktape_Context_Chain); // [stash]
duk_pop(ctx); // ...
duk_get_global_string(ctx, "Duktape"); // [globalString]
duk_push_c_function(ctx, mod_Search, 4); // [globalString][func]
duk_push_pointer(ctx, chain); // [globalString][func][chain]
duk_put_prop_string(ctx, -2, "chain"); // [globalString][func]
if (mDB != NULL)
{
duk_push_pointer(ctx, mDB); // [globalString][func][DB]
duk_put_prop_string(ctx, -2, "SimpleDS"); // [globalString][func]
}
duk_put_prop_string(ctx, -2, "modSearch"); // [globalString]
duk_pop(ctx); // ...
ILibDuktape_Helper_AddHeapFinalizer(ctx, ILibDuktape_ModSearch_Destroy, NULL);
}

View File

@@ -0,0 +1,29 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef ___ILIBDUKTAPEMODSEARCH___
#define ___ILIBDUKTAPEMODSEARCH___
#include "duktape.h"
#include "microstack/ILibSimpleDataStore.h"
typedef void (*ILibDuktape_ModSearch_PUSH_Object)(duk_context *ctx, void *chain);
int ILibDuktape_ModSearch_AddHandler(duk_context *ctx, char *id, ILibDuktape_ModSearch_PUSH_Object handler);
int ILibDuktape_ModSearch_AddModule(duk_context *ctx, char *id, char *module, int moduleLen);
void ILibDuktape_ModSearch_Init(duk_context *ctx, void *chain, ILibSimpleDataStore mDB);
#endif

View File

@@ -0,0 +1,90 @@
/*
Copyright 2006 - 2017 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef WIN32
#include <WinSock2.h>
#include <ws2tcpip.h>
#endif
#include "microstack/ILibParsers.h"
#include "microstack/ILibAsyncServerSocket.h"
#include "ILibDuktape_Helpers.h"
#include "duktape.h"
typedef struct ILibDuktape_Debugger
{
duk_context *ctx;
#ifdef WIN32
SOCKET listener;
SOCKET client;
#else
int listener;
int client;
#endif
}ILibDuktape_Debugger;
duk_size_t ILibDuktape_Debugger_ReadCB(void *udata, char *buffer, duk_size_t length)
{
ILibDuktape_Debugger *dbg = (ILibDuktape_Debugger*)udata;
return (duk_size_t)recv(dbg->client, buffer, (int)length, 0);
}
duk_size_t ILibDuktape_Debugger_WriteCB(void *udata, const char *buffer, duk_size_t length)
{
ILibDuktape_Debugger *dbg = (ILibDuktape_Debugger*)udata;
return (duk_size_t)send(dbg->client, buffer, (int)length, 0);
}
void ILibDuktape_Debugger_DetachCB(void *udata)
{
}
void ILibDuktape_Debugger_Start(duk_context *ctx, unsigned short debugPort)
{
ILibDuktape_Debugger *dbg;
struct sockaddr_in6 local_int;
struct sockaddr_in6 remote_int;
int remote_int_size = sizeof(struct sockaddr_in6);
memset(&local_int, 0, sizeof(struct sockaddr_in6));
local_int.sin6_family = AF_INET;
((struct sockaddr_in*)&local_int)->sin_addr.s_addr = INADDR_ANY;
local_int.sin6_port = htons(debugPort);
duk_push_global_object(ctx); // [obj]
duk_push_fixed_buffer(ctx, sizeof(ILibDuktape_Debugger)); // [obj][buf]
dbg = (ILibDuktape_Debugger*)Duktape_GetBuffer(ctx, -1, NULL);
duk_put_prop_string(ctx, -2, "_DbgObj"); // [obj]
duk_pop(ctx); // ...
memset(dbg, 0, sizeof(ILibDuktape_Debugger));
dbg->ctx = ctx;
if((dbg->listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { dbg->listener = (SOCKET)~0; return; }
bind(dbg->listener, (struct sockaddr*)&local_int, sizeof(struct sockaddr_in6));
listen(dbg->listener, 1);
dbg->client = accept(dbg->listener, (struct sockaddr*)&remote_int, &remote_int_size);
duk_debugger_attach(ctx, ILibDuktape_Debugger_ReadCB, ILibDuktape_Debugger_WriteCB, NULL, NULL, NULL, ILibDuktape_Debugger_DetachCB, (void*)dbg);
}
void ILibDuktape_Debugger_Stop(duk_context *ctx)
{
}

Some files were not shown because too many files have changed in this diff Show More