Browse Source

ffho-ath9k-blackout-workaround: new package

Karsten Böddeker 7 years ago
parent
commit
360768aa10

+ 22 - 0
ffho/ffho-ath9k-blackout-workaround/LICENSE

@@ -0,0 +1,22 @@
+Copyright (c) 2016, Karsten Böddeker <freifunk@kb-light.de>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+  1. Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 43 - 0
ffho/ffho-ath9k-blackout-workaround/Makefile

@@ -0,0 +1,43 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ffho-ath9k-blackout-workaround
+PKG_VERSION:=1
+PKG_RELEASE:=$(GLUON_VERSION).$(GLUON_SITE_CODE)-$(GLUON_RELEASE).$(GLUON_CONFIG_VERSION)
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ffho-ath9k-blackout-workaround
+  SECTION:=ffho
+  CATEGORY:=Workarounds
+  TITLE:=ATH9K-Blackout workaround
+  DEPENDS:=+gluon-core +micrond
+  MAINTAINER:=Freifunk Hochstift <kontakt@hochstift.freifunk.net>
+  URL:=https://git.c3pb.de/freifunk-pb/ffho-packages
+endef
+
+define Package/ffho-ath9k-blackout-workaround/description
+	Restartes the wifi if possible blckout is detected.
+endef
+
+define Build/Prepare
+	mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/ffho-ath9k-blackout-workaround/install
+	$(CP) ./files/* $(1)/
+endef
+
+define Package/ffho-ath9k-blackout-workaround/postinst
+#!/bin/sh
+$(call GluonCheckSite,check_site.lua)
+endef
+
+$(eval $(call BuildPackage,ffho-ath9k-blackout-workaround))

+ 29 - 0
ffho/ffho-ath9k-blackout-workaround/ReadMe.md

@@ -0,0 +1,29 @@
+ffho-ath9k-blackout-workaround
+==============================
+
+In order to avoid further WiFi-Blackouts that *might* be caused by buggy ath9k,
+we try to detect problems and restart the wifi.
+
+site.conf
+---------
+
+**ath9k-workaround.blackout_wait:**
+- minimum delay to detect a possible blackout as blackout
+
+**ath9k-workaround.reset_wait:**
+- minimum delay between reset
+
+**ath9k-workaround.step_size**
+- execute the cronjob each x minutes
+
+### example
+```lua
+{
+  ath9k-workaround = {
+    blackout_wait = 720,
+    reset_wait = 1440,
+    step_size = 10,
+  },
+  ...
+},
+```

+ 3 - 0
ffho/ffho-ath9k-blackout-workaround/check_site.lua

@@ -0,0 +1,3 @@
+need_number('ath9k_workaround.blackout_wait')
+need_number('ath9k_workaround.reset_wait')
+need_number('ath9k_workaround.step_size')

+ 15 - 0
ffho/ffho-ath9k-blackout-workaround/files/etc/hotplug.d/iface/90-ath9k-blackout-workaround

@@ -0,0 +1,15 @@
+#!/bin/sh
+[[ "${ACTION}" != "ifup" ]] && exit 0;
+
+. /lib/functions.sh
+config_load "wireless"
+
+local RADIO
+config_get RADIO ${INTERFACE} device
+[[ -z ${RADIO} ]] && exit 0;
+
+local HWMODE
+config_get HWMODE ${RADIO} hwmode
+[[ "${HWMODE}" != "11g" ]] && exit 0;
+
+date +%s > /tmp/ath9k-reset

+ 10 - 0
ffho/ffho-ath9k-blackout-workaround/files/lib/gluon/upgrade/900-ath9k-blackout-workaround

@@ -0,0 +1,10 @@
+#!/usr/bin/lua
+
+local fs = require 'nixio.fs'
+local site = require 'gluon.site_config'
+
+local step_size = site.ath9k-workaround.step_size
+
+local f = io.open('/usr/lib/micron.d/ath9k-blackout-workaround', 'w')
+f:write(string.format('*/%i * * * * /usr/sbin/ath9k-blackout-workaround\n', step_size))
+f:close()

+ 74 - 0
ffho/ffho-ath9k-blackout-workaround/files/usr/sbin/ath9k-blackout-workaround

@@ -0,0 +1,74 @@
+#!/usr/bin/lua
+local fs = require('nixio.fs')
+local uci = require('luci.model.uci').cursor()
+local iwinfo = require "iwinfo"
+local site = require 'gluon.site_config'
+
+local fileOk="/tmp/ath9k-ok"
+local fileReset="/tmp/ath9k-reset"
+
+function time2file (file)
+  local f = io.open(file, 'w')
+  f:write(string.format('%i', os.time()))
+  f:close()
+end
+
+function devOk (iface)
+  local data = uci:get_all('wireless', iface)
+  if data.disabled then
+    return null
+  end
+  local radio = uci:get_all('wireless', data.radio)
+  if not radio.hwmode == '11g' or radio.disabled then
+    return null
+  end
+  local wifitype = iwinfo.type(data.radio)
+  local iw = iwinfo[wifitype]
+  if iw.assoclist(iface) then
+    return true
+  end
+  return false
+end
+
+function check_wifi()
+  local ifaces = {}
+  uci:foreach('wireless', 'wifi-iface',
+    function(s)
+      table.insert(ifaces, s['.name'])
+    end
+  )
+  local blackout = false
+  for _, iface in ipairs(ifaces) do
+    local tmp = devOk(iface)
+    if tmp then
+      return true
+    elseif tmp == false then
+      blackout = true
+    end
+  end
+  return not blackout
+end
+
+if not fs.readfile(fileReset) then
+  time2file(fileReset)
+end
+
+if check_wifi() or not fs.readfile(fileOk) then 
+  time2file(fileOk)
+  os.exit(0)                             
+end
+
+local blackout_wait_secs = site.ath9k-workaround.blackout_wait *60
+local reset_wait_secs = site.ath9k-workaround.reset_wait *60
+
+if os.difftime(os.time(), tonumber(fs.readfile(fileReset))) <= reset_wait_secs then
+  os.exit(0)
+end
+
+if os.difftime(os.time(), tonumber(fs.readfile(fileOk))) <= blackout_wait_secs then
+  os.exit(0)
+end
+
+io.popen('logger -s -t ath9k-blackout-workaround -p local0.info "blackout detected, resart wifi"')
+time2file(fileReset)
+os.execute("wifi")