From 4e1a4978cc86b35fa291e8da26c5a6598d023074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fdez?= Date: Sat, 10 Nov 2018 13:13:57 +0100 Subject: [PATCH] wireless: read wireless carrier from sysfs --- frontend/device/cervantes/device.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/device/cervantes/device.lua b/frontend/device/cervantes/device.lua index e25b2ba37..eabf004e7 100644 --- a/frontend/device/cervantes/device.lua +++ b/frontend/device/cervantes/device.lua @@ -13,6 +13,14 @@ local function getProductId() return product_id end +local function isConnected() + local file = io.open("/sys/class/net/eth0/carrier", "rb") + if not file then return 0 end + local carrier = tonumber(file:read("*all")) or 0 + file:close() + return carrier +end + local Cervantes = Generic:new{ model = "Cervantes", isCervantes = yes, @@ -142,6 +150,7 @@ end function Cervantes:initNetworkManager(NetworkMgr) function NetworkMgr:turnOffWifi(complete_callback) logger.info("Cervantes: disabling WiFi") + self:releaseIP() os.execute("./disable-wifi.sh") if complete_callback then complete_callback() @@ -163,7 +172,7 @@ function Cervantes:initNetworkManager(NetworkMgr) os.execute("./restore-wifi-async.sh") end function NetworkMgr:isWifiOn() - return 0 == os.execute("lsmod | grep -q 8189fs") + return 1 == isConnected() end end