From patchwork Tue Oct 11 11:37:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 680711 X-Patchwork-Delegate: openwrt@kresin.me Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3stZmM13QXz9rxl for ; Tue, 11 Oct 2016 22:40:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.b=YPvs6zLm; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1btvNu-0003o3-KW; Tue, 11 Oct 2016 11:38:14 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1btvNm-0003hz-Ms for lede-dev@lists.infradead.org; Tue, 11 Oct 2016 11:38:09 +0000 Received: by mail-lf0-x241.google.com with SMTP id x79so3255479lff.2 for ; Tue, 11 Oct 2016 04:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8ODkjiMf+XXJYPcBtY9QiiIBKcwWxt5bg8LdtET1b3w=; b=YPvs6zLmxodXepGbrCOYO6rLLXVTUY81xS7BF1U34XuQJs3aHuV3vqvUnyKuCRzVrx F3LN2bQVBRqmWjgSaWBEscDc4YfeidrETmwiIuTcSYRIkeC8VgvoKHlqwY0gUXqz7Zre JnRLOOamh3631+lZia0r2o6ZjWXPyfFh3x7aGvlBuPkkln0F3+pBIgrF313ujrj6e0Tp jzwT+MbEd6VvRCkqLyJfgEl5T5NrGgRb7FlMrtCb+xsU6kqNM0L0FYWT6A5iEMlIWz/C zl7TMFYZi1EP8RZTjiIxxN/Hs9umQv5xVgi5DmkDskX/KOPIJaBeSNmiJF2PwLaoCvoC 8lfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8ODkjiMf+XXJYPcBtY9QiiIBKcwWxt5bg8LdtET1b3w=; b=PwYpqHoUvnltQH0LDy0PYELLWtVljAaeXY2Zffj3ceenHIq8T231lVck4H6nElP8E1 pAAH/iOlY+/1M/QodNufSnTh50UFGbWew4ktiNms0U2YIqtAANxfrDiN2PHeEvW7lLiR uCoxm2KROSg+rtHRaF7ZpiJECf/whNpEoyOGzblJlJFVjBldyteiJdnRZlRUG3Lj5I3N Jb9x4PHpWT82S5iWEy3apkWYR90bd3m7WhHy9zoJnPq+/hc5GDgMiU1m2f+09C2TUvcw L8Z7Q+xNh0gFjDxbueFdmdGe0VM3FhR08stytQUwfDjUJKSreKoebyLG+sdVHw7yPHqR 0OhA== X-Gm-Message-State: AA6/9Rkj1MHSnFyBXajX2cQJoQI7ZvQ0tbC7b3sELJMQ6NjPfRzlxbdCKmZ6QHbhlhSShw== X-Received: by 10.194.105.41 with SMTP id gj9mr2616182wjb.58.1476185864563; Tue, 11 Oct 2016 04:37:44 -0700 (PDT) Received: from debian64.daheim (p5B2E769C.dip0.t-ipconnect.de. [91.46.118.156]) by smtp.gmail.com with ESMTPSA id qq7sm5671767wjc.30.2016.10.11.04.37.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Oct 2016 04:37:41 -0700 (PDT) From: Christian Lamparter X-Google-Original-From: Christian Lamparter Received: from chuck by debian64.daheim with local (Exim 4.87) (envelope-from ) id 1btvNM-0007Oq-E6; Tue, 11 Oct 2016 13:37:40 +0200 To: lede-dev@lists.infradead.org Date: Tue, 11 Oct 2016 13:37:39 +0200 Message-Id: <20161011113740.28392-4-chunkeey@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161011113740.28392-1-chunkeey@gmail.com> References: <20161011113740.28392-1-chunkeey@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161011_043807_011511_2ABFC6B6 X-CRM114-Status: GOOD ( 16.94 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (chunkeey[at]googlemail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [LEDE-DEV] [PATCH v2 4/5] base-files, mac80211, broadcom-wl: plug-and-play wifi detection X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , Jo-Philipp Wich , Matthias Schiffer , Mathias Kresin MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, the wifi detection script is executed as part of the (early) boot process. Pluggable wifi USB devices, which are inserted at a later time are not automatically detected and therefore they don't show up in LuCI. A user has to deal with wifi detection manually, or restart the router. However, the current "sleep 1" window - which the boot process waits for wifi devices to "settle down" - is too short to detect wifi devices for some routers anyway. For example, this can happen with USB WLAN devices on the WNDR4700. This is because the usb controller needs to load its firmware from UBI and initialize, before it can operate. The issue can be seen on a BT HomeHub 5A as well as soon as the caldata are on an ubi volume. This is because the ath9k card has to be initialized by owl-loader first. Which has to wait for the firmware extraction script to retrieve the pci initialization values inside the caldata. This patch moves the wifi detection to hotplug scripts. For mac80211, the wifi detection will now automatically run any time a "ieee80211" device is added. Likewise broadcom-wl's script checks for new "net" devices which have the "wl$NUMBERS" moniker. File locking has been added to the detection scripts in order to prevent races during discovery. The locking code will protect against adding more open wireless network configurations. In case "wifi detect" is run manually by the user at a bad time. All changes to base-files, mac80211 and broadcom-wl packages have been integrated into a single patch to play nice with git bisect. Thanks to Martin Blumenstingl for helping with the implementation and testing of the patch. Acked-by: Jo-Philipp Wich Signed-off-by: Mathias Kresin Signed-off-by: Christian Lamparter --- v1 -> v2: - filter for broadcom devices (Mathias) - integrate uci changes (no more /tmp/wireless.tmp) - move locking to detect_mac80211 and detect_broadcom --- --- package/base-files/files/etc/init.d/boot | 9 --------- .../broadcom-wl/files/etc/hotplug.d/net/00-broadcom-wifi-detect | 5 +++++ package/kernel/broadcom-wl/files/lib/wifi/broadcom.sh | 6 ++++++ package/kernel/mac80211/Makefile | 2 ++ package/kernel/mac80211/files/lib/wifi/mac80211.sh | 7 +++++++ package/kernel/mac80211/files/mac80211.hotplug | 5 +++++ 6 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 package/kernel/broadcom-wl/files/etc/hotplug.d/net/00-broadcom-wifi-detect create mode 100644 package/kernel/mac80211/files/mac80211.hotplug diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index 904f7db..1d61f2f 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -38,15 +38,6 @@ boot() { /sbin/kmodloader - # allow wifi modules time to settle - sleep 1 - - /sbin/wifi detect > /tmp/wireless.tmp - [ -s /tmp/wireless.tmp ] && { - cat /tmp/wireless.tmp >> /etc/config/wireless - } - rm -f /tmp/wireless.tmp - /bin/config_generate uci_apply_defaults diff --git a/package/kernel/broadcom-wl/files/etc/hotplug.d/net/00-broadcom-wifi-detect b/package/kernel/broadcom-wl/files/etc/hotplug.d/net/00-broadcom-wifi-detect new file mode 100644 index 0000000..6ced270 --- /dev/null +++ b/package/kernel/broadcom-wl/files/etc/hotplug.d/net/00-broadcom-wifi-detect @@ -0,0 +1,5 @@ +#!/bin/sh + +[ "${ACTION}" = "add" ] && [ "${INTERFACE%%[0-9]*}" = "wl" ] { + /sbin/wifi detect +} diff --git a/package/kernel/broadcom-wl/files/lib/wifi/broadcom.sh b/package/kernel/broadcom-wl/files/lib/wifi/broadcom.sh index 1881b46..264e01b 100644 --- a/package/kernel/broadcom-wl/files/lib/wifi/broadcom.sh +++ b/package/kernel/broadcom-wl/files/lib/wifi/broadcom.sh @@ -446,10 +446,16 @@ EOF eval "$nas_cmd" } +detect_unlock_broadcom_trap() { + lock -u /var/lock/wifi-detect-broadcom.lock +} detect_broadcom() { local i=-1 + trap detect_unlock_broadcom_trap EXIT + lock /var/lock/wifi-detect-broadcom.lock + while grep -qs "^ *wl$((++i)):" /proc/net/dev; do local channel type diff --git a/package/kernel/mac80211/Makefile b/package/kernel/mac80211/Makefile index 91c9362..f320326 100644 --- a/package/kernel/mac80211/Makefile +++ b/package/kernel/mac80211/Makefile @@ -1732,6 +1732,8 @@ define KernelPackage/cfg80211/install $(INSTALL_DIR) $(1)/lib/wifi $(1)/lib/netifd/wireless $(INSTALL_DATA) ./files/lib/wifi/mac80211.sh $(1)/lib/wifi $(INSTALL_BIN) ./files/lib/netifd/wireless/mac80211.sh $(1)/lib/netifd/wireless + $(INSTALL_DIR) $(1)/etc/hotplug.d/ieee80211 + $(INSTALL_DATA) ./files/mac80211.hotplug $(1)/etc/hotplug.d/ieee80211/00-wifi-detect endef define KernelPackage/ipw2100/install diff --git a/package/kernel/mac80211/files/lib/wifi/mac80211.sh b/package/kernel/mac80211/files/lib/wifi/mac80211.sh index 253de40..44ba511 100644 --- a/package/kernel/mac80211/files/lib/wifi/mac80211.sh +++ b/package/kernel/mac80211/files/lib/wifi/mac80211.sh @@ -58,7 +58,14 @@ check_mac80211_device() { [ "$phy" = "$dev" ] && found=1 } +detect_mac80211_unlock_trap() { + lock -u /var/lock/wifi-detect-mac80211.lock +} + detect_mac80211() { + trap detect_mac80211_unlock_trap EXIT + lock /var/lock/wifi-detect-mac80211.lock + devidx=0 config_load wireless while :; do diff --git a/package/kernel/mac80211/files/mac80211.hotplug b/package/kernel/mac80211/files/mac80211.hotplug new file mode 100644 index 0000000..581be3d --- /dev/null +++ b/package/kernel/mac80211/files/mac80211.hotplug @@ -0,0 +1,5 @@ +#!/bin/sh + +[ "${ACTION}" = "add" ] && { + /sbin/wifi detect +}