Skip to content

Commit

Permalink
Use correct MAC derivation from Gluon
Browse files Browse the repository at this point in the history
See https://forum.freifunk.net/t/wifi-analyzer-alias-app/8475/11
The alias list generation now uses the same algorithm for generating the
MACs of the access point interfaces (called "client" in Gluon) as the
firmware.
  • Loading branch information
pixelistik committed Dec 3, 2015
1 parent 91b26e3 commit af23814
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 98 deletions.
99 changes: 28 additions & 71 deletions spec/nodeListTransformSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,74 @@ var assert = require("chai").assert
var nodeListTransform = require("../www/js/nodeListTransform.js")

describe("Wifi Analyzer alias list", function () {
it("should list a simple node", function () {
var result = nodeListTransform({
nodes: {
c423523487: {
nodeinfo: {
hostname: "host-one",
network: {
mesh: {
bat0: {
interfaces: {
wireless: ["99:ee:ee:ee:01:01"]
}
}
}
}
}
}
}
});
assert.include(result, "99:ee:ee:ee:01:01|host-one (99:ee:ee:ee:01:01)");
});
it("should derive 2 client MACs from the primary MAC correctly", function () {7
var hostname = "derive-mac-test-host";
var primaryMac = "24:a4:3c:b1:11:d9";
var expectedClientMac1 = "26:a6:3d:b1:11:d9";
var expectedClientMac2 = "26:a6:3e:b1:11:d9";

it("should filter out nodes without hostname", function () {
var result = nodeListTransform({
var nodeData = {
nodes: {
c423523487: {
nodeinfo: {
network: {
mesh: {
bat0: {
interfaces: {
wireless: ["99:ee:ee:ee:01:01"]
}
}
}
}
}
c46e1f875ef0: {
nodeinfo: {
hostname: hostname,
network: {
mac: primaryMac
},
}
}
}
});
assert.notInclude(result.join(), "undefined");
};

var result = nodeListTransform(nodeData);

assert.include(result, expectedClientMac1 + "|" + hostname + " (" + expectedClientMac1 + ")");
assert.include(result, expectedClientMac2 + "|" + hostname + " (" + expectedClientMac2 + ")");
});

it("should filter out nodes without interfaces", function () {
it("should list a simple node", function () {
var result = nodeListTransform({
nodes: {
c423523487: {
nodeinfo: {
hostname: "host-one",
network: {
mesh: {
bat0: {}
}
mac: "99:ee:ee:ee:01:01"
}
}
}
}
});

assert.notInclude(result.join(), "undefined");
assert.include(result.join(), "host-one");
});

it("should list a node with multiple macs", function () {
it("should filter out nodes without hostname", function () {
var result = nodeListTransform({
nodes: {
c423523487: {
nodeinfo: {
hostname: "host-one",
network: {
mesh: {
bat0: {
interfaces: {
wireless: [
"99:ee:ee:ee:01:01",
"11:ee:ee:ee:01:01"
]
}
}
}
mac: "99:ee:ee:ee:01:01"
}
}
}
}
});

assert.include(result, "99:ee:ee:ee:01:01|host-one (99:ee:ee:ee:01:01)");
assert.include(result, "11:ee:ee:ee:01:01|host-one (11:ee:ee:ee:01:01)");
assert.notInclude(result.join(), "undefined");
});

it("should add the next and previous mac", function () {
it("should filter out nodes without mac", function () {
var result = nodeListTransform({
nodes: {
c423523487: {
nodeinfo: {
hostname: "host-one",
network: {
mesh: {
bat0: {
interfaces: {
wireless: ["99:ee:ee:ee:01:01"]
}
}
}
}
network: {}
}
}
}
});

assert.include(result, "99:ee:ee:ee:01:01|host-one (99:ee:ee:ee:01:01)");
assert.include(result, "99:ef:ee:ee:01:01|host-one (99:ef:ee:ee:01:01)");
assert.include(result, "99:ed:ee:ee:01:01|host-one (99:ed:ee:ee:01:01)");
assert.notInclude(result.join(), "undefined");
});
});
54 changes: 27 additions & 27 deletions www/js/nodeListTransform.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
(function (window) {
var nodeListTransform = function (nodeData) {
var deriveClientMacs = function () {
return "foo";
};

var nodes = nodeData.nodes;

var nodeList = [];
var macList = [];
var extendedMacList = [];

var nodeWithOffsetMac = function (node, offset) {
var macParts = node.mac.split(":");
macParts[1] = (parseInt(macParts[1], 16) + offset).toString(16);

return {
hostname: node.hostname,
mac: macParts.join(":")
};
}

var nodeWithPreviousMac = function (node) {
return nodeWithOffsetMac(node, -1);
}

var nodeWithNextMac = function (node) {
return nodeWithOffsetMac(node, +1);
}

for (var id in nodes) {
try {
if (
typeof nodes[id].nodeinfo.hostname !== "undefined" &&
(
typeof nodes[id].nodeinfo.network.mesh.bat0.interfaces.wireless !== "undefined" ||
typeof nodes[id].nodeinfo.network.mesh.bat0.interfaces.other !== "undefined"
)
typeof nodes[id].nodeinfo.network.mac !== "undefined"
) {
nodeList.push({
hostname: nodes[id].nodeinfo.hostname,
macs: nodes[id].nodeinfo.network.mesh.bat0.interfaces.wireless || nodes[id].nodeinfo.network.mesh.bat0.interfaces.other
macs: [nodes[id].nodeinfo.network.mac]
});
}
} catch (e) {}
Expand All @@ -50,10 +32,28 @@
});
});

/**
* Derive MACs of the public client MACs from primary MAC
*
* @see https://forum.freifunk.net/t/wifi-analyzer-alias-app/8475/11
*/
var nodeWithDerivedClientMac = function (node, offset) {
var macParts = node.mac.split(":");
macParts[0] = (parseInt(macParts[0], 16) + 2).toString(16);
macParts[1] = (parseInt(macParts[1], 16) + 2).toString(16);
macParts[2] = (parseInt(macParts[2], 16) + offset).toString(16);

return {
hostname: node.hostname,
mac: macParts.join(":")
};
}

var extendedMacList = [];

macList.forEach(function (node) {
extendedMacList.push(node);
extendedMacList.push(nodeWithPreviousMac(node));
extendedMacList.push(nodeWithNextMac(node));
extendedMacList.push(nodeWithDerivedClientMac(node, 1));
extendedMacList.push(nodeWithDerivedClientMac(node, 2));
});

return extendedMacList.map(function (node) {
Expand Down

0 comments on commit af23814

Please sign in to comment.