From 89a9d8138c4b48726bd17abe9128385b3430af14 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 29 Aug 2015 23:37:40 +0200 Subject: [PATCH] gluon-mesh-batman-adv-core: Announce client count by frequency --- .../lib/gluon/announce/statistics.d/clients | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/statistics.d/clients b/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/statistics.d/clients index 235865ed..8e4506e9 100644 --- a/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/statistics.d/clients +++ b/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/statistics.d/clients @@ -1,20 +1,55 @@ -local list = io.lines("/sys/kernel/debug/batman_adv/bat0/transtable_local") +local iwinfo = require 'iwinfo' -local count = 0 -local wifi = 0 +local counts = { total = 0 + , wifi = 0 + , wifi24 = 0 + , wifi5 = 0 + } + +local list = io.lines("/sys/kernel/debug/batman_adv/bat0/transtable_local") +local clients = {} for line in list do local mac, _, flags, lastseen = line:match("^ %* ([0-9a-f:]+) *(.- )%[(.-)%] +(%d+%.%d+)") if mac then if not flags:match('P') then - count = count + 1 + counts.total = counts.total + 1 + clients[mac:lower()] = true if flags:match('W') then - wifi = wifi +1 + counts.wifi = counts.wifi +1 end end end end -return { total = count - , wifi = wifi - } +function count_iface_stations(iface) + local wifitype = iwinfo.type(iface) + if wifitype == nil then + return + end + + local freq = iwinfo[wifitype].frequency(iface) + local key + if freq >= 2400 and freq < 2500 then + key = "wifi24" + elseif freq >= 5000 and freq < 6000 then + key = "wifi5" + else + return + end + + for k, v in pairs(iwinfo[wifitype].assoclist(iface)) do + if clients[k:lower()] then + counts[key] = counts[key] + 1 + end + end +end + +local ifaces = {} +uci:foreach("wireless", "wifi-iface", function(s) + if s.network == "client" and s.mode == "ap" then + count_iface_stations(s.ifname) + end +end) + +return counts