On Sun, Sep 03, 2017 at 09:37:02PM +0200, Stefan Sperling wrote:
> 
> Starting out in associated (not down!) state:
>  ifconfig iwn0 down; ifconfig iwn0 scan
> shows 2 GHz and 5 GHz APs, whereas just
>   ifconfig iwn0 scan
> does not show all APs. The diff below makes both cases show all APs.
> 
> ok?

I tested with iwn(4) on the sony vaio laptop.

$ dmesg | grep iwn0
iwn0 at pci2 dev 0 function 0 "Intel Wireless WiFi Link 4965" rev 0x61: msi, 
MIMO 2T3R, MoW1, address 00:1d:e0:b3:e6:c1

Without this diff, 'ifconfig iwn0 scan' sometimes can scan the available
2ghz and 5ghz APs and sometimes not.  With this diff, iwn(4) can scan
the available 2ghz and 5ghz APs all the time.

ok kevlo@

> 
> Index: ieee80211.c
> ===================================================================
> RCS file: /cvs/src/sys/net80211/ieee80211.c,v
> retrieving revision 1.62
> diff -u -p -r1.62 ieee80211.c
> --- ieee80211.c       20 Jun 2017 13:51:46 -0000      1.62
> +++ ieee80211.c       3 Sep 2017 18:44:31 -0000
> @@ -877,7 +877,9 @@ ieee80211_next_mode(struct ifnet *ifp)
>               if (ic->ic_curmode == IEEE80211_MODE_11N)
>                       continue;
>  
> -             if (ic->ic_curmode >= IEEE80211_MODE_MAX) {
> +             /* Always scan in AUTO mode if the driver scans all bands. */
> +             if (ic->ic_curmode >= IEEE80211_MODE_MAX ||
> +                 (ic->ic_caps & IEEE80211_C_SCANALLBAND)) {
>                       ic->ic_curmode = IEEE80211_MODE_AUTO;
>                       break;
>               }
> 
> Long explanation:
> 
> The iwn, iwm, and wpi drivers run a firmware-based scan which receives
> beacons from all channels the device supports, across 2 and 5 GHz bands.
> Such drivers set a capability flag called 'SCANALLBAND'.
> 
> The net80211 stack filters received beacons based on the current active
> channel set. The active channel set depends on the current mode (11a/b/g/n).
> 
> For example, set the interface to 11g mode and scan:
>   ifconfig iwn0 mode 11g; ifconfig iwn0 scan
> Only 2GHz APs will be shown because net80211 filters out 5GHz ones.
> Conversely, with:
>   ifconfig iwn0 mode 11a; ifconfig iwn0 scan
> only 5GHz APs will be shown.
> Reset the mode to default (autoselect): ifconfig iwn0 -mode
> 
> The autoselect mode puts all channels in the active channel set during
> its first scan iteration. However, the automatic mode then also tries
> all fixed modes in sequence and recalculates the active channel set
> during each iteration (see net80211/ieee80211.c:ieee80211_setmode()).
> 
> This behaviour makes sense for devices which can only scan distinct
> channel sets, e.g. 11b and 11a, like ath(4).
> But with firmware-based scans which return beacons from all supported
> channels every time, it gets in the way.
> 
> While iwn is associated to a 2GHz AP, 'ifconfig iwn0 scan' will start out
> in 11g mode. The active channel set is restricted accordingly and only
> 2GHz APs will be seen during the first scan iteration. Even if there
> is a better 5GHz AP around it will only be selected if association to
> the 2GHz AP fails for some reason and another mode is tried.
> 
> If the interface is reset (ifconfig iwn0 down) then a scan always starts
> out in the initial 'auto' iteration with all channels in the initial active
> channel set. So to switch from a 2GHz AP to a better 5GHz AP, the interface
> must be stopped and restarted. Just running a scan is not enough.
> 
> The diff fixes this inconsistency by always keeping iwn, iwm, and wpi in
> auto mode during scans. This allows reception of beacons on all channels,
> unless 'ifconfig mode' was used to force a particular mode (not visible in
> context of the diff: this function returns early if a specific mode has
> been configured).
> 
> 

Reply via email to