Selaa lähdekoodia

Don't check current txpower but determine correct txpower step

Michael Schwarz 8 vuotta sitten
vanhempi
commit
5b77946a02

+ 59 - 0
ffho/ffho-txpower-fix/files/lib/gluon/upgrade/310-ffho-txpower-fix

@@ -0,0 +1,59 @@
+#!/usr/bin/lua
+
+site = require("gluon.site_config")
+uci = require('luci.model.uci').cursor()
+
+--- wrapper for calling systemcommands
+function cmd(_command)
+        local f = io.popen(_command)
+        local l = f:read("*a")
+        f:close()
+        return l
+end
+
+--- first of all, get 2.4GHz wifi interface
+local interface24 = false
+if uci:get('wireless', 'radio0', 'hwmode') then
+	hwmode = uci:get('wireless', 'radio0', 'hwmode')
+	if hwmode == '11g' then
+		interface24 = 'radio0'
+	end
+end
+
+--- try with radio1 if radio0 seems not the correct interface
+if not interface24 and uci:get('wireless', 'radio1', 'hwmode') then
+        hwmode = uci:get('wireless', 'radio1', 'hwmode')
+        if hwmode == '11g' then
+                interface24 = 'radio1'
+        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
+if uci:get('wireless', interface24, 'txpower') then
+	os.exit(0)
+end
+
+--- get maximum available power and step
+t = cmd('iwinfo ' .. interface24 .. ' txpowerlist | tail -n 1 | awk \'{print $1}\'')
+maximumTxPowerDb = string.gsub(t, "\n", "")
+maximumTxPowerDb = tonumber(maximumTxPowerDb)
+
+if maximumTxPowerDb < 20 then
+	t = cmd('iwinfo ' .. interface24 .. ' txpowerlist | wc -l')
+	maximumTxPower = string.gsub(t, "\n", "")
+	maximumTxPower = tonumber(maximumTxPower)-1
+else
+	t = cmd('iwinfo ' .. interface24 .. ' txpowerlist | grep -n "20 dBm" | cut -f1 -d\':\'')
+        maximumTxPower = string.gsub(t, "\n", "")
+        maximumTxPower = tonumber(maximumTxPower)-1
+end
+
+--- set values
+uci:set('wireless', interface24, 'country', '00')
+uci:set('wireless', interface24, 'txpower', maximumTxPower)
+uci:save('wireless')
+uci:commit('wireless')
+

+ 0 - 72
ffho/ffho-txpower-fix/files/lib/gluon/upgrade/600-ffho-txpower-fix

@@ -1,72 +0,0 @@
-#!/usr/bin/lua
-
-site = require("gluon.site_config")
-uci = require('luci.model.uci').cursor()
-
---- wrapper for calling systemcommands
-function cmd(_command)
-        local f = io.popen(_command)
-        local l = f:read("*a")
-        f:close()
-        return l
-end
-
---- first of all, get 2.4GHz wifi interface
-local interface24 = false
-if uci:get('wireless', 'radio0', 'hwmode') then
-	hwmode = uci:get('wireless', 'radio0', 'hwmode')
-	if hwmode == '11g' then
-		interface24 = 'radio0'
-	end
-end
-
---- try with radio1 if radio0 seems not the correct interface
-if not interface24 and uci:get('wireless', 'radio1', 'hwmode') then
-        hwmode = uci:get('wireless', 'radio1', 'hwmode')
-        if hwmode == '11g' then
-                interface24 = 'radio1'
-        end
-end
-
---- check if txpower is already set. if so, we have nothing to do
-if uci:get('wireless', interface24, 'txpower') then
-	os.exit(0)
-end
-
---- get corresponding wifi interface
-configuredInterface = ''
-interfaceList = uci:get_all('wireless')
-for interface, value in pairs(interfaceList) do
-	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
-t = cmd('iwinfo ' .. configuredInterface .. ' info | grep Tx-Power | awk \'{print $2}\'')
-currentTxPower = string.gsub(t, "\n", "")
-currentTxPower = tonumber(currentTxPower)
-
---- get maximum possible Tx-Power
-t = cmd('iwinfo ' .. configuredInterface .. ' txpowerlist | tail -n 1 | sed -e \'s/\\\*//\' | awk \'{print $1}\'')
-maximumTxPower = string.gsub(t, "\n", "")
-maximumTxPower = tonumber(maximumTxPower)
-
---- if current and maximum power differs, apply workaround
-if maximumTxPower > 20 then
-	maximumTxPower = 20 -- we are in Germany!
-end
-
-if currentTxPower < maximumTxPower then
-	uci:set('wireless', interface24, 'country', '00')
-	uci:set('wireless', interface24, 'txpower', maximumTxPower)
-	uci:save('wireless')
-	uci:commit('wireless')
-	cmd('wifi')
-end
-