Skip to content

Commit

Permalink
Fix wifi mode manual
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Aug 7, 2016
1 parent 13d2f62 commit ca5e7e4
Showing 1 changed file with 53 additions and 62 deletions.
115 changes: 53 additions & 62 deletions packages/lime-system/files/usr/lib/lua/lime/wireless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,85 +80,76 @@ end
function wireless.configure()
local specificRadios = {}
config.foreach("wifi", function(radio) specificRadios[radio[".name"]] = radio end)
local uci = libuci:cursor()

local allRadios = wireless.scandevices()
for _,radio in pairs(allRadios) do
local radioName = radio[".name"]
local phyIndex = radioName:match("%d+")
if wireless.is5Ghz(radioName) then
freqSuffix = "_5ghz"
ignoredSuffix = "_2ghz"
else
freqSuffix = "_2ghz"
ignoredSuffix = "_5ghz"
end
local specRadio = specificRadios[radioName]
local modes = config.get("wifi", "modes")
local options = config.get_all("wifi")

local specRadio = specificRadios[radioName]
if specRadio then
modes = specRadio["modes"]
options = specRadio
end

--! If manual mode is used toghether with other modes it results in an
--! unpredictable behaviour
if modes[1] ~= "manual" then
local freqSuffix = "_2ghz"
local ignoredSuffix = "_5ghz"
if wireless.is5Ghz(radioName) then
freqSuffix = "_5ghz"
ignoredSuffix = "_2ghz"
end

local uci = libuci:cursor()
local distance = options["distance"..freqSuffix]
if not distance then
distance = 10000 -- up to 10km links by default
end
uci:set("wireless", radioName, "disabled", 0)
uci:set("wireless", radioName, "distance", distance)
uci:set("wireless", radioName, "noscan", 1)
uci:set("wireless", radioName, "channel", options["channel"..freqSuffix])

local country = options["country"]
if country then
uci:set("wireless", radioName, "country", country)
end

local htmode = options["htmode"..freqSuffix]
if htmode then
uci:set("wireless", radioName, "htmode", htmode)
end

uci:save("wireless")

for _,modeArgs in pairs(modes) do
local args = utils.split(modeArgs, wireless.modeParamsSeparator)
local modeName = args[1]

if modeName == "manual" then break end

local mode = require("lime.mode."..modeName)
local wirelessInterfaceName = mode.setup_radio(radio, args)[".name"]

local uci = libuci:cursor()

for key,value in pairs(options) do
local keyPrefix = utils.split(key, "_")[1]
local isGoodOption = ( (key ~= "modes")
and (not key:match("^%."))
and (not key:match("channel"))
and (not key:match("country"))
and (not key:match("htmode"))
and (not (wireless.isMode(keyPrefix) and keyPrefix ~= modeName))
and (not key:match(ignoredSuffix)) )

if isGoodOption then
local nk = key:gsub("^"..modeName.."_", ""):gsub(freqSuffix.."$", "")
if nk == "ssid" then
value = utils.applyHostnameTemplate(value)
value = utils.applyMacTemplate16(value, network.primary_mac())
value = string.sub(value, 1, 32)
--! up to 10km links by default
local distance = options["distance"..freqSuffix] or options["distance"] or 10000
local htmode = options["htmode"..freqSuffix] or options["htmode"]

uci:set("wireless", radioName, "disabled", 0)
uci:set("wireless", radioName, "distance", distance)
uci:set("wireless", radioName, "noscan", 1)
uci:set("wireless", radioName, "channel", options["channel"..freqSuffix])
if options["country"] then uci:set("wireless", radioName, "country", options["country"]) end
if htmode then uci:set("wireless", radioName, "htmode", htmode) end

for _,modeArgs in pairs(modes) do
local args = utils.split(modeArgs, wireless.modeParamsSeparator)
local modeName = args[1]

local mode = require("lime.mode."..modeName)
local wirelessInterfaceName = mode.setup_radio(radio, args)[".name"]

local uci = libuci:cursor()

for key,value in pairs(options) do
local keyPrefix = utils.split(key, "_")[1]
local isGoodOption = ( (key ~= "modes")
and (not key:match("^%."))
and (not key:match("channel"))
and (not key:match("country"))
and (not key:match("htmode"))
and (not (wireless.isMode(keyPrefix) and keyPrefix ~= modeName))
and (not key:match(ignoredSuffix)) )

if isGoodOption then
local nk = key:gsub("^"..modeName.."_", ""):gsub(freqSuffix.."$", "")
if nk == "ssid" then
value = utils.applyHostnameTemplate(value)
value = utils.applyMacTemplate16(value, network.primary_mac())
value = string.sub(value, 1, 32)
end

uci:set("wireless", wirelessInterfaceName, nk, value)
end

uci:set("wireless", wirelessInterfaceName, nk, value)
end
end

uci:save("wireless")
end
end

uci:save("wireless")
end

return wireless

0 comments on commit ca5e7e4

Please sign in to comment.