Skip to content
Snippets Groups Projects
Commit 5b77946a authored by Michael Schwarz's avatar Michael Schwarz
Browse files

Don't check current txpower but determine correct txpower step

parent 7c093075
No related branches found
No related tags found
No related merge requests found
...@@ -27,46 +27,33 @@ if not interface24 and uci:get('wireless', 'radio1', 'hwmode') then ...@@ -27,46 +27,33 @@ if not interface24 and uci:get('wireless', 'radio1', 'hwmode') then
interface24 = 'radio1' interface24 = 'radio1'
end end
end end
if not interface24 then
os.exit(0) -- something went wrong
end
--- check if txpower is already set. if so, we have nothing to do --- check if txpower is already set. if so, we have nothing to do
if uci:get('wireless', interface24, 'txpower') then if uci:get('wireless', interface24, 'txpower') then
os.exit(0) os.exit(0)
end end
--- get corresponding wifi interface --- get maximum available power and step
configuredInterface = '' t = cmd('iwinfo ' .. interface24 .. ' txpowerlist | tail -n 1 | awk \'{print $1}\'')
interfaceList = uci:get_all('wireless') maximumTxPowerDb = string.gsub(t, "\n", "")
for interface, value in pairs(interfaceList) do maximumTxPowerDb = tonumber(maximumTxPowerDb)
if uci:get('wireless', interface, 'device') == interface24 and
uci:get('wireless', interface, 'disabled') == '0' then
configuredInterface = uci:get('wireless', interface, 'ifname')
break
end
end
if configuredInterface == '' then
exit(0) -- we didn't find an active wifi interface
end
--- get current txpower if maximumTxPowerDb < 20 then
t = cmd('iwinfo ' .. configuredInterface .. ' info | grep Tx-Power | awk \'{print $2}\'') t = cmd('iwinfo ' .. interface24 .. ' txpowerlist | wc -l')
currentTxPower = string.gsub(t, "\n", "") maximumTxPower = string.gsub(t, "\n", "")
currentTxPower = tonumber(currentTxPower) maximumTxPower = tonumber(maximumTxPower)-1
else
--- get maximum possible Tx-Power t = cmd('iwinfo ' .. interface24 .. ' txpowerlist | grep -n "20 dBm" | cut -f1 -d\':\'')
t = cmd('iwinfo ' .. configuredInterface .. ' txpowerlist | tail -n 1 | sed -e \'s/\\\*//\' | awk \'{print $1}\'') maximumTxPower = string.gsub(t, "\n", "")
maximumTxPower = string.gsub(t, "\n", "") maximumTxPower = tonumber(maximumTxPower)-1
maximumTxPower = tonumber(maximumTxPower)
--- if current and maximum power differs, apply workaround
if maximumTxPower > 20 then
maximumTxPower = 20 -- we are in Germany!
end end
if currentTxPower < maximumTxPower then --- set values
uci:set('wireless', interface24, 'country', '00') uci:set('wireless', interface24, 'country', '00')
uci:set('wireless', interface24, 'txpower', maximumTxPower) uci:set('wireless', interface24, 'txpower', maximumTxPower)
uci:save('wireless') uci:save('wireless')
uci:commit('wireless') uci:commit('wireless')
cmd('wifi')
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment