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

Christian Lamparter chunkeey at googlemail.com
Wed Oct 12 11:13:22 PDT 2016


Hello,

On Wednesday, October 12, 2016 1:32:38 PM CEST Jonas Gorski wrote:
> On 11 October 2016 at 13:37, Christian Lamparter
> <chunkeey at googlemail.com> wrote:
> > 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.
> 
> Funny enough I did something similar recently, but didn't submit it
> here yet because there is some ugliness. A few comments ...

Actually, I know that more people have tried this before and posted
different versions and patches to the MLs. So chances are there will
be more attempts after this one.

[...]
> > 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
> 
> Don't you also need to update /etc/hotplug.json to pass through
> ieee80211 events?
No need for that. It's already handled there by [0].

  64                 [ "if",
  65                         [ "isdir", "/etc/hotplug.d/%SUBSYSTEM%" ],
  66                         [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ]
  67                 ]

If the /etc/hotplug.d/ieee80211 directory exits, hotplug-call will
look for scripts in the directory and execute them.
 
> > +       $(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
> 
> You need to fork here, else you will get a deadlock with wifi drivers
> that request firmware on interface up instead of probe time, e.g.
> rt2x00-usb.
Are you sure that the detect_mac80211 and friends actually do bring up
the interfaces? From what I can tell, it's just iw phy info and a bit
of readlink [1].

Still, I can add a "/sbin/wifi config &" there.

Regards,
Christian

[0] <https://git.lede-project.org/?p=source.git;a=blob;f=package/system/procd/files/hotplug.json;h=e5f8d967e8c16c8dc85a437a5259c0ba840d766c;hb=HEAD#l64>

[1] <https://git.lede-project.org/?p=source.git;a=blob;f=package/kernel/mac80211/files/lib/wifi/mac80211.sh;h=9b15de55a8986fa9d354ccb5c92d65edf2b4f514;hb=8869dd47ca8ca70213acf349abc263bd6ec4eed0#l61>



More information about the Lede-dev mailing list