Skip to content

Commit

Permalink
improve cache scan, avoid frequently disconnect if connected to mesh …
Browse files Browse the repository at this point in the history
…wifi
  • Loading branch information
zxystd committed Sep 8, 2020
1 parent 7d27457 commit 6ce19ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 10 additions & 2 deletions itl80211/openbsd/net80211/ieee80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ ieee80211_begin_bgscan(struct _ifnet *ifp)
{
struct ieee80211com *ic = (struct ieee80211com *)ifp;

if ((ic->ic_flags & IEEE80211_F_BGSCAN) ||
ic->ic_state != IEEE80211_S_RUN || ic->ic_mgt_timer != 0)
if (ic->ic_state != IEEE80211_S_RUN || ic->ic_mgt_timer != 0)
return;

if ((ic->ic_flags & IEEE80211_F_RSNON) && !ic->ic_bss->ni_port_valid)
return;

if ((ic->ic_flags & IEEE80211_F_BGSCAN)) {
//clear disable flag, because we need to switch a better wifi now.
ic->ic_flags &= ~IEEE80211_F_DISABLE_BG_AUTO_CONNECT;
return;
}

if (ic->ic_bgscan_start != NULL && ic->ic_bgscan_start(ic) == 0) {
/*
* Free the nodes table to ensure we get an up-to-date view
Expand All @@ -117,6 +122,7 @@ ieee80211_begin_bgscan(struct _ifnet *ifp)
ieee80211_free_allnodes(ic, 0 /* keep ic->ic_bss */);

ic->ic_flags |= IEEE80211_F_BGSCAN;
ic->ic_flags &= ~IEEE80211_F_DISABLE_BG_AUTO_CONNECT;
if (ifp->if_flags & IFF_DEBUG)
XYLog("%s: begin background scan\n", ifp->if_xname);

Expand All @@ -137,6 +143,8 @@ ieee80211_begin_cache_bgscan(struct _ifnet *ifp)
if ((ic->ic_flags & IEEE80211_F_RSNON) && !ic->ic_bss->ni_port_valid)
return;

ic->ic_flags |= IEEE80211_F_DISABLE_BG_AUTO_CONNECT;

//if last cache scan is 5 minutes ago, clear the nodes and rescan.
microtime(&tv);
if (ic->ic_last_cache_scan_ts > 0 && tv.tv_sec - ic->ic_last_cache_scan_ts > 5 * 60) {
Expand Down
13 changes: 8 additions & 5 deletions itl80211/openbsd/net80211/ieee80211_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ ieee80211_end_scan(struct _ifnet *ifp)
/* AP disappeared? Should not happen. */
if (selbs == NULL || curbs == NULL) {
ic->ic_flags &= ~IEEE80211_F_BGSCAN;
ic->ic_flags &= ~IEEE80211_F_DISABLE_BG_AUTO_CONNECT;
goto notfound;
}

Expand All @@ -1473,6 +1474,7 @@ ieee80211_end_scan(struct _ifnet *ifp)
if (ic->ic_bgscan_fail < IEEE80211_BGSCAN_FAIL_MAX)
ic->ic_bgscan_fail++;
ic->ic_flags &= ~IEEE80211_F_BGSCAN;
ic->ic_flags &= ~IEEE80211_F_DISABLE_BG_AUTO_CONNECT;
/*
* HT is negotiated during association so we must use
* ic_bss to check HT. The nodes tree was re-populated
Expand All @@ -1489,10 +1491,12 @@ ieee80211_end_scan(struct _ifnet *ifp)
ieee80211_chan2mode(ic, ni->ni_chan));
return;
}
//zxy disable roam when doing background scanning, because it will cause too much problems.
#ifndef BGSCAN_ROAM
goto notfound;
#else

if (ic->ic_flags & IEEE80211_F_DISABLE_BG_AUTO_CONNECT) {
ic->ic_flags &= ~IEEE80211_F_BGSCAN;
ic->ic_flags &= ~IEEE80211_F_DISABLE_BG_AUTO_CONNECT;
return;
}

arg = (struct ieee80211_node_switch_bss_arg *)_MallocZero(sizeof(*arg));
if (arg == NULL) {
Expand Down Expand Up @@ -1530,7 +1534,6 @@ ieee80211_end_scan(struct _ifnet *ifp)
ic->ic_bss->ni_unref_cb = ieee80211_node_switch_bss;
/* F_BGSCAN flag gets cleared in ieee80211_node_join_bss(). */
return;
#endif //BGSCAN_ROAM
} else if (selbs == NULL)
goto notfound;

Expand Down
1 change: 1 addition & 0 deletions itl80211/openbsd/net80211/ieee80211_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ struct ieee80211_ess {
#define IEEE80211_F_BGSCAN 0x08000000 /* STATUS: background scan */
#define IEEE80211_F_AUTO_JOIN 0x10000000 /* CONF: auto-join active */
#define IEEE80211_F_VHTON 0x20000000 /* CONF: VHT enabled */
#define IEEE80211_F_DISABLE_BG_AUTO_CONNECT 0x40000000 /* CONF: disable auto connect to wifi when doing backgound scan */

/* ic_xflags */
#define IEEE80211_F_TX_MGMT_ONLY 0x00000001 /* leave data frames on ifq */
Expand Down

0 comments on commit 6ce19ee

Please sign in to comment.