From c734de5d5e91cb0b3f1c619d20eec88969dec77d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 10 Nov 2023 01:19:13 +0000 Subject: [PATCH] first commit --- Makefile | 10 +++ README.md | 0 luasrc/controller/mesh.lua | 10 +++ luasrc/model/cbi/mesh/mesh_hearing_map.lua | 70 +++++++++++++++ luasrc/model/cbi/mesh/mesh_network.lua | 94 ++++++++++++++++++++ luasrc/tools/ieee80211.lua | 20 +++++ root/usr/share/rpcd/acl.d/luci-app-mesh.json | 11 +++ 7 files changed, 215 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 luasrc/controller/mesh.lua create mode 100644 luasrc/model/cbi/mesh/mesh_hearing_map.lua create mode 100644 luasrc/model/cbi/mesh/mesh_network.lua create mode 100644 luasrc/tools/ieee80211.lua create mode 100644 root/usr/share/rpcd/acl.d/luci-app-mesh.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0b6f1cf --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for Dawn Mesh Wireless Control +LUCI_DEPENDS:=+dawn +luci-compat +luci-lib-json +LUCI_PKGARCH:=all + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/luasrc/controller/mesh.lua b/luasrc/controller/mesh.lua new file mode 100644 index 0000000..440dd1a --- /dev/null +++ b/luasrc/controller/mesh.lua @@ -0,0 +1,10 @@ +module("luci.controller.mesh", package.seeall) + +function index() + local e = entry({ "admin", "mesh" }, firstchild(), "Mesh", 60) + e.dependent = false + e.acl_depends = { "luci-app-mesh" } + + entry({ "admin", "mesh", "view_network" }, cbi("mesh/mesh_network"), "Mesh Network Overview", 1) + entry({ "admin", "mesh", "view_hearing_map" }, cbi("mesh/mesh_hearing_map"), "Wireless Hearing Map", 2) +end diff --git a/luasrc/model/cbi/mesh/mesh_hearing_map.lua b/luasrc/model/cbi/mesh/mesh_hearing_map.lua new file mode 100644 index 0000000..0d3f215 --- /dev/null +++ b/luasrc/model/cbi/mesh/mesh_hearing_map.lua @@ -0,0 +1,70 @@ +m = Map("mesh", "Hearing Map", translate("Wireless Hearing Map")) +m.pageaction = false + +s = m:section(NamedSection, "__hearingmap__") + +function s.render(self, sid) + local tpl = require "luci.template" + tpl.render_string([[ + <% + local utl = require "luci.util" + local xml = require "luci.xml" + local status = require "luci.tools.ieee80211" + local stat = utl.ubus("dawn", "get_hearing_map", { }) + local name, macs + + for name, macs in pairs(stat) do + %> +
+

SSID: <%= xml.pcdata(name) %>

+ + + + + + + + + + + + + + + <% + local mac, data + for mac, data in pairs(macs) do + + local mac2, data2 + local count_loop = 0 + for mac2, data2 in pairs(data) do + if data2.freq ~= 0 then --prevent empty entry crashes + %> + + + + + + + + + + + + + + <% + count_loop = count_loop + 1 + end + end + end + %> +
Client MACAP MACFrequencyHT SupVHT SupSignalRCPIRSNIChannel UtilizationStation connect to APScore
<%= (count_loop == 0) and mac or "" %><%= mac2 %><%= "%.3f" %( data2.freq / 1000 ) %> GHz Channel: <%= "%d" %( status.frequency_to_channel(data2.freq) ) %><%= (data2.ht_capabilities == true and data2.ht_support == true) and "True" or "False" %><%= (data2.vht_capabilities == true and data2.vht_support == true) and "True" or "False" %><%= "%d" % data2.signal %><%= "%d" % data2.rcpi %><%= "%d" % data2.rsni %><%= "%.2f" % (data2.channel_utilization / 2.55) %> %<%= "%d" % data2.num_sta %><%= "%d" % data2.score %>
+
+ <% + end + %> + ]]) +end + +return m diff --git a/luasrc/model/cbi/mesh/mesh_network.lua b/luasrc/model/cbi/mesh/mesh_network.lua new file mode 100644 index 0000000..51053b2 --- /dev/null +++ b/luasrc/model/cbi/mesh/mesh_network.lua @@ -0,0 +1,94 @@ +m = Map("mesh", "Network Overview", translate("Wireless Network Overview")) +m.pageaction = false + +s = m:section(NamedSection, "__networkoverview__") + +function s.render(self, sid) + local tpl = require "luci.template" + local json = require "luci.json" + local utl = require "luci.util" + tpl.render_string([[ + <% + local status = require "luci.tools.ieee80211" + local utl = require "luci.util" + local sys = require "luci.sys" + local xml = require "luci.xml" + local hosts = sys.net.host_hints() + local stat = utl.ubus("dawn", "get_network", { }) + local name, macs + for name, macs in pairs(stat) do + %> +
+

SSID: <%= xml.pcdata(name) %>

+ + + + + + <% + local mac, data + for mac, data in pairs(macs) do + %> + + + + + <% + end + %> +
APClients
+ + + + + + + + + + + + + + + + + + + + + +
HostnameInterfaceMACUtilizationFrequencyStationsHT SupVHT Sup
<%= xml.pcdata(data.hostname) %><%= xml.pcdata(data.iface) %><%= mac %><%= "%.2f" %(data.channel_utilization / 2.55) %> %<%= "%.3f" %( data.freq / 1000 ) %> GHz (Channel: <%= "%d" %( status.frequency_to_channel(data.freq) ) %>)<%= "%d" % data.num_sta %><%= (data.ht_support == true) and "available" or "not available" %><%= (data.vht_support == true) and "available" or "not available" %>
+
+ + + + + + + + <% + local mac2, data2 + for clientmac, clientvals in pairs(data) do + if (type(clientvals) == "table") then + %> + + + + + + + <% + end + end + %> +
MACHTVHTSignal
<%= clientmac %><%= (clientvals.ht == true) and "available" or "not available" %><%= (clientvals.vht == true) and "available" or "not available" %><%= "%d" % clientvals.signal %>
+
+
+ <% + end + %> + ]]) +end + +return m diff --git a/luasrc/tools/ieee80211.lua b/luasrc/tools/ieee80211.lua new file mode 100644 index 0000000..44b0464 --- /dev/null +++ b/luasrc/tools/ieee80211.lua @@ -0,0 +1,20 @@ +module("luci.tools.ieee80211", package.seeall) + +function frequency_to_channel(freq) + if (freq <= 2400) then + return 0; + elseif (freq == 2484) then + return 14; + elseif (freq < 2484) then + return (freq - 2407) / 5; + elseif (freq >= 4910 and freq <= 4980) then + return (freq - 4000) / 5; + elseif (freq <= 45000) then + return (freq - 5000) / 5; + elseif (freq >= 58320 and freq <= 64800) then + return (freq - 56160) / 2160; + else + return 0; + end +end + diff --git a/root/usr/share/rpcd/acl.d/luci-app-mesh.json b/root/usr/share/rpcd/acl.d/luci-app-mesh.json new file mode 100644 index 0000000..09f4ff2 --- /dev/null +++ b/root/usr/share/rpcd/acl.d/luci-app-mesh.json @@ -0,0 +1,11 @@ +{ + "luci-app-mesh": { + "description": "Grant UCI access for luci-app-mesh", + "read": { + "uci": [ "mesh" ] + }, + "write": { + "uci": [ "mesh" ] + } + } +}