From af23814ce00d7e9389cfd06c6718020a38d41e3f Mon Sep 17 00:00:00 2001 From: Pixelistik Date: Thu, 3 Dec 2015 12:57:04 +0100 Subject: [PATCH] Use correct MAC derivation from Gluon 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. --- spec/nodeListTransformSpec.js | 99 ++++++++++------------------------- www/js/nodeListTransform.js | 54 +++++++++---------- 2 files changed, 55 insertions(+), 98 deletions(-) diff --git a/spec/nodeListTransformSpec.js b/spec/nodeListTransformSpec.js index 48a72f5..6c145db 100644 --- a/spec/nodeListTransformSpec.js +++ b/spec/nodeListTransformSpec.js @@ -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"); }); }); diff --git a/www/js/nodeListTransform.js b/www/js/nodeListTransform.js index 2bc6422..f126b67 100644 --- a/www/js/nodeListTransform.js +++ b/www/js/nodeListTransform.js @@ -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) {} @@ -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) {