# manual scanning all channels function read_file(name) local f = io.open(name,"r") local ret = nil if f ~= nil then ret = f:read("*all") f:close() end return ret end function write_file(name, content) local f = io.open(name, "w") local ret = false if f ~= nil then f:write(content) f:close() ret = true end return ret end local function shell(command) local handle = io.popen(command) local result = handle:read("*a") handle:close() return result end local phy = 'phy1' local ath9k_debug = '/sys/kernel/debug/ieee80211/' .. phy .. '/ath9k/' local MANUAL_CMD = 'manual' local BACKGROUND_CMD = 'background' local TRIGGER_CMD = 'trigger' local DISABLE_CMD = 'disable' local ctl_file = ath9k_debug .. 'spectral_scan_ctl' local results_file = ath9k_debug .. 'spectral_scan0' if shell("iw dev | grep Interface | grep monspec") == '' then os.execute("iw phy " .. phy .. " interface add monspec type monitor") os.execute("ifconfig monspec up") end write_file(ath9k_debug .. 'spectral_count', '64') write_file(ath9k_debug .. 'spectral_short_repeat', '1') write_file(ath9k_debug .. 'spectral_period', '50') local freqs = {"5180","5200","5220","5240","5260","5280","5300","5320","5500","5520","5540","5560","5580","5600","5620","5640","5660","5680","5700","5745","5765","5785","5805","5825"} for _, freq in pairs(freqs) do print('freq: ' .. freq) os.execute("iw dev monspec set freq " .. freq) write_file(ctl_file, BACKGROUND_CMD) write_file(ctl_file, TRIGGER_CMD) os.execute("sleep 2") data = read_file(results_file) print(#data) write_file('/tmp/spectral_result_freq' .. freq, data) end write_file(ctl_file, DISABLE_CMD) os.execute("cat /tmp/spectral_result_freq* > /tmp/spectral_result") os.execute("rm /tmp/spectral_result_freq*")