Skip to content
/ src Public

Commit a90e20d

Browse files
committed
Fix the behavior of preferring weaker-but-still-good 5Ghz APs over
2Ghz APs because the 5Ghz band is generally less saturated. The previous implementation was dependent upon the order of walking APs. ok stsp
1 parent 0a9a54a commit a90e20d

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

sys/net80211/ieee80211_node.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ieee80211_node.c,v 1.122 2017/12/08 21:16:01 stsp Exp $ */
1+
/* $OpenBSD: ieee80211_node.c,v 1.123 2017/12/12 00:24:21 jcs Exp $ */
22
/* $NetBSD: ieee80211_node.c,v 1.14 2004/05/09 09:18:47 dyoung Exp $ */
33

44
/*-
@@ -665,10 +665,12 @@ void
665665
ieee80211_end_scan(struct ifnet *ifp)
666666
{
667667
struct ieee80211com *ic = (void *)ifp;
668-
struct ieee80211_node *ni, *nextbs, *selbs, *curbs;
668+
struct ieee80211_node *ni, *nextbs, *selbs = NULL, *curbs = NULL,
669+
*selbs2 = NULL, *selbs5 = NULL;
669670
int bgscan = ((ic->ic_flags & IEEE80211_F_BGSCAN) &&
670671
ic->ic_opmode == IEEE80211_M_STA &&
671672
ic->ic_state == IEEE80211_S_RUN);
673+
uint8_t min_5ghz_rssi;
672674

673675
if (ifp->if_flags & IFF_DEBUG)
674676
printf("%s: end %s scan\n", ifp->if_xname,
@@ -749,8 +751,6 @@ ieee80211_end_scan(struct ifnet *ifp)
749751
ieee80211_next_scan(ifp);
750752
return;
751753
}
752-
selbs = NULL;
753-
curbs = NULL;
754754

755755
for (; ni != NULL; ni = nextbs) {
756756
nextbs = RBT_NEXT(ieee80211_tree, ni);
@@ -771,31 +771,34 @@ ieee80211_end_scan(struct ifnet *ifp)
771771
if (ieee80211_match_bss(ic, ni) != 0)
772772
continue;
773773

774-
/* Pick the AP/IBSS match with the best RSSI. */
775-
if (selbs == NULL)
776-
selbs = ni;
777-
else if ((ic->ic_caps & IEEE80211_C_SCANALLBAND) &&
778-
IEEE80211_IS_CHAN_5GHZ(selbs->ni_chan) &&
774+
if ((ic->ic_caps & IEEE80211_C_SCANALLBAND) &&
779775
IEEE80211_IS_CHAN_2GHZ(ni->ni_chan) &&
780-
ni->ni_rssi > selbs->ni_rssi) {
781-
uint8_t min_rssi;
782-
783-
/*
784-
* Prefer 5GHz (with reasonable RSSI) over 2GHz since
785-
* the 5GHz band is usually less saturated.
786-
*/
787-
if (ic->ic_max_rssi)
788-
min_rssi = IEEE80211_RSSI_THRES_RATIO_5GHZ;
789-
else
790-
min_rssi = (uint8_t)IEEE80211_RSSI_THRES_5GHZ;
776+
(selbs2 == NULL || ni->ni_rssi > selbs2->ni_rssi))
777+
selbs2 = ni;
778+
else if ((ic->ic_caps & IEEE80211_C_SCANALLBAND) &&
779+
IEEE80211_IS_CHAN_5GHZ(ni->ni_chan) &&
780+
(selbs5 == NULL || ni->ni_rssi > selbs5->ni_rssi))
781+
selbs5 = ni;
782+
}
791783

792-
if (selbs->ni_rssi >= min_rssi)
793-
continue;
794-
}
784+
if (ic->ic_max_rssi)
785+
min_5ghz_rssi = IEEE80211_RSSI_THRES_RATIO_5GHZ;
786+
else
787+
min_5ghz_rssi = (uint8_t)IEEE80211_RSSI_THRES_5GHZ;
795788

796-
if (ni->ni_rssi > selbs->ni_rssi)
797-
selbs = ni;
798-
}
789+
/*
790+
* Prefer a 5Ghz AP even if its RSSI is weaker than the best 2Ghz AP
791+
* (as long as it meets the minimum RSSI threshold) since the 5Ghz band
792+
* is usually less saturated.
793+
*/
794+
if (selbs5 && selbs5->ni_rssi > min_5ghz_rssi)
795+
selbs = selbs5;
796+
else if (selbs5 && selbs2)
797+
selbs = (selbs5->ni_rssi >= selbs2->ni_rssi ? selbs5 : selbs2);
798+
else if (selbs2)
799+
selbs = selbs2;
800+
else if (selbs5)
801+
selbs = selbs5;
799802

800803
if (bgscan) {
801804
struct ieee80211_node_switch_bss_arg *arg;

0 commit comments

Comments
 (0)