| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
m> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
local type = type |
| 24 |
local tonumber = tonumber |
| 25 |
|
| 26 |
local helpers = require("vicious.helpers") |
| 27 |
local spawn = require("vicious.spawn") |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
local wifiiw_linux = {} |
| 34 |
|
| 35 |
local LINK = "PATH=$PATH:/sbin/:/usr/sbin:/usr/local/sbin iw dev %s link" |
| 36 |
local INFO = "PATH=$PATH:/sbin/:/usr/sbin:/usr/local/sbin iw dev %s info" |
| 37 |
|
| 38 |
|
| 39 |
function wifiiw_linux.async(format, warg, callback) |
| 40 |
if type(warg) ~= "string" then return callback{} end |
| 41 |
local winfo = {} |
| 42 |
|
| 43 |
local function parse_link(stdout) |
| 44 |
winfo["{bssid}"] = stdout:match"Connected to ([%x:]*)" or "N/A" |
| 45 |
winfo["{ssid}"] = stdout:match"SSID: ([^\n]*)" or "N/A" |
| 46 |
winfo["{freq}"] = tonumber(stdout:match"freq: (%d+)" or 0) |
| 47 |
winfo["{sign}"] = |
| 48 |
tonumber(stdout:match"signal: (%-?%d+)" or 0) |
| 49 |
winfo["{linp}"] = |
| 50 |
winfo["{sign}"] ~= 0 and 200 + winfo["{sign}"]*2 or 0 |
| 51 |
winfo["{rate}"] = |
| 52 |
tonumber(stdout:match"tx bitrate: ([%d%.]+)" or 0) |
| 53 |
end |
| 54 |
|
| 55 |
local function parse_info(stdout) |
| 56 |
winfo["{mode}"] = stdout:match"type ([^\n]*)" or "N/A" |
| 57 |
winfo["{chan}"] = tonumber(stdout:match"channel (%d+)" or 0) |
| 58 |
|
| 59 |
winfo["{txpw}"] = tonumber(stdout:match"txpower (%-?%d+)" or 0) |
| 60 |
end |
| 61 |
|
| 62 |
spawn.easy_async_with_shell( |
| 63 |
LINK:format(warg), |
| 64 |
function (std_out, std_err, exit_reason, exit_code) |
| 65 |
parse_link(std_out) |
| 66 |
spawn.easy_async_with_shell( |
| 67 |
INFO:format(warg), |
| 68 |
function (stdout, stderr, exitreason, exitcode) |
| 69 |
parse_info(stdout) |
| 70 |
callback(winfo) |
| 71 |
end) |
| 72 |
end) |
| 73 |
end |
| 74 |
|
| 75 |
|
| 76 |
return helpers.setasyncall(wifiiw_linux) |