Improved Wifi Roaming Behavior - sharmasadhna/mylearnings GitHub Wiki

Problem statement:

  1. It takes too long for device to switch to another AP, when signal strength at AP was bad. i.e. switching to another BSS took several seconds from AP1 to AP2 when signal strength of AP1 was lower than AP2.

Solution:

  1. In Settings application, customer will set the

    1. frequencies for which they want to roam,
    2. scanning period: how often they want to scan over a freq before switching to another BSS,
    3. thresholdValues for SNR (SignalToNoise Ratio) : threshold level (in dB) to switch to another BSS
  2. WifiConnectivityManager.java : add User entered roaming frequencies for scanning --> modify setScanChannels(), startPeriodicSingleScan(), startPeriodicScan() (when screen is ON), Reduce MACROS for scanning interval from 20sec to 2sec,

  3. WifiStateMachine.java: Call, USer roaming methods (setAutoRoaming, setFrequency etc...) from WifiNative, it handles calling WifiConfigManager to add & enable n/w configs & reply to the message from the sender of outcome.

  4. Read these values from the customer setting, into WifiStaHAl (frameworks/opt/net/wifi/*), to have user values passed to the lower level wpa_supplicant daemon. (Check Android Wifi stack diagram, WifiConfigManager also modified for USer entered values)

  5. WifiNative.java : native calls for bringup/shutdown of supplicant daemon & for sending req to supplicant daemon

  6. wpa_supplicant daemon, implements the roaming behavior, we modify the core logic to roam for frequencies entered by User, and switch to best BSS in the network wpa_supp_roamingFlow_diag_compact

Read: How wpa_supplicant works, for overview of what is wpa_supp and how it works and how to build this https://github.com/sharmasadhna/mylearnings/wiki/WIFi-Roaming-terminologies-and-project-problem-statement and https://github.com/sharmasadhna/mylearnings/wiki/wpa_supplicant

<TODO: Add stack diagram>

https://innovativetechspace.wordpress.com/2015/02/24/wifi-architecture-and-flow-in-android/

frameworks/opt/net/wifi/service/java/com/android/server/wifi/*

WifiConnectivityManager.java : manages all connectivity related scanning activities when screen is on/off; Wifi is connected/disconnected/on-demand; scan is initiated and scan results are passed to WifiNetworkSelector. WifiNetworkSelector, makes recommendation on which network to connect to.

WifiStateMachine.java: tracks state of Wifi connectivity, wifi on the android device supports 3 modes: Wifi client, SoftAP(hotspot) and P2P (Wifi-direct), (concurrent Wifip2P and Wifi works), WifiStateMachine handles, Wifi Client and WifiP2P.

WifiController : controller for WifiStateMachine, check if current mode is STA/AP

WifiSettingsStore: tracks settings including wifi toggle, airplane toggle, tethering toggle, scan mode toggle and provide API to figure out if Wifi should be on/off.

WifiTrafficPoller: Polls traffic on Wifi and notify apps listening on it

XmlUtil.java: utility methods for : 1. backup/restore wifi n/w data to/from cloud, 2. persisting wifi n/w data to/from disk utility class to serialize/DE serialize obj to XML vice-versa, used by WifiConfigStore & WifibackupStore, (add roaming fields here)

#################.........................###############

wpa supplicant roaming Configuration from handbook:

Frequency list

A list of channels on which the DLT-V72 should scan for potential AP candidates. Enter all the frequencies you use separated with a whitespace. Use the center frequency from the tables below.

IMPORTANT NOTE: In case user configures only 2.4 or 5.0Ghz channels, the terminal will still use all available channels in case Access Point offers 2.4 and 5.0Ghz channels in parallel with matching SSID.

Scan period

Corresponding to the number of channels used for the SSID, you need to calculate a suitable timer in working environment. Hints on such calculation can be found in the note below.

Minimum and maximum signal

The signal strength with currently connected access point. The terminal is triggered to roam when the current signal strength is weaker than the setting value and the new visible access point has certain higher signal strength. (defined in Minimum and maximum signal others). We recommend starting your device integration test with -65 for all the different signals.

Minimum and maximum signal others

The signal strength of the new visible candidates. The terminal is triggered to roam when the current signal strength is weaker than Min/Max signal and the new visible access point has certain higher signal strength than Min/Max signal others. Proper difference could avoid unnecessary roaming frequency. We recommend setting difference larger than 5 dBm.

Subject matter, Purpose

This document describes the modifications applied to the wpa_supplicant and the upper layer Android Java Network System in order to establish a robust WiFi networking and roaming behaviour for fast moving devices.

Problem description

Android was not yet designed in 7.1.2 for industrial environments with Android on board of fast moving vehicles requiring a very persistent and permanent connection to a WiFi network with the same ESSID and lot of BSS, also with overlapping BSS on the same frequency. If the wpa_supplicant driver netlink sees a disconnection from an AP or better one for the network, it informs the Java network layer which does a lot of things who are very generic and more tight to mobile phone use cases. The time between the current BSS is disconnected and the reconnect to the BSS is almost too long.

A typical roaming use case in industrial environments would include the following setup:

• One network name ESSID for the entire environment

• Many BSS (most of them working on channel 1, 7 and 12 in the same network

Improvements for faster roaming

There were in fact 2 parts referring to that, one is the real roaming where ony the BSS is switched from one BSS to another and the other part is the fast reconnection whenever a disconnection is detected.

In the Settings App there are 5 new parameters for manual roaming defined:

  1. Scan interval: It has to be properly selected depending on the number of channels (frequencies) selected + a time constant. One frequency scan is about ~50ms. With 1-3 frequencies it is reasonable to configure the scan interval to 2 seconds.
  2. Frequencies list: Frequencies as space separated list.,i.e. "2442 2422"
  3. All threshold levels must be filled out.

Improvement on BSS switching

The idea is to switch the BSS when a better BSS is detected upon better signal strength. This is done in the wpa_supplicant daemon.

• The algorithm behind is working as follows (Levels are negative):

• Minimum Signal = Ms

• Minimum Signal Others = Mso

• Maximum Signal = Mx

• Maximum Signal Others = Mxo

• Own signal strength (in dB) = E

• Best BSS Signal strength of the list, but not including the currently connected = A

• "Others" means: The best BSS threshold level of the BSS, but not the current connected

Algorithm:

If ( (E < Ms && A >= Mso) || (E <Mx && A >= Mxo) ) then switch to BSS A.

The code herefore can be found in wpa_supplicant_8/wpa_supplicant/bss.c, starting from line 868. This is done with (control command “ROAM” when using wpa_cli):

wpa_s->reassociate = 1; wpa_supplicant_connect(wpa_s,new_bss,wpa_s→current_ssid);

Reconnection when disconnected

Previously, the wpa_supplicant detects a BSS disconnection and informs the java layer. Since this takes too long, it has not been changed but in addition, the wpa_supplicant has been modified. has been introduced for the case that there'S already a connection. The method described here is very similar, but for the case the device is not connected to the network. When disconnected and the wpa_supplicant sees the configured network appearing after a scan, it automatically reconnects to the BSS with the best signal strength. The code herefore is on the same location as above and can be found in wpa_supplicant_8/wpa_supplicant/bss.c, starting from line 920.

Additional improvements

• Due to configured scan periods, the scan period could be chosen in the Settings menu for connected networks.

• For unconnected networks the scan period is 2 seconds but lasts at least the duration of the scan

• Android has a mechanism to blacklist access points. This has been modified with the following logic: Whenever an access point is successfully connected, it is put in a whitelist and never be blacklisted. If an accesspoint connection attempt fails for 10 times, it is blacklisted. The whitelist are cleaned up when the android is rebooted.

• Android has a mechanism to disable networks temporary or permanent. This has been removed.

• The two points above may include some security risks since they may have been implemented to prevent attackers pretending to be an AP

Why “minimum” and “maximum” ?

Imagine you have a building where the AP coverage is well done with a threshold of -65dB. That means when you pass from one to the other you will have the condition met that the one you are connected to has worser than -65 and there’s another new one which is better than -65, meaning that you will roam. Imagine there are places where this coverage is not fulfilled, maybe alongside the wall in this building. It may happen that the one you are connected to is worser than -65 and there’s another new one which you’re not already in range of better than -65, it will not roam and the connection may be lost. To avoid this, the maximum is introduced which is somehow a second level threshold for roaming in worser conditions. Because you don’t want to roam always in worser condition mode with bad db-levels, both “minimum” and “maximum” were present.

⚠️ **GitHub.com Fallback** ⚠️