Developing lightweight computation at the DSG edge

Commit 159c3bc6 authored by p4u's avatar p4u
Browse files

Adapt some functions to be compatible for adhoc_ap mode (dont show wlan0ap interfaces and so on)

Improved the chael selection for mode ap and adhoc_ap
Minor chages in the code
parent 499d6803
......@@ -391,17 +391,26 @@ qmp_wifi_get_default() {
# channel AP = ( node_id + index*3 ) % ( num_channels_ap) + 1
# channel is 1, 6 or 11 for coexistence and performance
[ "$mode" = "ap" -o "$mode" = "adhoc_ap" ] && {
c=$(((($(qmp_get_dec_node_id)+$index*3) % $num_channels_ap) +1))
if [ $c -lt 5 ]; then c=1
else if [ $c -lt 9 ]; then c=6
else c=11
fi; fi
#if the resulting channel is used by adhoc, selecting another one
[ -n "$ADHOC_BG_USED" ] && [ $ADHOC_BG_USED -eq $c ] && \
( [ $c -lt 7 ] && c=$(($c+5)) || c=$(($c-5)) )
AP_INDEX=${AP_INDEX:-0}
# if there is only one wifi device, configure a static channel (it will be used as adhoc_ap)
if [ $($QMPINFO devices wifi | wc -l) -eq 1 ]; then
c=1
else
c=$(((($(qmp_get_dec_node_id)+$AP_INDEX*3) % $num_channels_ap) +1))
AP_INDEX=$(($AP_INDEX+1))
if [ $c -lt 5 ]; then c=1
else if [ $c -lt 9 ]; then c=6
else c=11
fi; fi
#if the resulting channel is used by adhoc, selecting another one
[ -n "$ADHOC_BG_USED" ] && [ $ADHOC_BG_USED -eq $c ] && \
( [ $c -lt 7 ] && c=$(($c+5)) || c=$(($c-5)) )
fi
channel_info="$($channels_cmd | awk NR==$c)"
}
......
......@@ -22,27 +22,28 @@
package.path = package.path .. ";/etc/qmp/?.lua"
qmp = require "qmpinfo"
qmpinfo = require "qmpinfo"
function print_help()
print("qMpinfo is a dummy script to get some information about the device")
print("Usage: qmpinfo <question> [options]")
print("Available questions:")
print(" modes <dev> : supported modes by the wireless card")
print(" channels <dev> : supported channels and supported HT40 type (+/-) ")
print(" txpower <dev> : supported transmission powers")
print(" ipv4 : print all ipv4 from this computer (excluding localhost)")
print(" hostname : print device hostname")
print(" bwtest <ipv6> : perform a bandwidth test")
print(" nodes : list all nodes on MESH network")
print(" links : list direct connected nodes on MESH")
print(" version <option> : show version (options: full, build, branch, codename, release, revision)")
print(" key : print qmp key")
print("\nAvailable questions:")
print(" modes <dev> : supported modes by the wireless card")
print(" channels <dev> : supported channels and supported HT40 type (+/-) ")
print(" txpower <dev> : supported transmission powers")
print(" devices [wifi|eth] : print all physical network devices")
print(" ipv4 : print all ipv4 from this computer (excluding localhost)")
print(" hostname : print device hostname")
print(" bwtest <ipv6> : perform a bandwidth test")
print(" nodes : list all nodes on MESH network")
print(" links : list direct connected nodes on MESH")
print(" version <option> : show version (full, build, branch, codename, release, revision)")
print(" key : print qmp key")
print("")
end
function print_modes()
local data = qmp.get_modes(op1)
local data = qmpinfo.get_modes(op1)
local output = ""
if data.b then output = output .. "b " end
if data.g then output = output .. "g " end
......@@ -54,7 +55,7 @@ end
function print_channels()
local partial
local output = ""
local data = qmp.get_channels(op1)
local data = qmpinfo.get_channels(op1)
for _,d in ipairs(data) do
output = d.channel
if d.ht40p then output = output .. " ht40+" end
......@@ -64,22 +65,37 @@ function print_channels()
end
end
function print_devices()
local _,v,devs
if op1 == nil then
devs = qmpinfo.get_devices().all
elseif op1 == "wifi" then
devs = qmpinfo.get_devices().wifi
else
devs = qmpinfo.get_devices().eth
end
for _,v in ipairs(devs) do
print(v)
end
end
function print_txpower()
local data = qmp.get_txpower(op1)
local data = qmpinfo.get_txpower(op1)
for _,v in ipairs(data) do
print(v)
end
end
function print_ipv4()
local ipv4 = qmp.get_ipv4()
local ipv4 = qmpinfo.get_ipv4()
for _,v in pairs(ipv4) do
print(v)
end
end
function print_hostname()
print(qmp.get_hostname())
print(qmpinfo.get_hostname())
end
function bw_test()
......@@ -147,6 +163,8 @@ elseif question == "channels" then
print_channels()
elseif question == "txpower" then
print_txpower()
elseif question == "devices" then
print_devices()
elseif question == "ipv4" then
print_ipv4()
elseif question == "hostname" then
......
......@@ -24,14 +24,44 @@
--]]
iwinfo = require "iwinfo"
util = require "luci.util"
sys = require "luci.sys"
qmpinfo = {}
local iwinfo = require "iwinfo"
local util = require "luci.util"
local sys = require "luci.sys"
local nixio = require "nixio"
local uci = luci.model.uci.cursor()
local qmpinfo = {}
local i,d
-- returns all the physical devices as a table
-- in table.wifi only the wifi ones
-- in table.eth only the non-wifi ones
function qmpinfo.get_devices()
local d
local phydevs = {}
phydevs.wifi = {}
phydevs.all = {}
phydevs.eth = {}
local sysnet = "/sys/class/net/"
for d in nixio.fs.dir(sysnet) do
if nixio.fs.stat(sysnet..d..'/device',"type") ~= nil then
if string.find(d,"%.") == nil and string.find(d,"ap") == nil then
if nixio.fs.stat(sysnet..d..'/phy80211',"type") ~= nil then
table.insert(phydevs.wifi,d)
else
table.insert(phydevs.eth,d)
end
table.insert(phydevs.all,d)
end
end
end
return phydevs
end
-- deprecated
function qmpinfo.get_devices_old()
ethernet_interfaces = { 'eth' }
wireless_interfaces = { 'ath', 'wlan' }
......@@ -203,6 +233,18 @@ function qmpinfo.bandwidth_test(ip)
return result
end
function qmpinfo.get_wifi_index()
local k,v
local windex = {}
for k,v in pairs(uci:get_all("qmp")) do
if v.device ~= nil and v.mac ~= nil then
table.insert(windex,k)
end
end
return windex
end
function qmpinfo.nodes()
local nodes = util.split(util.exec('bmx6 -c --originators | awk \'{print $1 "|" $3}\' | grep -e ".*:.*:"'))
local ni
......
......@@ -18,61 +18,34 @@
The full GNU General Public License is included in this distribution in
the file called "COPYING".
--]]
package.path = package.path .. ";/etc/qmp/?.lua"
qmpinfo = require "qmpinfo"
require("luci.sys")
local http = require "luci.http"
m = Map("qmp", "Quick Mesh Project")
ethernet_interfaces = { 'eth', 'ath', 'wlan' }
wireless_interfaces = { 'ath', 'wlan' }
eth_section = m:section(NamedSection, "interfaces", "qmp", "Interfaces", "Interfaces")
eth_section.addremove = False
--wl_section = m:section(NamedSection, "interfaces", "qmp", "Wireless interfaces", "Wireless devices")
--wl_section.addremove = False
-- Getting the physical (real) interfaces
-- interfaces matching with real_interfaces and without dot
-- ethernet interfaces will be stored in eth_int and wireless in wl_int
eth_int = {}
for i,d in ipairs(luci.sys.net.devices()) do
for i,r in ipairs(ethernet_interfaces) do
if string.find(d,r) ~= nil then
if string.find(d,"%.") == nil then
table.insert(eth_int,d)
end
end
end
end
wl_int = {}
for i,d in ipairs(luci.sys.net.devices()) do
for i,r in ipairs(wireless_interfaces) do
if string.find(d,r) ~= nil then
if string.find(d,"%.") == nil then
table.insert(wl_int,d)
end
end
end
end
net_int = qmpinfo.get_devices().all
-- Option: lan_devices
lan = eth_section:option(MultiValue, "lan_devices", "LAN devices","These devices will be used for end-user connection (DHCP server)")
for i,l in ipairs(eth_int) do
for i,l in ipairs(net_int) do
lan:value(l,l)
end
-- Option wan_device
wan = eth_section:option(MultiValue, "wan_devices", "WAN devices","These devices will be used for internet or any other gateway connection (DHCP client)")
for i,w in ipairs(eth_int) do
for i,w in ipairs(net_int) do
wan:value(w,w)
end
-- Option mesh_devices
mesh = eth_section:option(MultiValue, "mesh_devices", "MESH devices","These devices will be used for Mesh network")
for i,l in ipairs(eth_int) do
for i,l in ipairs(net_int) do
mesh:value(l,l)
end
......
......@@ -22,21 +22,13 @@
require("luci.sys")
local http = require "luci.http"
package.path = package.path .. ";/etc/qmp/?.lua"
qmp = require "qmpinfo"
qmpinfo = require "qmpinfo"
device_names = {"wlan","ath","wifi"}
m = Map("qmp", "Quick Mesh Project")
local uci = luci.model.uci.cursor()
local wdevs = {}
for k,v in pairs(uci:get_all("qmp")) do
for _,n in ipairs(device_names) do
if v.device ~= nil and string.find(v.device,n) then
table.insert(wdevs,k)
end
end
end
local wdevs = qmpinfo.get_wifi_index()
---------------------------
-- Section Wireless Main --
......@@ -95,7 +87,7 @@ for _,wdev in ipairs(wdevs) do
channel = s_wireless:option(ListValue,"channel","Channel",translate("WiFi channel to use in this device.\nSelect +/- for 40MHz channel. Select b for 802.11b only"))
mymode = m.uci:get("qmp",wdev,"mode")
for _,ch in ipairs(qmp.get_channels(mydev)) do
for _,ch in ipairs(qmpinfo.get_channels(mydev)) do
if mymode ~= "adhoc" or ch.adhoc then
channel:value(ch.channel, ch.channel)
if ch.ht40p then channel:value(ch.channel .. '+', ch.channel .. '+') end
......@@ -106,7 +98,7 @@ for _,wdev in ipairs(wdevs) do
-- Txpower
txpower = s_wireless:option(ListValue,"txpower","Power",translate("Choose the transmit power (each 4 number the power is doubled)"))
for _,t in ipairs(qmp.get_txpower(mydev)) do
for _,t in ipairs(qmpinfo.get_txpower(mydev)) do
txpower:value(t,t)
end
end
......
......@@ -119,7 +119,7 @@ local function is_a(dev, what)
return false
end
for i,v in ipairs(devices[1]) do
for i,v in ipairs(devices.eth) do
tmp = m:field(ListValue, "_" .. v, v)
tmp:value("Mesh")
tmp:value("Lan")
......@@ -139,7 +139,7 @@ end
-- Wireless devices
nodedevs_wifi = {}
for i,v in ipairs(devices[2]) do
for i,v in ipairs(devices.wifi) do
tmp = m:field(ListValue, "_" .. v, v)
tmp:value("Mesh")
tmp:value("AP")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment