[LEDE-DEV] [PATCH v2 4/5] base-files, mac80211, broadcom-wl: plug-and-play wifi detection

Christian Lamparter chunkeey at googlemail.com
Tue Oct 11 04:37:39 PDT 2016


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 <jo at mein.io>
Signed-off-by: Mathias Kresin <dev at kresin.me>
Signed-off-by: Christian Lamparter <chunkeey at gmail.com>

---
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
+}
-- 
2.9.3




More information about the Lede-dev mailing list