From 409c6cd7a48f0a105001555208d9235ceb94ccb2 Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Fri, 13 May 2016 18:02:04 +0200 Subject: [PATCH] Added iwx plugin --- iwx/control.zaf | 141 +++++++++ iwx/functions.sh | 151 +++++++++ iwx/template.xml | 792 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1084 insertions(+) create mode 100644 iwx/control.zaf create mode 100644 iwx/functions.sh create mode 100644 iwx/template.xml diff --git a/iwx/control.zaf b/iwx/control.zaf new file mode 100644 index 0000000..3f31585 --- /dev/null +++ b/iwx/control.zaf @@ -0,0 +1,141 @@ +Plugin: iwx + +Description:: + Plugin for wifi mac80211 informations and discovery +:: + +Version: 0.1 +Url: https://raw.githubusercontent.com/limosek/zaf-plugins/master/iwx +Web: https://github.com/limosek/zaf-plugins + +# Dependencies +Depends-dpkg: dash curl +Depens-opkg: busybox curl +Depends-rpm: curl +Depends-bin: curl ps iw + +Sudo: iw + +# Install +Install-bin: functions.sh + +Item if_discovery: +Description:: + Discovery of wireless interfaces +:: +Cmd: wifi_if_discovery +/Item + +Item phy_discovery: +Description:: + Discovery of wireless physical interfaces +:: +Cmd: wifi_phy_discovery +/Item + +Item channels_discovery: +Description:: + Discovery of wireless channels +:: +Parameters: dev +Cmd: wifi_channels_discovery $1 +/Item + +Item clients_discovery: +Description:: + Discovery of wireless clients +:: +Parameters: dev +Cmd: wifi_clients_discovery $1 +/Item + +Item client_signal: +Description:: + Signal level of client +:: +Parameters: dev mac +Cmd: wifi_clients_discovery $1 $2 +/Item + +Item client_rxrate: +Description:: + RX rate of client +:: +Parameters: dev mac +Cmd: wifi_clients_rxrate $1 $2 +/Item + +Item client_txrate: +Description:: + TX rate of client +:: +Parameters: dev mac +Cmd: wifi_clients_txrate $1 $2 +/Item + +Item neigh_ssid: +Description:: + SSID of neighbour +:: +Parameters: dev mac +Cmd: wifi_neigh_ssid $1 $2 +/Item + +Item neigh_signal: +Description:: + Signal level of neighbour +:: +Parameters: dev mac +Cmd: wifi_neigh_signal $1 $2 +/Item + +Item neigh_channel: +Description:: + Channel of neighbour +:: +Parameters: dev mac +Cmd: wifi_neigh_channel $1 $2 +/Item + +Item channel_noise: +Description:: + Noise level on channel +:: +Parameters: dev channel +Cmd: wifi_channel_noise $1 $2 +/Item + +Item channel_activetime: +Description:: + Time spend as active on channel +:: +Parameters: dev channel +Cmd: wifi_channel_activetime $1 $2 +/Item + +Item channel_busytime: +Description:: + Time spend as busy on channel +:: +Parameters: dev channel +Cmd: wifi_channel_busytime $1 $2 +/Item + +Item channel_txtime: +Description:: + Time spend as TX on channel +:: +Parameters: dev channel +Cmd: wifi_channel_transmittime $1 $2 +/Item + +Item channel_rxtime: +Description:: + Time spend as RX on channel +:: +Parameters: dev channel +Cmd: wifi_channel_receivetime $1 $2 +/Item + + + diff --git a/iwx/functions.sh b/iwx/functions.sh new file mode 100644 index 0000000..0699240 --- /dev/null +++ b/iwx/functions.sh @@ -0,0 +1,151 @@ + +wifi_ifphylist_openwrt() { + local devs phys p ifname ifindex i + + json_load "$(ubus -S call network.wireless status)" + json_get_keys phys + for p in $phys; do + if [ "$1" = "phy" ]; then + echo $p + continue + fi + json_select "$p" + json_select "interfaces" + json_get_keys ifindex + for i in $ifindex; do + json_select $i + json_get_var ifname ifname + echo $ifname + json_select .. + done + json_select .. + json_select .. + done +} + +wifi_ifphylist() { + local i + + if [ "$1" = "phy" ]; then + for i in 0 1 2 3 4 5 6; do + if zaf_sudo iw phy phy$i info >/dev/null 2>/dev/null; then + echo phy$i + fi + done + else + for i in 0 1 2 3 4 5 6; do + if zaf_sudo iw dev wlan$i info >/dev/null 2>/dev/null; then + echo wlan$i + fi + done + fi +} + +wifi_iflist(){ + zaf_os_specific wifi_ifphylist || wifi_ifphylist +} + +wifi_phylist(){ + zaf_os_specific wifi_ifphylist phy || wifi_ifphylist phy +} + +wifi_scan_dump(){ + wifi_scan $1 | tr '(' ' ' | \ + awk '/^BSS / { printf "'$1' %s ",$2} /freq:/ { printf "%s ",$2 } /signal:/ { printf "%s ",$2 } /SSID:/ { printf "%s\n",$2 } ' +} + +wifi_scan() { + local key="wifi_scan_dump_$1" + if ! zaf_fromcache "$key"; then + wifi_real_scan "$1" | zaf_tocache_stdin "$key" 300 + fi +} + +wifi_real_scan() { + zaf_sudo iw dev "$1" scan +} + +wifi_channel_dump(){ + wifi_scan "$1" >/dev/null + zaf_sudo iw dev $1 survey dump | tr -s '\t ' | \ + awk '/frequency:/ { printf "'$1' %i ",$2 } /noise:/ {printf "%i ",$2 } /active time:/ {printf "%i ",$4 } /busy time:/ {printf "%i ",$4 } /receive time:/ {printf "%i ",$4 } /transmit time:/ {printf "%i \n",$4 }' +} + +wifi_if_discovery(){ + wifi_iflist | grep '^[a-z].*' | zaf_discovery "{#IF}" +} + +wifi_phy_discovery(){ + wifi_phylist | grep '^[a-z].*' | zaf_discovery "{#DEV}" +} + +wifi_channels_discovery(){ + local devs + [ -n "$1" ] && devs="$1" || devs="$(wifi_iflist)" + for dev in $devs; do wifi_channel_dump $dev 2>/dev/null; done | zaf_discovery "{#DEV}" "{#FREQ}" "{#NOISE}" +} + +wifi_neigh_discovery(){ + local devs + [ -n "$1" ] && devs="$1" || devs="$(wifi_iflist)" + for dev in $devs; do wifi_scan_dump $dev 2>/dev/null; done | zaf_discovery "{#DEV}" "{#BSS}" "{#FREQ}" "{#SIGNAL}" "{#SSID}" +} + +wifi_channel_noise(){ + wifi_channel_dump $1 | grep "^$1 $2" | (read dev freq noise active busy receive transmit; echo $noise) +} + +wifi_channel_activetime(){ + wifi_channel_dump $1 | grep "^$1 $2" | (read dev freq noise active busy receive transmit; echo $active) +} + +wifi_channel_busytime(){ + wifi_channel_dump $1 | grep "^$1 $2" | (read dev freq noise active busy receive transmit; echo $busy) +} + +wifi_channel_receivetime(){ + wifi_channel_dump $1 | grep "^$1 $2" | (read dev freq noise active busy receive transmit; echo $receive) +} + +wifi_channel_transmittime(){ + wifi_channel_dump $1 | grep "^$1 $2" | (read dev freq noise active busy receive transmit; echo $transmit) +} + +wifi_neigh_channel(){ + wifi_scan_dump $1 | grep "^$1 $2" | (read dev bss freq signal ssid; echo $freq) +} + +wifi_neigh_signal(){ + wifi_scan_dump $1 | grep "^$1 $2" | (read dev bss freq signal ssid; echo $signal) +} + +wifi_neigh_ssid(){ + wifi_scan_dump $1 | grep "^$1 $2" | (read dev bss freq signal ssid; echo $ssid) +} + +wifi_clients(){ + zaf_sudo iw dev $1 station dump | grep ^Station | wc -l +} + +wifi_clients_dump(){ + zaf_sudo iw dev $1 station dump | awk '/^Station / { printf "'$1' %s ",$2} /signal:/ { printf "%s ",$2 } /tx bitrate:/ { printf "%s ",$3 } /rx bitrate:/ { printf "%s\n",$3 } ' +} + +wifi_clients_discovery(){ + local devs + [ -n "$1" ] && devs="$1" || devs="$(wifi_iflist)" + for dev in $devs; do wifi_clients_dump $dev 2>/dev/null; done | zaf_discovery "{#DEV}" "{#STATION}" "{#SIGNAL}" "{#TXRATE}" "{#RXRATE}" +} + +wifi_client_signal(){ + wifi_clients_dump $1 | grep "^$1 $2" | (read dev station signal tx rx; echo $signal) +} + +wifi_client_rxrate(){ + wifi_clients_dump $1 | grep "^$1 $2" | (read dev station signal tx rx; echo $rx) +} + +wifi_client_txrate(){ + wifi_clients_dump $1 | grep "^$1 $2" | (read dev station signal tx rx; echo $tx) +} + diff --git a/iwx/template.xml b/iwx/template.xml new file mode 100644 index 0000000..0815ceb --- /dev/null +++ b/iwx/template.xml @@ -0,0 +1,792 @@ + + + 3.0 + 2016-05-13T15:42:32Z + + + Templates + + + + + +