2016-10-22 23:19:00 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2016, Marius M. <mellich@gmx.net>
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2019-05-29 16:45:28 +02:00
|
|
|
local type = type
|
2016-10-22 23:19:00 +02:00
|
|
|
local tonumber = tonumber
|
2019-05-29 16:45:28 +02:00
|
|
|
|
2016-10-22 23:19:00 +02:00
|
|
|
local helpers = require("vicious.helpers")
|
2019-05-29 16:45:28 +02:00
|
|
|
local spawn = require("vicious.spawn")
|
2016-10-22 23:19:00 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
-- Wifiiw: provides wireless information for a requested interface
|
|
|
|
-- using iw instead of deprecated iwconfig
|
2016-10-22 23:19:00 +02:00
|
|
|
-- vicious.widgets.wifiiw
|
2017-01-25 17:56:50 +01:00
|
|
|
local wifiiw_linux = {}
|
2016-10-22 23:19:00 +02:00
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
local LINK = "PATH=$PATH:/sbin/:/usr/sbin:/usr/local/sbin iw dev %s link"
|
|
|
|
local INFO = "PATH=$PATH:/sbin/:/usr/sbin:/usr/local/sbin iw dev %s info"
|
2016-10-22 23:19:00 +02:00
|
|
|
|
|
|
|
-- {{{ Wireless widget type
|
2019-05-29 16:45:28 +02:00
|
|
|
function wifiiw_linux.async(format, warg, callback)
|
|
|
|
if type(warg) ~= "string" then return callback{} end
|
2016-10-22 23:19:00 +02:00
|
|
|
local winfo = {}
|
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
local function parse_link(stdout)
|
2019-07-18 20:34:42 +02:00
|
|
|
winfo["{bssid}"] = stdout:match"Connected to ([%x:]*)" or "N/A"
|
2019-05-29 16:45:28 +02:00
|
|
|
winfo["{ssid}"] = stdout:match"SSID: ([^\n]*)" or "N/A"
|
|
|
|
winfo["{freq}"] = tonumber(stdout:match"freq: (%d+)" or 0)
|
|
|
|
winfo["{sign}"] = -- Signal level can be negative; w/o unit (dBm)
|
|
|
|
tonumber(stdout:match"signal: (%-?%d+)" or 0)
|
|
|
|
winfo["{linp}"] = -- Link Quality (-100dBm->0%, -50dBm->100%)
|
|
|
|
winfo["{sign}"] ~= 0 and 200 + winfo["{sign}"]*2 or 0
|
|
|
|
winfo["{rate}"] = -- Transmission rate, without unit (Mb/s)
|
|
|
|
tonumber(stdout:match"tx bitrate: ([%d%.]+)" or 0)
|
|
|
|
end
|
2016-10-22 23:19:00 +02:00
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
local function parse_info(stdout)
|
|
|
|
winfo["{mode}"] = stdout:match"type ([^\n]*)" or "N/A"
|
|
|
|
winfo["{chan}"] = tonumber(stdout:match"channel (%d+)" or 0)
|
|
|
|
-- Transmission power, without unit (dBm)
|
|
|
|
winfo["{txpw}"] = tonumber(stdout:match"txpower (%-?%d+)" or 0)
|
2016-10-22 23:19:00 +02:00
|
|
|
end
|
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
spawn.easy_async_with_shell(
|
|
|
|
LINK:format(warg),
|
2019-08-23 17:50:13 +02:00
|
|
|
function (std_out, std_err, exit_reason, exit_code)
|
|
|
|
parse_link(std_out)
|
2019-05-29 16:45:28 +02:00
|
|
|
spawn.easy_async_with_shell(
|
|
|
|
INFO:format(warg),
|
|
|
|
function (stdout, stderr, exitreason, exitcode)
|
|
|
|
parse_info(stdout)
|
|
|
|
callback(winfo)
|
|
|
|
end)
|
|
|
|
end)
|
2016-10-22 23:19:00 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
return helpers.setasyncall(wifiiw_linux)
|