2022-12-22 13:22:49 -07:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
Copyright (C) 2022 Tim Wilkinson
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
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, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
|
|
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
|
|
|
Attributions to the AREDN Project must be retained in the source code.
|
|
|
|
If importing this code into a new or existing project attribution
|
|
|
|
to the AREDN project must be added to the source code.
|
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2023-06-01 18:06:39 -06:00
|
|
|
local periodic_scan_tick = 5
|
2023-01-03 22:25:22 -07:00
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
local wifiiface
|
2023-06-07 23:42:42 -06:00
|
|
|
local phy
|
2022-12-22 13:22:49 -07:00
|
|
|
|
|
|
|
function rssi_monitor_10k()
|
2023-02-17 22:02:21 -07:00
|
|
|
if not string.match(get_ifname("wifi"), "^wlan") then
|
2022-12-22 13:22:49 -07:00
|
|
|
exit_app()
|
|
|
|
else
|
|
|
|
wait_for_ticks(math.max(1, 120 - nixio.sysinfo().uptime))
|
|
|
|
|
|
|
|
wifiiface = get_ifname("wifi")
|
|
|
|
|
|
|
|
-- ath10k only
|
2023-06-07 23:42:42 -06:00
|
|
|
phy = iwinfo.nl80211.phyname(wifiiface)
|
2022-12-22 22:35:01 -07:00
|
|
|
if not phy or not nixio.fs.stat("/sys/kernel/debug/ieee80211/" .. phy .. "/ath10k") then
|
2022-12-22 13:22:49 -07:00
|
|
|
exit_app()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
run_monitor_10k()
|
|
|
|
wait_for_ticks(60) -- 1 minute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local logfile = "/tmp/rssi_ath10k.log"
|
|
|
|
|
|
|
|
if not file_exists(logfile) then
|
|
|
|
io.open(logfile, "w+"):close()
|
|
|
|
end
|
|
|
|
|
2023-06-01 18:06:39 -06:00
|
|
|
local station_zero = 0
|
2022-12-22 13:22:49 -07:00
|
|
|
local log = aredn.log.open(logfile, 16000)
|
|
|
|
|
2023-06-01 18:06:39 -06:00
|
|
|
local function reset_network()
|
|
|
|
write_all("/sys/kernel/debug/ieee80211/" .. phy .. "/ath10k/simulate_fw_crash", "hw-restart")
|
|
|
|
end
|
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
function run_monitor_10k()
|
|
|
|
|
|
|
|
local station_count = 0
|
|
|
|
local stations = iwinfo.nl80211.assoclist(wifiiface)
|
|
|
|
for mac, station in pairs(stations)
|
|
|
|
do
|
|
|
|
station_count = station_count + 1
|
|
|
|
end
|
|
|
|
|
2023-06-01 18:06:39 -06:00
|
|
|
if station_count ~= 0 then
|
|
|
|
station_zero = periodic_scan_tick - 1
|
|
|
|
else
|
|
|
|
station_zero = station_zero + 1
|
|
|
|
if math.mod(station_zero, periodic_scan_tick) == 0 then
|
|
|
|
reset_network()
|
|
|
|
log:write("No stations detected")
|
|
|
|
log:flush()
|
|
|
|
end
|
2022-12-22 13:22:49 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return rssi_monitor_10k
|