Commit Graph

3191 Commits

Author SHA1 Message Date
Alvin Šipraga f50a51d943 network: sync known network frequency on BSS update
When a scan_bss is updated in the BSS list of a known network, it may be
on a new frequency. Sync the known frequencies list accordingly.
2021-05-27 13:49:43 -05:00
Alvin Šipraga 38ded68a38 scan: parse NL80211_BSS_LAST_SEEN_BOOTTIME in units of nanoseconds
NL80211_BSS_LAST_SEEN_BOOTTIME is expressed in nanoseconds, while BSS
timestamps are expressed in microseconds internally. Convert the
attribute to microseconds when using it to timestamp a BSS. This makes
iwd expire absent BSSes within 30 seconds as intended.

Fixes: 454cee12d4 ("scan: Use kernel-reported time-stamp if provided")
2021-05-26 10:20:48 -05:00
Denis Kenzior 1822062d55 station: Continue trying to autoconnect on failure
Right now, if a connection to a network selected by auto-connect fails,
the entire autoconnect process is restarted.  This means that scans are
kicked off again, auto-connect list is rebuilt, etc.  This was due to
auto-connect reusing the same failure path as connections triggered via
D-Bus.

The above behavior can lead to weird situations in certain corner cases.
For example, a highly preferred network configured with the wrong
password would result in auto-connect entering an infinite loop.

Fix this by making sure that all auto-connect entries are tried and
exhausted prior to re-scanning again.
2021-05-25 18:42:57 -05:00
Denis Kenzior ca561be4b9 network: Clear temporary ban list in network_disconnected
The temporary ban list is cleared when a network is connected to
successfully, and also in network_connect_failed.  Unfortunately,
network_connect_failed is not called in all paths (i.e. during
autoconnect) since it messes with the state of secrets and passphrases.

Clear the list in network_disconnected() instead, since it is guaranteed
to be called in every circumstance.
2021-05-25 18:42:57 -05:00
Denis Kenzior db3024eed6 station: Introduce CONNECTING_AUTO state
This will be effectively the same as the CONNECTING state, but can be
used to enable differing behavior, depending on whether connection was
triggered by autoconnect or via D-Bus.
2021-05-25 18:42:57 -05:00
Denis Kenzior 00763fde0d station: Break up station_connect_cb
Break this up into two parts, one handling the successful connect case,
the other for handling error conditions
2021-05-25 18:42:57 -05:00
Denis Kenzior e265f95f45 ie: Fix VHT Capabilities to Data Rate conversion
Code that walked the VHT TX/RX MCS maps seemed to assume that bit_field
operated on bits that start at '1'.  But this utility actually operates
on bits that start at '0'.  I.e. the least significant bit is at
position 0.

While we're at it, rename the mcs variable into bitoffset to make it
clearer how the maps are being iterated over.  Supported MCS is actually
the value found in the map.
2021-05-25 18:42:57 -05:00
Denis Kenzior efa5b0cc62 main: Document '-E', --developer option 2021-05-25 13:30:29 -05:00
Denis Kenzior e47bc6ede4 main: Remove dbus-debug -B option
This option has not been used in a very long time, and is of limited
utility since the only thing D-Bus debugging does is hexdumps the
content of D-Bus messages to the terminal.
2021-05-25 13:20:07 -05:00
Denis Kenzior c3b1425edd ie: Fix up HT/VHT data rate calculation
The current calculation was giving erroneous results when it came to VHT
MCS index 4 and VHT MCS index 8 & 9.

Switch to a precomputed look up table and add a multiplication factor
for short GI.
2021-05-24 18:39:26 -05:00
Denis Kenzior edf7294c06 ap: Do not leak ap->server
ap_reset() seems to be called whenever the AP is stopped or removed due
to interface shutdown.  For some reason ap_reset did not remove the DHCP
server object, resulting in leaks:

==211==    at 0x483879F: malloc (vg_replace_malloc.c:307)
==211==    by 0x46B5AD: l_malloc (util.c:62)
==211==    by 0x49B0E2: l_dhcp_server_new (dhcp-server.c:715)
==211==    by 0x433AA3: ap_setup_dhcp (ap.c:2615)
==211==    by 0x433AA3: ap_load_dhcp (ap.c:2645)
==211==    by 0x433AA3: ap_load_config (ap.c:2753)
==211==    by 0x433AA3: ap_start (ap.c:2885)
==211==    by 0x434A96: ap_dbus_start_profile (ap.c:3329)
==211==    by 0x482DA9: _dbus_object_tree_dispatch (dbus-service.c:1815)
==211==    by 0x47A4D9: message_read_handler (dbus.c:285)
==211==    by 0x4720EB: io_callback (io.c:120)
==211==    by 0x47130C: l_main_iterate (main.c:478)
==211==    by 0x4713DB: l_main_run (main.c:525)
==211==    by 0x4713DB: l_main_run (main.c:507)
==211==    by 0x4715EB: l_main_run_with_signal (main.c:647)
==211==    by 0x403EE1: main (main.c:550)
2021-05-24 14:31:04 -05:00
Denis Kenzior 23451be606 netconfig: Do not leak l_acd if static IP is used
==209==    by 0x43E48A: netconfig_ipv4_select_and_install (netconfig.c:887)
==209==    by 0x43E48A: netconfig_configure (netconfig.c:1025)
==209==    by 0x41743C: station_connect_cb (station.c:2556)
==209==    by 0x408E0D: netdev_connect_ok (netdev.c:1311)
==209==    by 0x47549E: process_unicast (genl.c:994)
==209==    by 0x47549E: received_data (genl.c:1102)
==209==    by 0x4720EB: io_callback (io.c:120)
==209==    by 0x47130C: l_main_iterate (main.c:478)
==209==    by 0x4713DB: l_main_run (main.c:525)
==209==    by 0x4713DB: l_main_run (main.c:507)
==209==    by 0x4715EB: l_main_run_with_signal (main.c:647)
==209==    by 0x403EE1: main (main.c:550)
2021-05-24 14:31:04 -05:00
Denis Kenzior 66b73262df station: Check return of network_bss_select
network_bss_select can return NULL if no suitable BSSes are found, or if
all of them are blacklisted.  Make sure to skip the network if this
happens.
2021-05-19 09:56:59 -05:00
James Prestwood 877d910a44 station: autoconnect based on network, not BSS
Prior to the BSS blacklist a BSS based autoconnect list made
the most sense, but now station actually retries all BSS's upon
failure. This means that for each BSS in the autoconnect list
every other BSS under that SSID will be attempted to connect to
if there is a failure. Essentially this is a network based
autoconnect list, just an indirect way of doing it.

Intead the autoconnect list can be purely network based, using
the network rank for sorting. This avoids the need for a special
autoconnect_entry struct as well as ensures the last connected
network is chosen first (simply based on existing network ranking
logic).
2021-05-19 09:44:18 -05:00
James Prestwood 0be5beffc8 network: use WPA version and privacy for ranking
These ranking factors were moved out of scan.c and into
network.c as they are more relevant for network ranking
than BSS ranking.
2021-05-19 09:32:28 -05:00
James Prestwood 3fde169001 scan: rework BSS ranking
It was observed that IWD's ranking for BSS's did not always
end up with the fastest being chosen. This was due to IWD's
heavy weight on signal strength. This is a decent way of ranking
but even better is calculating a theoretical data rate which
was also done and factored in. The problem is the data rate
factor was always outdone by the signal strength.

Intead remove signal strength entirely as this is already taken
into account with the data rate calculation. This also removes
the check for rate IEs. If no IEs are found the parser will
base the data rate soley on RSSI.

There were a few other factors removed which will be added back
when ranking *networks* rather than BSS's. WPA version (or open)
was removed as well as the privacy capability. These values really
should not differ between BSS's in the same SSID and as such
should be used for network ranking instead.
2021-05-19 09:32:17 -05:00
James Prestwood 7c9561f027 ie: refactor parsing supported data rates
Both ext/supported rates IEs are obtained from scan results. These
IEs are passed to ie_tlv_init/ie_tlv_next, as well as direct length
checks (for supported rates at least, extended supported rates can
be as long as a single byte integer can hold, 1 - 255) which verifies
that the length in the IE matches the overall IE length that is
stored in scan_bss. Because of this, ie_parse_supported_rates_from_data
was doing double duty re-initializing a TLV iterator.

Intead, since we know the IE length is within bounds, the length/data
can simply be directly accessed out of the buffer. This avoids the need
for a wrapper function entirely.

The length parameters were also removed, since this is now obtained
directly from the IE.
2021-05-14 14:28:23 -05:00
Andrew Zaborowski 02e46542e3 ap: Make rtnl global static 2021-05-14 09:49:08 -05:00
James Prestwood df04877a67 station: use IE_AKM_IS_FT when possible
Update a check to use IE_AKM_IS_FT as the condition is identical
to the macro.
2021-05-12 18:04:30 -05:00
James Prestwood 7fc0a8fc0f station: make station_can_fast_transition more robust
Check that the current handshake is using an FT AKM and that the
target BSS AKM suites contain an FT AKM.
2021-05-12 18:04:30 -05:00
James Prestwood 9a3639f2fa ie: use bitwise compare for IE_AKM_IS_FT
This has the same effect when passing a single AKM value, but also
handles AKM bit fields (e.g. ie_rsn_info->akm_suites)
2021-05-12 18:04:30 -05:00
James Prestwood e5fcc93a9e netdev: remove callback/userdata/timeout from FT-over-DS action
Since netdev maintains the list of FT over DS info structs there is not
any need for station to get callbacks when the initial action frame
is received, or not. This removes the need for the callback handler,
user data, and response timeout.
2021-05-12 18:04:30 -05:00
James Prestwood 7385e2c90e station: send FT-over-DS actions upon connection
Roam times can be slightly improved by sending out the FT-over-DS
action frames to any BSS in the mobility domain immediately after
connecting. This preauthenticates IWD to each AP which means
Reassociation can happen right away when a roam is needed.

When a roam is needed station_transition_start will first try
FT-over-DS (if supported) via netdev_fast_transtion_over_ds. The
return is checked and if netdev has no cached entries FT-over-Air
will be used instead.
2021-05-12 18:04:30 -05:00
James Prestwood 78fe1cc0ef network: add network_bss_list_get_entries
Gets the first l_queue_entry in the networks BSS list. Useful
for iterating only a given networks BSS's outside of network.c.
2021-05-12 18:04:30 -05:00
James Prestwood 9b7d761db5 netdev: handle multiple concurrent FT-over-DS action frames
The beauty of FT-over-DS is that a station can send and receive
action frames to many APs to prepare for a future roam. Each
AP authenticates the station and when a roam happens the station
can immediately move to reassociation.

To handle this a queue of netdev_ft_over_ds_info structs is used
instead of a single entry. Using the new ft.c parser APIs these
info structs can be looked up when responses come in. For now
the timeouts/callbacks are kept but these will be removed as it
really does not matter if the AP sends a response (keeps station
happy until the next patch).
2021-05-12 18:04:30 -05:00
James Prestwood ff333a112b ft: break up FT action parsing into two steps
This is to prepare for multiple concurrent FT-over-DS action frames.
A list will be kept in netdev and for lookup reasons it needs to
parse the start of the frame to grab the aa/spa addresses. In this
call the IEs are also returned and passed to the new
ft_over_ds_parse_action_response.

For now the address checks have been moved into netdev, but this will
eventually turn into a queue lookup.
2021-05-12 18:04:30 -05:00
James Prestwood 80712face4 station: remove ap_directed_roam check for over-DS
This flag was being checked but it is explicitly being set to
false prior.
2021-05-12 18:04:30 -05:00
James Prestwood f95e3a02e8 station: factor out logic for choosing FT 2021-05-12 18:04:30 -05:00
Andrew Zaborowski e8eb05feea netdev: ensure DISCONNECT_BY_SME uses a reason_code
Station callbacks expect a reason code (as opposed to status codes) with
this event type.
2021-05-11 11:34:17 -05:00
Andrew Zaborowski dfe57b8bb0 main: Add NetworkConfigurationEnabled to Daemon.GetInfo() 2021-05-11 10:08:51 -05:00
Andrew Zaborowski c0a1760f46 ap: Move sending CMD_START_AP to common function 2021-05-10 10:14:29 -05:00
James Prestwood b89720ca47 doc: document [General].RoamThreshold5G 2021-05-10 10:12:46 -05:00
James Prestwood 968584d3f0 netdev: introduce [General].RoamThreshold5G
This value sets the roaming threshold on 5GHz networks. The
threshold has been separated from 2.4GHz because in many cases
5GHz can perform much better at low RSSI than 2.4GHz.

In addition the BSS ranking logic was re-worked and now 5GHz is
much more preferred, even at low RSSI. This means we need a
lower floor for RSSI before roaming, otherwise IWD would end
up roaming immediately after connecting due to low RSSI CQM
events.
2021-05-10 10:05:21 -05:00
James Prestwood 7b26a87d7a ie: fix ie_parse_data_rates to handle NULL
The code was partially there to handle NULL IEs but not
quite. If NULL IEs are passed in base the data rate totally
on the basic rate RSSI table.
2021-05-10 10:04:32 -05:00
James Prestwood 694ccf62d0 station: add Roam() diagnostics method
This is being added as a developer method and should not be used
in production. For testing purposes though, it is quite useful as
it forces IWD to roam to a provided BSS and bypasses IWD's roaming
and ranking logic for choosing a roam candidate.

To use this a BSSID is provided as the only parameter. If this
BSS is not in IWD's current scan results -EINVAL will be returned.
If IWD knows about the BSS it will attempt to roam to it whether
that is via FT, FT-over-DS, or Reassociation. These details are
still sorted out in IWDs station_transition_start() logic.
2021-05-07 08:45:42 -05:00
James Prestwood 174c14aefb main: add a --developer,-E option
This will enable developer features to be used. Currently the
only user of this will be StationDiagnostics.Roam() method which
should only be exposed in this mode.
2021-05-07 08:45:20 -05:00
Andrew Zaborowski a8736b8df8 main: Add D-Bus Daemon.GetInfo method
Expose the state directory/storage directory path on D-Bus because it
can't be known to clients until IWD runs, and client might need to
occasionally fiddle with the network config files.  While there also
expose the IWD version string, similar to how some other D-Bus services
do.
2021-05-07 08:41:21 -05:00
James Prestwood a3906272cc station: print reason why autoconnect failed 2021-05-04 10:30:55 -05:00
James Prestwood 8606bd6435 adhoc: set operstate on Start/Stop
Similar to 06aa84cca set the operstate when AdHoc is started and
stopped as it is no longer always set by netdev (only for station/p2p
interface types)
2021-04-30 20:07:19 -05:00
Denis Kenzior 29dd246f5e ap: Fix invalid length argument to ap_build_beacon_pr_head
Previously resp was a simple array of bytes allocated on the stack.
This was changed to a dynamically allocated array, but the sizeof(resp)
argument to ap_build_beacon_pr_head() was never changed appropriately.

Fix this by introducing a new resp_len variable that holds the number of
bytes allocated for resp.  Also, move the allocation after the basic
sanity checks have been performed to avoid allocating/freeing memory
unnecessarily.

Fixes: 18a63f91fd ("ap: Write extra frame IEs from the user")
2021-04-30 16:37:19 -05:00
James Prestwood e0f21ed293 netdev: set connected to false in netdev_reassociate
Commit 1fe5070 added a workaround for drivers which may send the
connect event prior to the connect callback/ack. This caused IWD
to fail to start eapol if reassociation was used due to
netdev_reassociate never setting netdev->connected = false.

netdev_reassociate uses the same code path as normal connections,
but when the connect callback came in connected was already set
to true which then prevents eapol from being registered. Then,
once the connect event comes in, there is no frame watch for
eapol and IWD doesn't respond to any handshake frames.
2021-04-30 16:21:35 -05:00
James Prestwood 486c859ad6 ft: netdev: add return value to tx_associate
Prior to this, an error sending the FT Reassociation was treated
as fatal, which is correct for FT-over-Air but not for FT-over-DS.
If the actual l_genl_family_send call fails for FT-over-DS the
existing connection can be maintained and there is no need to
call netdev_connect_failed.

Adding a return to the tx_associate function works for both FT
types. In the FT-over-Air case this return will ultimately get
sent back up to auth_proto_rx_authenticate in which case will
call netdev_connect_failed. For FT-over-DS tx_associate is
actually called from the 'start' operation which can fail and
still maintain the existing connection.
2021-04-30 13:09:53 -05:00
James Prestwood 1b5a58233c station: separate FT-over-DS stages
FT-over-DS was refactored to separate the FT action frame and
reassociation. From stations standpoint IWD needs to call
netdev_fast_transition_over_ds_action prior to actually roaming.
For now these two stages are being combined and the action
roam happens immediately after the action response callback.
2021-04-30 13:09:13 -05:00
James Prestwood c10b8d42e3 ft: netdev: refactor FT-over-DS into two stages
FT-over-DS followed the same pattern as FT-over-Air which worked,
but really limited how the protocol could be used. FT-over-DS is
unique in that we can authenticate to many APs by sending out
FT action frames and parsing the results. Once parsed IWD can
immediately Reassociate, or do so at a later time.

To take advantage of this IWD need to separate FT-over-DS into
two stages: action frame and reassociation.

The initial action frame stage is started by netdev. The target
BSS is sent an FT action frame and a new cache entry is created
in ft.c. Once the response is received the entry is updated
with all the needed data to Reassociate. To limit the record
keeping on netdev each FT-over-DS entry holds a userdata pointer
so netdev doesn't need to maintain its own list of data for
callbacks.

Once the action response is parsed netdev will call back signalling
the action frame sequence was completed (either successfully or not).
At this point the 'normal' FT procedure can start using the
FT-over-DS auth-proto.
2021-04-30 13:09:09 -05:00
Denis Kenzior 184b19c992 ap: Fix possible memleak of 'rates' 2021-04-30 11:38:04 -05:00
Denis Kenzior d973c347be ap: Fix l_settings leak
l_settings is leaked if l_settings_load_from_file() fails.
2021-04-30 11:36:19 -05:00
Denis Kenzior 84ca680611 netdev: Refine error handling in roam_event 2021-04-30 11:31:22 -05:00
Denis Kenzior f35a40c0c5 resolve: Simplify dbus_message error handling logic 2021-04-30 11:04:33 -05:00
James Prestwood 6c5fe246a7 netdev: separate over-air and over-ds netdev APIs 2021-04-30 09:59:46 -05:00
James Prestwood 0d45316891 ft: separate over-air from over-ds initializers 2021-04-30 09:59:31 -05:00
James Prestwood 37811a092c ft: create class for FT-over-DS targets
FT-over-DS is being separated into two independent stages. The
first of which is the processing of the action frame response.
This new class will hold all the parsed information from the action
frame and allowing it to be retrieved at a later time when IWD
needs to roam.

Initial info class should be created when the action frame is
being sent out. Once a response is received it can be parsed
with ft_over_ds_parse_action_response. This verifies the frame
and updates the ft_ds_info class with the parsed data.

ft_over_ds_prepare_handshake is the final step prior to
Reassociation. This sets all the stored IEs, anonce, and KH IDs
into the handshake and derives the new PTK.
2021-04-30 09:58:37 -05:00
James Prestwood 2c0234e161 ft: rework ft_parse_ies
This adds the RSNE verification to ft_parse_ies which will
be common between over-Air and over-DS. The MDE check was
also factored out into its own minimal function as to
retain the spec comment but allow reuse elsewhere.
2021-04-30 09:58:13 -05:00
Denis Kenzior 2697af428e nl80211cmd: Add additional command decoding 2021-04-29 21:37:38 -05:00
Denis Kenzior acbbedb9d3 netdev: Remove unused member 2021-04-29 12:56:51 -05:00
James Prestwood 0531e9ab08 station: remove diagnostic interface on station_free
If station gets removed ungracefully (e.g. rfkill/hotplug) it
may not have a chance to disconnect, meaning the diagnostic
interface would remain up.
2021-04-28 14:46:16 -05:00
James Prestwood 3b3f6d33fe station: tie diagnostic interface cleanup to DISCONNECTING
Prior to this the diagnostic interface was taken down when station
transitioned to DISCONNECTED. This worked but once station is in
a DISCONNECTING state it then calls netdev_disconnect(). Trying to
get any diagnostic data during this time may not work as its
unknown what state exactly the kernel is in. To be safe take the
interface down when station is DISCONNECTING.
2021-04-28 14:31:33 -05:00
Denis Kenzior dcfd0e2ade treewide: Get rid of non-ASCII characters 2021-04-28 14:16:06 -05:00
James Prestwood f4d515fc79 ft: expose ft_build_authenticate_ies
The building of the FT IEs for Action/Authenticate
frames will need to be shared between ft and netdev
once FT-over-DS is refactored.

The building was refactored to work off the callers
buffer rather than internal stack buffers. An argument
'new_snonce' was included as FT-over-DS will generate
a new snonce for the initial action frame, hence the
handshakes snonce cannot be used.
2021-04-28 13:49:35 -05:00
James Prestwood f3e4266add ft: factor out various parsing routines
Break up the rather large code block which parses out IEs,
verifies, and sets into the handshake. FT-over-DS needs these
steps broken up in order to parse the action frame response
without modifying the handshake.
2021-04-28 13:46:31 -05:00
James Prestwood 07fe995a5d netdev: add user_data to netdev_send_action_frame[v]
This makes this internal API a bit more usable by removing the
restriction of always having netdev as the user_data.
2021-04-28 13:35:21 -05:00
Denis Kenzior a0911ca778 station: Make sure roam_scan_id is always canceled
Under very rare circumstances the roaming scan triggered might not be
canceled properly.  This is because we issue the roam scan recursively
from within a scan callback and re-use the id of the scan for the
subsequent request.  The destroy callback is invoked right after the
callback and resets the id.  This leads to the scan not being canceled
properly in roam_state_clear().

src/netdev.c:netdev_mlme_notify() MLME notification Notify CQM(64)
src/station.c:station_roam_trigger_cb() 37
src/station.c:station_roam_scan() ifindex: 37
src/station.c:station_roam_trigger_cb() Using cached neighbor report for roam
...
src/scan.c:get_scan_done() get_scan_done
src/station.c:station_roam_failed() 37
src/station.c:station_roam_scan() ifindex: 37
src/scan.c:scan_request_triggered() Active scan triggered for wdev 22
^CTerminate
src/netdev.c:netdev_free() Freeing netdev wlan0[37]
src/device.c:device_free()
src/station.c:station_free()
...
Removing scan context for wdev 22
src/scan.c:scan_context_free() sc: 0x4a362a0
src/wiphy.c:wiphy_radio_work_done() Work item 14 done
==19542== Invalid write of size 4
==19542==    at 0x411500: station_roam_scan_destroy (station.c:2010)
==19542==    by 0x420B5B: scan_request_free (scan.c:156)
==19542==    by 0x410BAC: destroy_work (wiphy.c:294)
==19542==    by 0x410BAC: wiphy_radio_work_done (wiphy.c:1613)
==19542==    by 0x46C66E: l_queue_clear (queue.c:107)
==19542==    by 0x46C6B8: l_queue_destroy (queue.c:82)
==19542==    by 0x420BAE: scan_context_free (scan.c:205)
==19542==    by 0x424135: scan_wdev_remove (scan.c:2272)
==19542==    by 0x408754: netdev_free (netdev.c:847)
==19542==    by 0x40E18C: netdev_shutdown (netdev.c:5773)
==19542==    by 0x404756: iwd_shutdown (main.c:78)
==19542==    by 0x404756: iwd_shutdown (main.c:65)
==19542==    by 0x470E21: handle_callback (signal.c:78)
==19542==    by 0x470E21: signalfd_read_cb (signal.c:104)
==19542==    by 0x47166B: io_callback (io.c:120)
==19542==  Address 0x4d81f98 is 200 bytes inside a block of size 288 free'd
==19542==    at 0x48399CB: free (vg_replace_malloc.c:538)
==19542==    by 0x47F3E5: interface_instance_free (dbus-service.c:510)
==19542==    by 0x481DEA: _dbus_object_tree_remove_interface (dbus-service.c:1694)
==19542==    by 0x481F1C: _dbus_object_tree_object_destroy (dbus-service.c:795)
==19542==    by 0x40894F: netdev_free (netdev.c:844)
==19542==    by 0x40E18C: netdev_shutdown (netdev.c:5773)
==19542==    by 0x404756: iwd_shutdown (main.c:78)
==19542==    by 0x404756: iwd_shutdown (main.c:65)
==19542==    by 0x470E21: handle_callback (signal.c:78)
==19542==    by 0x470E21: signalfd_read_cb (signal.c:104)
==19542==    by 0x47166B: io_callback (io.c:120)
==19542==    by 0x47088C: l_main_iterate (main.c:478)
==19542==    by 0x47095B: l_main_run (main.c:525)
==19542==    by 0x47095B: l_main_run (main.c:507)
==19542==    by 0x470B6B: l_main_run_with_signal (main.c:647)
==19542==  Block was alloc'd at
==19542==    at 0x483879F: malloc (vg_replace_malloc.c:307)
==19542==    by 0x46AB2D: l_malloc (util.c:62)
==19542==    by 0x416599: station_create (station.c:3448)
==19542==    by 0x406D55: netdev_newlink_notify (netdev.c:5324)
==19542==    by 0x46D4BC: l_hashmap_foreach (hashmap.c:612)
==19542==    by 0x472F46: process_broadcast (netlink.c:158)
==19542==    by 0x472F46: can_read_data (netlink.c:279)
==19542==    by 0x47166B: io_callback (io.c:120)
==19542==    by 0x47088C: l_main_iterate (main.c:478)
==19542==    by 0x47095B: l_main_run (main.c:525)
==19542==    by 0x47095B: l_main_run (main.c:507)
==19542==    by 0x470B6B: l_main_run_with_signal (main.c:647)
==19542==    by 0x403EDB: main (main.c:490)
==19542==
2021-04-28 13:15:45 -05:00
James Prestwood 06aa84ccaf ap: set link/operstate on AP start/stop
Prior to this netdev_connect_ok set setting this which really
only applies to station mode. In addition this happens for each
new station that connects to the AP. Instead set the operstate /
link mode when AP starts and stops.
2021-04-28 11:29:51 -05:00
James Prestwood e0ffd94832 netdev: only call connect_ok in station/p2p_client mode
netdev_connect_ok is only for station/p2p_client modes but AP
also ends up on the same code path. Check the iftype before
calling netdev_connect_ok.
2021-04-28 11:29:43 -05:00
Andrew Zaborowski e148e1ea99 eap: Print a hint if Identity is likely wrong 2021-04-28 11:27:14 -05:00
Andrew Zaborowski 694799c9c2 ap: Deduplicate writing authorized MACs into wsc_* structs 2021-04-28 11:26:42 -05:00
Andrew Zaborowski ca9895692a doc: Update iwd.ap(5) man page
Try to document some of the settings moved from struct ap_config to the
settings object now passed to ap_start(), skip the strictly internal-use
ones.
2021-04-28 11:25:46 -05:00
Andrew Zaborowski 5cc0f68d51 doc: Clarify settings in iwd.ap(5)
Change some of the wording, add some references and more specific syntax
information (time units, IP list separator character, etc.)
2021-04-28 11:25:46 -05:00
Andrew Zaborowski ab6cd7e465 ap: Drop struct ap_config in favor of l_settings
Change ap_start to load all of the AP configuration from a struct
l_settings, moving the 6 or so parameters from struct ap_config members
to the l_settings groups and keys.  This extends the ap profile concept
used for the DHCP settings.  ap_start callers create the l_settings
object and fill the values in it or read the settings in from a file.

Since ap_setup_dhcp and ap_load_profile_and_dhcp no longer do the
settings file loading, they needed to be refactored and some issues were
fixed in their logic, e.g. l_dhcp_server_set_ip_address() was never
called when the "IP pool" was used.  Also the IP pool was previously only
used if the ap->config->profile was NULL and this didn't match what the
docs said:
"If [IPv4].Address is not provided and no IP address is set on the
interface prior to calling StartProfile the IP pool will be used."
2021-04-28 11:25:46 -05:00
James Prestwood 11914431bc netdev: zero out diagnostic info
The info struct is on the stack which leads to the potential
for uninitialized data access. Zero out the info struct prior
to calling the get station callback:

==141137== Conditional jump or move depends on uninitialised value(s)
==141137==    at 0x458A6F: diagnostic_info_to_dict (diagnostic.c:109)
==141137==    by 0x41200B: station_get_diagnostic_cb (station.c:3620)
==141137==    by 0x405BE1: netdev_get_station_cb (netdev.c:4783)
==141137==    by 0x4722F9: process_unicast (genl.c:994)
==141137==    by 0x4722F9: received_data (genl.c:1102)
==141137==    by 0x46F28B: io_callback (io.c:120)
==141137==    by 0x46E5AC: l_main_iterate (main.c:478)
==141137==    by 0x46E65B: l_main_run (main.c:525)
==141137==    by 0x46E65B: l_main_run (main.c:507)
==141137==    by 0x46E86B: l_main_run_with_signal (main.c:647)
==141137==    by 0x403EA8: main (main.c:490)
2021-04-28 11:24:13 -05:00
Denis Kenzior 8cb61f9aae diagnostic: Fix crash with Open networks
It isn't safe to return a NULL from diagnostic_akm_suite_to_security()
since the value is used directly.  Also, if the AKM suite is 0, this
implies that the network is an Open network and not some unknown AKM.

==17982== Invalid read of size 1
==17982==    at 0x483BC92: strlen (vg_replace_strmem.c:459)
==17982==    by 0x47DE60: _dbus1_builder_append_basic (dbus-util.c:981)
==17982==    by 0x41ACB2: dbus_append_dict_basic (dbus.c:197)
==17982==    by 0x412050: station_get_diagnostic_cb (station.c:3614)
==17982==    by 0x405B19: netdev_get_station_cb (netdev.c:4801)
==17982==    by 0x47436E: process_unicast (genl.c:994)
==17982==    by 0x47436E: received_data (genl.c:1102)
==17982==    by 0x470FBB: io_callback (io.c:120)
==17982==    by 0x4701DC: l_main_iterate (main.c:478)
==17982==    by 0x4702AB: l_main_run (main.c:525)
==17982==    by 0x4702AB: l_main_run (main.c:507)
==17982==    by 0x4704BB: l_main_run_with_signal (main.c:647)
==17982==    by 0x403EDB: main (main.c:490)
==17982==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==17982==
Aborting (signal 11) [/home/denkenz/iwd/src/iwd]
++++++++ backtrace ++++++++
0  0x488a550 in /lib64/libc.so.6
1  0x483bc92 in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
2  0x47de61 in _dbus1_builder_append_basic() at ell/dbus-util.c:983
3  0x41acb3 in dbus_append_dict_basic() at src/dbus.c:197
4  0x412051 in station_get_diagnostic_cb() at src/station.c:3618
5  0x405b1a in netdev_get_station_cb() at src/netdev.c:4801
2021-04-28 11:19:38 -05:00
Denis Kenzior 1c9a736ed5 netconfig: Cancel outstanding rtnl commands
It is possible for the RTNL command callback to come after
netconfig_reset or netconfig_destroy has been called.  Make sure that
any outstanding commands that might access the netconfig object are
canceled.

src/netconfig.c:netconfig_ipv4_dhcp_event_handler() DHCPv4 event 0
src/netconfig.c:netconfig_ifaddr_added() wlan0: ifaddr 192.168.1.55/24 broadcast 192.168.1.255
^CTerminate
src/netdev.c:netdev_free() Freeing netdev wlan0[15]
src/device.c:device_free()
src/station.c:station_free()
src/netconfig.c:netconfig_destroy()
src/netconfig.c:netconfig_reset()
src/netconfig.c:netconfig_reset_v4() 16
src/netconfig.c:netconfig_reset_v4() Stopping client
Removing scan context for wdev c
src/scan.c:scan_context_free() sc: 0x4a3cc10
==12792== Invalid read of size 8
==12792==    at 0x43BF5A: netconfig_route_add_cmd_cb (netconfig.c:600)
==12792==    by 0x4727FA: process_message (netlink.c:181)
==12792==    by 0x4727FA: can_read_data (netlink.c:289)
==12792==    by 0x470F4B: io_callback (io.c:120)
==12792==    by 0x47016C: l_main_iterate (main.c:478)
==12792==    by 0x47023B: l_main_run (main.c:525)
==12792==    by 0x47023B: l_main_run (main.c:507)
==12792==    by 0x47044B: l_main_run_with_signal (main.c:647)
==12792==    by 0x403EDB: main (main.c:490)
2021-04-28 11:19:34 -05:00
Denis Kenzior e5550ed58f netdev: Detect netdev going down early
In case the netdev is brought down while we're trying to connect, try to
detect this and fail early instead of trying to send additional
commands.

src/station.c:station_enter_state() Old State: disconnected, new state: connecting
src/station.c:station_netdev_event() Associating
src/netdev.c:netdev_mlme_notify() MLME notification Connect(46)
src/netdev.c:netdev_connect_event()
src/netdev.c:netdev_link_notify() event 16 on ifindex 4
src/eapol.c:eapol_handle_ptk_1_of_4() ifindex=4
src/netdev.c:netdev_link_notify() event 16 on ifindex 4
src/eapol.c:eapol_handle_ptk_3_of_4() ifindex=4
src/netdev.c:netdev_set_gtk() 4
src/station.c:station_handshake_event() Setting keys
src/netdev.c:netdev_set_tk() 4
src/netdev.c:netdev_set_rekey_offload() 4
New Key for Group Key failed for ifindex: 4:Network is down
src/netdev.c:netdev_link_notify() event 16 on ifindex 4
src/station.c:station_free()
src/netdev.c:netdev_mlme_notify() MLME notification Disconnect(48)
src/netdev.c:netdev_disconnect_event()
src/wiphy.c:wiphy_reg_notify() Notification of command Reg Change(36)
src/wiphy.c:wiphy_update_reg_domain() New reg domain country code for (global) is XX
src/netdev.c:netdev_link_notify() event 16 on ifindex 4
src/wiphy.c:wiphy_reg_notify() Notification of command Reg Change(36)
src/wiphy.c:wiphy_update_reg_domain() New reg domain country code for (global) is DE
src/wiphy.c:wiphy_radio_work_done() Work item 14 done
src/station.c:station_connect_cb() 4, result: 4
Segmentation fault
2021-04-27 17:33:37 -05:00
Denis Kenzior 775f4643b5 netdev: Move disconnect_cmd_id reset
This operation logically belongs in the callback, not a common operation
that is also invoked from event handlers.
2021-04-27 16:16:09 -05:00
James Prestwood 9d9c516596 wiphy: add fils_hint to wiphy_can_connect
A prior commit refactored the AKM selection in wiphy.c. This
ended up breaking FILS tests due to the hard coding of a
false fils_hint in wiphy_select_akm. Since our FILS tests
only advertise FILS AKMs wiphy_can_connect would return false
for these networks.

Similar to wiphy_select_akm, add a fils hint parameter to
wiphy_can_connect and pass that down directly to wiphy_select_akm.
2021-04-27 14:48:23 -05:00
James Prestwood bba47527d3 station: update to use network_has_erp_identity 2021-04-27 14:48:09 -05:00
James Prestwood 936542fa79 network: copy station_has_erp_identity
This API is internal to station, but acts only on the network
object so it is being moved into network.c and exposed.
2021-04-27 14:47:16 -05:00
Denis Kenzior 1fe5070666 netdev: Work around CMD_CONNECT behavior on mwifiex 2021-04-27 14:00:24 -05:00
Denis Kenzior 337f5e062e netdev: Return -ENOTCONN in netdev_get_current_station 2021-04-27 10:22:46 -05:00
Denis Kenzior 654154e721 network: ensure passphrase is valid when psk is set
If PreSharedKey is set, the current logic does not validate the
Passphrase beyond its existence.  This can lead to strange situations
where an invalid WPA3-PSK passphrase might get used.  This can of course
only happen if the user (as root) or NetworkManager-iwd-backend writes
such a file incorrectly.
2021-04-27 09:34:22 -05:00
Andrew Zaborowski 8d58f5b679 wscutil: Move DeviceType parsing from p2p & eap-wsc to a function
Move the WSC Primary Device Type parsing from p2p.c and eap-wsc.c to a
common function in wscutil.c supporting both formats so that it can be
used in ap.c too.
2021-04-26 10:48:03 -05:00
Andrew Zaborowski 0ad463742b p2p,netdev: Fix event name typo in comments
Fix the spelling of NETDEV_RESULT_KEY_SETTING_FAILED in two comments.
2021-04-26 10:47:59 -05:00
Denis Kenzior 4a1dafb907 station: Move AP directed roam watch to station
Logically this frame watch belongs in station.  It was kept in device.c
for the purported reason that the station object was removed with
ifdown/ifup changes and hence the frame watch might need to be removed
and re-added unnecessarily.  Since the kernel does not actually allow to
unregister a frame watch (only when the netdev is removed or its iftype
changes), re-adding a frame watch might trigger a -EALREADY or similar
error.

Avoid this by registering the frame watch when a new netdev is detected
in STATION mode, or when the interface type changes to STATION.
2021-04-23 09:51:46 -05:00
Denis Kenzior a83bb33ea5 rrm: React to IFTYPE_CHANGE events
If a netdev iftype is changed, all frame registrations are removed.
Make sure to re-register for the appropriate frame notifications in case
our iftype is switched back to 'station'.  In any other iftype, no frame
watches are registered and rrm_state object is effectively dormant.
2021-04-23 09:51:46 -05:00
Denis Kenzior 5e0069e146 rrm: Always create RRM state
Right now, RRM is created when a new netdev is detected and its iftype
is of type station.  That means that any devices that start their life
as any other iftype cannot be changed to a station and have RRM function
properly.  Fix that by always creating the RRM state regardless of the
initial iftype.
2021-04-23 09:51:46 -05:00
Denis Kenzior 23249c85c7 netdev: Add new iftype change event 2021-04-23 09:51:46 -05:00
Denis Kenzior 0611632d7b rrm: Track that station is removed
In the case that a netdev is powered down, or an interface type change
occurs, the station object will be removed and any watches will be
freed.

Since rrm is created when the netdev is created and persists across
iftype and power up/down changes, it should provide a destroy callback
to station_add_state_watch so that it can be notified when the watch is
removed.
2021-04-23 09:51:46 -05:00
Denis Kenzior 4fa2ce2cbe netdev: Re-add frame watches on iftype change
If the iftype changes, kernel silently wipes out any frame registrations
we may have registered.  Right now, frame registrations are only done when
the interface is created.  This can result in frame watches not being
added if the interface type is changed between station mode to ap mode
and then back to station mode, e.g.:

device wlan0 set-property Mode ap
device wlan0 set-property Mode station

Make sure to re-add frame registrations according to the mode if the
interface type is changed.
2021-04-23 09:51:46 -05:00
Denis Kenzior b8ef64f6e3 frame-xchg: iftype changes to be managed by netdev
Since netdev now keeps track of iftype changes, let it call
frame_watch_wdev_remove on netdevs that it manages to clear frame
registrations that should be cleared due to an iftype change.

Note that P2P_DEVICE wdevs are not managed by any netdev object, but
since their iftype cannot be changed, they should not be affected
by this change.
2021-04-23 09:51:46 -05:00
Denis Kenzior 7a2719f314 netdev: Track SET_INTERFACE events
And set the interface type based on the event rather than the command
callback.  This allows us to track interface type changes even if they
come from outside iwd (which shouldn't happen.)
2021-04-23 09:51:46 -05:00
James Prestwood d42549e46d netdev: move prepare_ft call which broke FT
The prepare_ft patch was an intermediate to a full patch
set and was not fully tested stand alone. Its placement
actually broke FT due to handshake->aa getting overwritten
prior to netdev->prev_bssid being copied out. This caused
FT to fail with "transport endpoint not connected (-107)"
2021-04-22 13:25:23 -05:00
James Prestwood f98ddf2201 netdev: print error number on CMD_FRAME failure 2021-04-22 13:25:23 -05:00
Denis Kenzior 45dd5d2f7c frame-xchg: Make debugs a bit more useful
- Make sure to print the cookie information
- Don't print messages for frames we're not interested in.  This is
  particularly helpful when running auto-tests since frame acks from
  hostapd pollute the iwd log.
2021-04-21 11:03:55 -05:00
Denis Kenzior ea324a7959 netdev: Fix connections to open networks
Fix a regression where connection to an open network results in an
NotSupported error being returned.

Fixes: d79e883e93 ("netdev: Introduce connection types")
2021-04-20 10:45:25 -05:00
Denis Kenzior 61d0abe910 netdev: Move iftype_to_string utility
Move and rename this utility into netdev_iftype_to_string away from
dbus.c.  This also allows us to drop including nl80211.h in dbus.c
2021-04-20 09:37:48 -05:00
Denis Kenzior 6096d8895d netdev: Mirror nl80211.h iftype enum values
This makes conversions simpler.  Also fixes a bug where P2P devices were
printed with an incorrect Mode value since dbus_iftype_to_string was
assuming that an iftype as defined in nl80211.h was being passed in,
while netdev was returning an enum value defined in netdev.h.
2021-04-20 09:37:48 -05:00
Denis Kenzior 89b3d34dd3 ie: Fix IE_AKM_IS_FILS macro
Fixes: e30345d699 ("ie: Add IE_AKM_IS_FILS macro")
2021-04-20 09:37:48 -05:00
Denis Kenzior d3eef8b56a netdev: Move netdev finding to a common function 2021-04-16 14:47:48 -05:00
James Prestwood 9bbe14e7a3 netdev: factor out FT handshake preparation
This isolates the handshake/nhs preparation for
FT into its own function to be used by both
FT-over-Air and FT-over-DS after refactoring.
2021-04-16 11:32:55 -05:00
James Prestwood 726a12461f ft: separate ft_sm from ft_process_ies
To prepare for some refactoring remove the ft_sm dependency
from ft_process_ies and instead only make it depend on the
handshake_state object.
2021-04-16 11:13:46 -05:00
James Prestwood b276e3f590 ap: remove rates requirement for fmac cards
It was seen that some full mac cards/drivers do not include any
rate information with the NEW_STATION event. This was causing
the NEW_STATION event to be ignored, preventing AP mode from
working on these cards.

Since the full mac path does not even require sta->rates the
parsing can be removed completely.
2021-04-12 14:15:18 -05:00