Do not sched scan if no enabled networks (UPSTREAM)

There is no point to sched scan when there are no enabled networks.
With some drivers initiating such an empty sched scan causes
returning of scan results with zero results. If this is repeated
it leads to clearing of wpa_s scan results.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Avoid changing state to WPA_SCANNING for sched scan (UPSTREAM)

This prevents manual scan requests from the control iface
in case of sched scan and normal scan can run concurrently.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Allow a new sched scan to replace an existing one (UPSTREAM)

Sched scan needs to be restarted in cases where the enabled
networks list changes. Make wpa_supplicant_req_sched_scan
cancel the previous scan in case there's an ongoing one and
start a new one with the updated networks list.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Fix use-after-free when removing all networks (UPSTREAM)

commit 59ff6653
"Fix REMOVE_NETWORK to not run operations with invalid current_ssid"
fixed the removal of a single network but the same use-after-free
issue exists when removing all networks.

As part of the fix refactor ctrl_iface_remove_network to use
wpa_supplicant_remove_network which actually does the work.
This should help with fixing the use-after-free issue also when
remove network is done via dbus.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
wpa_supplicant: add function that enables one network

This function enables one network, clears temp_disabled, notifies
About changing status and toggles reassociate if we are disconnected.

Signed-off-by: David Spinadel <david.spinadel@intel.com>
wpa_supplicant: use a different function to enable a network

Use a function to enable a network, and then start scan if needed.
Stop scheduled scan, if exists, before starting a regular scan.

Signed-off-by: David Spinadel <david.spinadel@intel.com>
Restart sched scan following remove network (UPSTREAM)

As the enabled networks list changes sched scan should
be restarted with the new networks list to avoid keep scanning
for removed networks.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Cancel sched scan upon assoc event (UPSTREAM)

Looks like since scan is canceled so should any sched scan.
This should probably not occur as both are canceled upon
attempting to connect.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Change sched_scan logic for large number of configured networks (UPSTREAM)

One of the major motivations behind sched scan is offloading
periodic scanning to the device firmware so that the host can
suspend and only be woken up when a known network is close by.
When there are more than max_match_sets or max_sched_scan_ssids
networks in the configuration the current logic will attempt to sched
scan a maximal group up to a certain timeout and then switch to
the next group. The timeout also changes with a backoff.

There are a couple of problems with this approach:
	1. The host can suspend while we are sched scanning an arbitrary
	sub group of networks from all the configured networks. The
	device will keep searching only for these networks while suspended
	and other configured networks won't be scanned for.

	2. The current backoff mechanism won't handle well large
	number of networks

Instead of this we switch to a simpler logic whose principles are:
	1. We sched scan only a single group of networks which are determined
	according to those networks with the highest priority. This way
	when the host suspends we'll be scanning the highest priority networks.

	2. If there are more networks than sched scan can handle it will
	fallback to normal scan so we can still scan for the lower priority
	networks.

	3. As there's no need to switch groups there's no need for
	timeout and backoff.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Don't scan ssids that were sched scanned (UPSTREAM)

When having more than max_sched_scan_ssids ssids, scanning
of the remaining ssids (not included in the sched scan)
might take a while.

Reduce this time by avoiding scanning of ssids that
were already included in the scheduled scan.

Signed-off-by: Eliad Peller <eliad@wizery.com>
sched scan: read driver support for sched scan intervals (UPSTREAM)

Use the feature flag reported by NL80211 to know
if the driver supports short and long intervals in
the sched scan API. This is a prep patch for the
actual handling of this flag.
sched scan: add support for short and long intervals (UPSTREAM)

Configure sched scan to use short and long intervals
if the driver supports it

Signed-off-by: Eyal Shapira <eyal@wizery.com>
sched scan: Add config parameters for short and long intervals (UPSTREAM)

Part of support for short and long intervals
Add API and CLI command to control sched scan intervals (UPSTREAM)

Enable control over the sched scan intervals parameters
through a new wpa_s API (SCHED_SCAN_INTERVALS) and a
matching wpa_cli command.

Signed-off-by: Eyal Shapira <eyal@wizery.com>