Minor networking fixes on legacy Kindles (#5059)

* Allow toggling WiFi & Suspend on legacy Kindles
* Fix ping invocations on Legacy Kindles
* Don't crash when disabling WiFi on legacy Kindles
pull/5062/head
NiLuJe 5 years ago committed by GitHub
parent 3798e1b72c
commit 89e002f236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -311,7 +311,13 @@ function Device:retrieveNetworkInfo()
std_out:close() std_out:close()
end end
if os.execute("ip r | grep -q default") == 0 then if os.execute("ip r | grep -q default") == 0 then
local pingok = os.execute("ping -q -w 3 -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null") -- NOTE: No -w flag available in the old busybox build used on Legacy Kindles...
local pingok
if self:isKindle() and self:hasKeyboard() then
pingok = os.execute("ping -q -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null")
else
pingok = os.execute("ping -q -w 3 -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null")
end
if pingok == 0 then if pingok == 0 then
result = result .. "Gateway ping successful" result = result .. "Gateway ping successful"
else else

@ -13,6 +13,11 @@ local function kindleEnableWifi(toggle)
if lipc_handle then if lipc_handle then
lipc_handle:set_int_property("com.lab126.cmd", "wirelessEnable", toggle) lipc_handle:set_int_property("com.lab126.cmd", "wirelessEnable", toggle)
lipc_handle:close() lipc_handle:close()
else
-- No liblipclua on FW < 5.x ;)
-- Always kill 3G first...
os.execute("lipc-set-prop -i com.lab126.wan enable 0")
os.execute("lipc-set-prop -i com.lab126.wifid enable " .. toggle)
end end
end end
@ -27,14 +32,18 @@ local function isWifiUp()
status = lipc_handle:get_int_property("com.lab126.wifid", "enable") or 0 status = lipc_handle:get_int_property("com.lab126.wifid", "enable") or 0
lipc_handle:close() lipc_handle:close()
else else
-- NOTE: Pilfered from Cervantes, c.f., #4380 local std_out = io.popen("lipc-get-prop -i com.lab126.wifid enable", "r")
-- Possibly race-y, if we're extremely unlucky and lipc drops WiFi between our open and our read... if std_out then
-- But then, if we're here, it's because we failed to acquire an lipc handle, local result = std_out:read("*all")
-- so it's likely we've failed to do that earlier when trying to toggle WiFi, too... std_out:close()
local file = io.open("/sys/class/net/wlan0/carrier", "rb") if result then
if not file then return 0 end return tonumber(result)
status = tonumber(file:read("*all")) or 0 else
file:close() return 0
end
else
return 0
end
end end
return status return status
end end

@ -92,6 +92,8 @@ end
function KindlePowerD:toggleSuspend() function KindlePowerD:toggleSuspend()
if self.lipc_handle then if self.lipc_handle then
self.lipc_handle:set_int_property("com.lab126.powerd", "powerButton", 1) self.lipc_handle:set_int_property("com.lab126.powerd", "powerButton", 1)
else
os.execute("powerd_test -p")
end end
end end

@ -102,7 +102,12 @@ function NetworkMgr:isConnected()
return self:isWifiOn() return self:isWifiOn()
else else
-- `-c1` try only once; `-w2` wait 2 seconds -- `-c1` try only once; `-w2` wait 2 seconds
return 0 == os.execute([[ping -c1 -w2 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]]) -- NOTE: No -w flag available in the old busybox build used on Legacy Kindles...
if Device:isKindle() and Device:hasKeyboard() then
return 0 == os.execute([[ping -c1 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]])
else
return 0 == os.execute([[ping -c1 -w2 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]])
end
end end
end end

Loading…
Cancel
Save