Commit Graph

186 Commits

Author SHA1 Message Date
James Prestwood 0b38aabde3 station: set handshake offload if required
If IWD is connecting to a SAE/WPA3 BSS and Auth/Assoc commands
are not supported the only option is SAE offload. At this point
network_connect should have verified that the extended feature
for SAE offload exists so we can simply enable offload if these
commands are not supported.
2021-03-22 14:16:31 -05:00
James Prestwood 2b5e566c9d station: use network_bss_update
This fixes a dangling pointer in network where station was
freeing the scan_bss but network still had a pointer to it
in its own bss_list.
2021-03-15 14:47:42 -05:00
James Prestwood 97de24e694 station: disable roaming logic for auto-roaming cards
If the hardware roams automatically we want to be sure to not
react to CQM events and attempt to roam/disconnect on our own.

Note: this is only important for very new kernels where CQM
events were recently added to brcmfmac.
2021-03-15 13:32:35 -05:00
James Prestwood 133347440e netdev: station: support full mac roaming
Roaming on a full mac card is quite different than soft mac
and needs to be specially handled. The process starts with
the CMD_ROAM event, which tells us the driver is already
roamed and associated with a new AP. After this it expects
the 4-way handshake to be initiated. This in itself is quite
simple, the complexity comes with how this is piped into IWD.

After CMD_ROAM fires its assumed that a scan result is
available in the kernel, which is obtained using a newly
added scan API scan_get_firmware_scan. The only special
bit of this is that it does not 'schedule' a scan but simply
calls GET_SCAN. This is treated special and will not be
queued behind any other pending scan requests. This lets us
reuse some parsing code paths in scan and initialize a
scan_bss object which ultimately gets handed to station so
it can update connected_bss/bss_list.

For consistency station must also transition to a roaming state.
Since this roam is all handled by netdev two new events were
added, NETDEV_EVENT_ROAMING and NETDEV_EVENT_ROAMED. Both allow
station to transition between roaming/connected states, and ROAMED
provides station with the new scan_bss to replace connected_bss.
2021-03-15 13:14:39 -05:00
James Prestwood c026337792 station: move scan cancelation to __station_connect_network
An earlier patch fixed a problem where a queued quick scan would
be triggered and fail once already connected, resulting in a state
transition from connected --> autoconnect_full. This fixed the
Connect() path but this could also happen via autoconnect. Starting
from a connected state, the sequence goes:

 - DBus scan is triggered
 - AP disconnects IWD
 - State transition from disconnected --> autoconnect_quick
 - Queue quick scan
 - DBus scan results come in and used to autoconnect
 - A connect work item is inserted ahead of all others, transition
   from autoconnect_quick --> connecting.
 - Connect completes, transition from connecting --> connected
 - Quick scan can finally get triggered, which the kernel fails to
   do since IWD is connected, transition from connected -->
   autoconnect_full.

This can be fixed by checking for a pending quick scan in the
autoconnect path.
2021-02-04 20:56:34 -06:00
Denis Kenzior 0c277e442e station: Remove unneeded logic from dbus_scan_done
Commit eac2410c83 ("station: Take scanned frequencies into account")
has made it unnecessary to explicitly invoke station_set_scan_results
with the expire to true in case a dbus scan finished prematurely or a
subset was not able to be started.  Remove this no-longer needed logic.

Fixes: eac2410c83 ("station: Take scanned frequencies into account")
2021-02-03 14:39:42 -06:00
James Prestwood c3e160880f station: only add diagnostic interface when connected
The diagnostic interface returns an error anyways if station is
not connected so it makes more sense to only bring the interface
up when its actually usable. This also removes the interface
when station disconnects, which was never done before (the
interface stayed up indefinitely due to a forgotten remove call).
2021-02-03 13:37:19 -06:00
Denis Kenzior 6ced1ec9de station: Use active scan in autoconnect mode
When we're auto-connecting and have hidden networks configured, use
active scans regardless of whether we see any hidden BSSes in our
existing scan results.

This allows us to more effectively see/connect to hidden networks
when first powering up or after suspend.
2021-02-03 13:36:36 -06:00
Denis Kenzior 73309686bd station: Use flush flag for all scans 2021-02-03 13:36:27 -06:00
Denis Kenzior ab5fd961c8 station: Also reset the SSID when hiding
Make the SSID all zeros when hiding a network.  This makes sure that the
BSS isn't inadvertently confused for a non-hidden one
2021-02-03 13:36:19 -06:00
Denis Kenzior 9af25d937d station: Make sure bss_match also matches the ssid
Kernel might report hidden BSSes that are reported from beacon frames
separately than ones reported due to probe responses.  This may confuse
the station network collation logic since the scan_bss generated by the
probe response might be removed erroneously when processing the scan_bss
that was generated due to a beacon.

Make sure that bss_match also takes the SSID into account and only
matches scan_bss structures that have the same BSSID and SSID contents.
2021-02-03 13:36:09 -06:00
Denis Kenzior 8fd6985214 station: move filtering of non-utf8 scan_bss entries
Instead of silently ignoring entries with non-utf8 SSIDs, drop them from
the new_bss_list entirely.
2021-02-03 13:35:58 -06:00
Denis Kenzior eac2410c83 station: Take scanned frequencies into account
Instead of manually managing whether to expire BSSes or not, use the
scanned frequency set instead.  This makes the API slightly easier to
understand (dropping two boolean arguments in a row) and also a bit more
future-proof.
2021-02-03 13:35:03 -06:00
Denis Kenzior ccbd32503b scan: Pass the frequencies scanned to notify cb 2021-02-03 13:34:44 -06:00
James Prestwood 1c80672983 station: add Frequency to diagnostics dictionary 2021-02-03 12:54:59 -06:00
Denis Kenzior c3f76cb5a5 station: Return NotHidden error
Commit d372d59bea checks whether a hidden network had a previous
connection attempt and re-tries.  However, it inadvertently dropped
handling of a condition where a non-hidden network SSID is provided to
ConnectHiddenNetwork.  Fix that.

Fixes: d372d59bea ("station: Allow ConnectHiddenNetwork to be retried")
2021-02-03 09:12:08 -06:00
Denis Kenzior c319bca477 station: correctly set mac randomization hint
Now that ConnectHiddenNetwork can be invoked while we're connected, set
the mac randomization hint parameter properly.  The kernel will reject
requests if randomization is enabled while we're connected to a network.
2021-02-02 09:54:34 -06:00
Denis Kenzior 06ca8e20a9 station: Hide forgotten hidden networks
If we forget a hidden network, then make sure to remove it from the
network list completely.  Otherwise it would be possible to still
issue a Network.Connect to that particular object, but the fact that the
network is hidden would be lost.
2021-02-02 09:36:37 -06:00
Denis Kenzior add3d43dad station: expire networks found by hidden scan sooner 2021-02-01 15:30:15 -06:00
Denis Kenzior 08a295c348 station: Fix leaking of roam_freqs on shutdown
==17639== 72 (16 direct, 56 indirect) bytes in 1 blocks are definitely
lost in loss record 3 of 3
==17639==    at 0x4C2F0CF: malloc (vg_replace_malloc.c:299)
==17639==    by 0x4670AD: l_malloc (util.c:61)
==17639==    by 0x4215AA: scan_freq_set_new (scan.c:1906)
==17639==    by 0x412A9C: parse_neighbor_report (station.c:1910)
==17639==    by 0x407335: netdev_neighbor_report_frame_event
(netdev.c:3522)
==17639==    by 0x44BBE6: frame_watch_unicast_notify (frame-xchg.c:233)
==17639==    by 0x470C04: dispatch_unicast_watches (genl.c:961)
==17639==    by 0x470C04: process_unicast (genl.c:980)
==17639==    by 0x470C04: received_data (genl.c:1101)
==17639==    by 0x46D9DB: io_callback (io.c:118)
==17639==    by 0x46CC0C: l_main_iterate (main.c:477)
==17639==    by 0x46CCDB: l_main_run (main.c:524)
==17639==    by 0x46CF01: l_main_run_with_signal (main.c:656)
==17639==    by 0x403EDE: main (main.c:490)
2021-02-01 15:12:17 -06:00
Denis Kenzior d372d59bea station: Allow ConnectHiddenNetwork to be retried
In the case that ConnectHiddenNetwork scans successfully, but fails for
some other reason, the network object is left in the scan results until
it expires.  This will prevent subsequent attempts to use
ConnectHiddenNetwork with a .NotHidden error.  Fix that by checking
whether a found network is hidden, and if so, allow the request to
proceed.
2021-02-01 14:19:37 -06:00
Denis Kenzior e04ae506a3 network: rework network_connect_new_hidden_network
Rework the logic slightly so that this function returns an error message
on error and NULL on success, just like other D-Bus method
implementations.  This also simplifies the code slightly.
2021-02-01 13:37:07 -06:00
Denis Kenzior 56538bf75b station: Allow ConnectHiddenNetwork while connected
We used to not allow to connect to a different network while already
connected.  One had to disconnect first.  This also applied to
ConnectHiddenNetwork calls.

This restriction can be dropped now.  station will intelligently
disconnect from the current AP when a station_connect_network() is
issued.
2021-02-01 13:37:07 -06:00
Denis Kenzior fc10ee8745 station: Fix not cleaning up pending_connect
If the disconnect fails and station_disconnect_onconnect_cb is called
with an error, we reply to the original message accordingly.
Unfortunately pending_connect is not unrefed or cleared in this case.
Fix that.

Fixes: d0ee923dda ("station: Disconnect, if needed, on a new connection attempt")
2021-02-01 13:37:07 -06:00
James Prestwood 7b2ce98abd station: fix leak on parse_neighbor_report 2021-01-29 17:22:20 -06:00
James Prestwood a9c32d85ea station: cancel quick scans on Connect()
At some point the non-interactive client tests began failing.
This was due to a bug in station where it would transition from
'connected' to 'autoconnect' due to a failed scan request. This
happened because a quick scan got scheduled during an ongoing
scan, then a Connect() gets issued. The work queue treats the
Connect as a priority so it delays the quick scan until after the
connection succeeds. This results in a failed quick scan which
IWD does not expect to happen when in a 'connected' state. This
failed scan actually triggers a state transition which then
gets IWD into a strange state where its connected from the
kernel point of view but does not think it is:

src/station.c:station_connect_cb() 13, result: 0
src/station.c:station_enter_state() Old State: connecting, new state: connected
src/wiphy.c:wiphy_radio_work_done() Work item 6 done
src/wiphy.c:wiphy_radio_work_next() Starting work item 5
src/station.c:station_quick_scan_triggered() Quick scan trigger failed: -95
src/station.c:station_enter_state() Old State: connected, new state: autoconnect_full

To fix this IWD should simply cancel any pending quick scans
if/when a Connect() call comes in.
2021-01-26 14:45:00 -06:00
James Prestwood 158dc40340 station: refactor to use diagnostic_info_to_dict 2021-01-22 14:59:47 -06:00
James Prestwood 5a6b474a14 netdev: move netdev_station_info to diagnostic.h
With AP now getting its own diagnostic interface it made sense
to move the netdev_station_info struct definition into its own
header which eventually can be accompanied by utilities in
diagnostic.c. These utilities can then be shared with AP and
station as needed.
2021-01-22 14:40:45 -06:00
Alvin Šipraga 4266b88658 station: add RoamRetryInterval setting 2021-01-22 13:46:25 -06:00
Alvin Šipraga f456501b9e station: retry roaming unless notified of a high RSSI
Following a successful roaming sequence, schedule another attempt unless
the driver has sent a high RSSI notification. This makes the behaviour
analogous to a failed roaming attempt where we remained connected to the
same BSS.

This makes iwd compatible with wireless drivers which do not necessarily
send out a duplicate low RSSI notification upon reassociation. Without
this change, iwd risks getting indefinitely stuck to a BSS with low
signal strength, even though a better BSS might later become available.

In the case of a high RSSI notification, the minimum roam time will also
be reset to zero. This preserves the original behaviour in the case
where a high RSSI notification is processed after station_roamed().
Doing so also gives a chance for faster roaming action in the following
example scenario:

    1. RSSI LOW
    2. schedule roam in 5 seconds
        (5 seconds pass)
    3. try roaming
    4. roaming fails, same BSS
    5. schedule roam in 60 seconds
        (20 seconds pass)
    6. RSSI HIGH
    7. cancel scheduled roam
        (20 seconds pass)
    8. RSSI LOW
    9. schedule roam in 5 seconds or 20 seconds?

By resetting the minimum roam time, we can avoid waiting 20 seconds when
the station may have moved considerably. And since the high/low RSSI
notifications are configured with a hysteresis, we should still be
protected against too frequent spurious roaming attempts.
2021-01-22 13:41:07 -06:00
Alvin Šipraga 9edd941bc2 station: remove unused roam_no_orig_ap state variable
Since commit 836beb1276 removed beacon
loss handling, the roam_no_orig_ap variable has no use and is always set
to false. This commit removes it.
2021-01-20 11:14:06 -06:00
James Prestwood a17e5e0f7f station: create StationDiagnostic interface
This interface sits aside the regular station interface but
provides low level connection details for diagnostic and
testing purposes.
2021-01-14 15:02:13 -06:00
Andrew Zaborowski f5a30a1cfc station: Don't expire BSSes between freq subset scans
Add a parameter to station_set_scan_results to allow skipping the
removal of old BSSes.  In the DBus-triggered scan only expire BSSes
after having gone through the full supported frequency set.

It should be safe to pass partial scan results to
station_set_scan_results() when not expiring BSSes so using this new
parameter I guess we could also call it for roam scan results.
2020-12-17 20:22:47 -06:00
Andrew Zaborowski e3bece76f9 station: Split DBus scans into 3 frequency subsets
A scan normally takes about 2 seconds on my dual-band wifi adapter when
connected.  The drivers will normally probe on each supported channel in
some unspecified order and will have new partial results after each step
but the kernel sends NL80211_CMD_NEW_SCAN_RESULTS only when the full
scan request finishes, and for segmented scans we will wait for all
segments to finish before calling back from scan_active() or
scan_passive().

To improve user experience define our own channel order favouring the
2.4 channels 1, 6 and 11 and probe those as an individual scan request
so we can update most our DBus org.connman.iwd.Network objects more
quickly, before continuing with 5GHz band channels, updating DBus
objects again and finally the other 2.4GHz band channels.

The overall DBus-triggered scan on my wifi adapter takes about the same
time but my measurements were not very strict, and were not very
consistent with and without this change.  With the change most Network
objects are updated after about 200ms though, meaning that I get most
of the network updates in the nm-applet UI 200ms from opening the
network list.  The 5GHz band channels take another 1 to 1.5s to scan and
remaining 2.4GHz band channels another ~300ms.

Hopefully this is similar when using other drivers although I can easily
imagine a driver that parallelizes 2.4GHz and 5GHz channel probing using
two radios, or uses 2, 4 or another number of dual-band radios to probe
2, 4, ... channels simultanously.  We'd then lose some of the
performance benefit.  The faster scan results may be worth the longer
overall scan time anyway.
I'm also assuming that the wiphy's supported frequency list is exactly
what was scanned when we passed no frequency list to
NL80211_CMD_TRIGGER_SCAN and we won't get errors for passing some
frequency that shouldn't have been scanned.
2020-12-17 20:15:37 -06:00
James Prestwood 845658bd32 station: get neighbor reports early
Waiting to request neighbor reports until we are in need of a roam
delays the roam time, and probably isn't as reliable since we are
most likely in a low RSSI state. Instead the neighbor report can
be requested immediately after connecting, saved, and used if/when
a roam is needed. The existing behavior is maintained if the early
neighbor report fails where a neighbor report is requested at the
time of the roam.

The code which parses the reports was factored out and shared
between the existing (late) neighbor report callback and the early
neighbor report callback.
2020-11-16 18:14:07 -06:00
James Prestwood 836beb1276 station/wsc: remove beacon loss handling
Modern kernels ~5.4+ have changed the way lost beacons are
reported and effectively make the lost beacon event useless
because it is immediately followed by a disconnect event. This
does not allow IWD enough time to do much of anything before
the disconnect comes in and we are forced to fully re-connect
to a different AP.
2020-11-04 13:40:25 -06:00
Andrew Zaborowski 1f89ebb86a station: Fix .Scanning being reset early
periodic_scan_stop is called whenever we exit the autoscan state but a
periodic scan may not be running at the time.  If we have a
user-triggered scan running, or the autoconnect_quick scan, and we reset
Scanning to false before that scan finished, a client could en up
calling GetOrderedNetwork too early and not receiving the scan results.
2020-10-14 13:01:18 -05:00
Andrew Zaborowski 758dba214e station: Make Disconnect() cancel ConnectHiddenNetwork()
ConnectHiddenNetwork can be seen a triggering this sequence:
1. the active scan,
2. the optional agent request,
3. the Authentication/Association/4-Way Handshake/netconfig,
4. connected state

Currently Disconnect() interrupts 3 and 4, allow it to also interrupt
state 1.  It's difficult to tell whether we're in state 2 from within
station.c.
2020-10-08 08:54:01 -05:00
James Prestwood ffe9ce8034 station: print which BSS is being connected to
For multi-bss networks its nice to know which BSS is being connected
to. The ranking can hint at it, but blacklisting or network capabilities
could effect which network is actually chosen. An explicit debug print
makes debugging much easier.
2020-09-14 16:03:04 -05:00
Denis Kenzior ac5ddda56f treewide: Add missing netdev module dependencies 2020-08-20 11:49:01 -05:00
Andrew Zaborowski 49f38b0d2e station: Don't call network_rank_update with NULL network
Move the update of station->networks_sorted order to before we set
station->connected_network NULL to avoid a crash when we attempt to
use the NULL pointer.
2020-08-17 09:25:33 -05:00
Alvin Šipraga bfd8cead95 treewide: guard compare functions against signed integer overflow
Besides being undefined behaviour, signed integer overflow can cause
unexpected comparison results. In the case of network_rank_compare(),
a connected network with rank INT_MAX would cause newly inserted
networks with negative rank to be inserted earlier in the ordered
network list. This is reflected in the GetOrderedMethods() DBus method
as can be seen in the following iwctl output:

  [iwd]# station wlan0 get-networks
    Network name                    Security  Signal
  ----------------------------------------------------
    BEOLAN                          8021x     **** }
    BeoBlue                         psk       ***  } all unknown,
    UI_Test_Network                 psk       ***  } hence assigned
    deneb_2G                        psk       ***  } negative rank
    BEOGUEST                        open      **** }
  > titan                           psk       ****
    Linksys05274_5GHz_dmt           psk       ****
    Lyngby-4G-4 5GHz                psk       ****
2020-08-14 10:55:30 -05:00
Alvin Šipraga 94d4b341e3 station: refresh ordered network list on (dis)connect
Doing so ensures that the currently connected network is always at the
beginning of the list. Previously, the list would only get updated after
a scan.

This fixes the documented behaviour of GetOrderedNetworks() DBus method,
which states that the currently connected network is always at the
beginning of the returned array.
2020-08-14 10:55:22 -05:00
Andrew Zaborowski 914a03c4bf station: Comment/whitespace fix 2020-07-31 10:38:59 -05:00
James Prestwood 4165d9414f netdev: use wiphy radio work queue for connections
This adds connection/FT attempts to the radio work queue. This
will ensure that connections aren't delayed or done concurrently
with scanning.
2020-07-15 17:10:36 -05:00
James Prestwood 5f7b28d501 scan: refactor to use wiphy radio work queue
To use the wiphy radio work queue, scanning mostly remained the same.
start_next_scan_request was modified to be used as the work callback,
as well as not start the next scan if the current one was done
(since this is taken care of by wiphy work queue now). All
calls to start_next_scan_request were removed, and more or less
replaced with wiphy_radio_work_done.

scan_{suspend,resume} were both removed since radio management
priorities solve this for us. ANQP requests can be inserted ahead of
scan requests, which accomplishes the same thing.
2020-07-10 13:23:58 -05:00
James Prestwood a3d0eebe74 station: cancel hidden network scan when connecting
Before connecting to a hidden network we must scan. During this scan
if another connection attempt comes in the expected behavior is to
abort the original connection. Rather than waiting for the scan to
complete, then canceling the original hidden connection we can just
cancel the hidden scan immediately, reply to dbus, and continue with
the new connection attempt.
2020-07-09 10:00:55 -05:00
James Prestwood 7e0084e6ae anqp: refactor to use frame-xchg
The new frame-xchg module now handles a lot of what ANQP used to do. ANQP
now does not need to depend on nl80211/netdev for building and sending
frames. It also no longer needs any of the request lookups, frame watches
or to maintain a queue of requests because frame-xchg filters this for us.

From an API perspective:
 - anqp_request() was changed to take the wdev_id rather than ifindex.
 - anqp_cancel() was added so that station can properly clean up ANQP
   requests if the device disappears.

During testing a bug was also fixed in station on the timeout path
where the request queue would get popped twice.
2020-07-09 09:58:21 -05:00
Denis Kenzior a1b41f786e station: Re-attempt roam with a full scan
When roaming, iwd tries to scan a limited number of frequencies to keep
the roaming latency down.  Ideally the frequency list would come in from
a neighbor report, but if neighbor reports are not supported, we fall
back to our internal database for known frequencies of this network.

iwd tries to keep the number of scans down to a bare minimum, which
means that we might miss APs that are in range.  This could happen
because the user might have moved physically and our frequency list is
no longer up to date, or if the AP frequencies have been reconfigured.

If a limited scan fails to find any good roaming candidates, re-attempt
a full scan right away.
2020-06-30 12:34:41 -05:00
Denis Kenzior b026e6740b station: Return errno from station_roam_scan 2020-06-30 12:29:22 -05:00