Commit Graph

3230 Commits

Author SHA1 Message Date
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
James Prestwood d04ab5ad96 agent: call back even if agent disconnects
It was found that if the user cancels/disconnects the agent prior to
entering credentials, IWD would get stuck and could no longer accept
any connect calls with the error "Operation already in progress".
For example exiting iwctl in the Password prompt would cause this:

iwctl
$ station wlan0 connect myssid
$ Password: <Ctrl-C>

This was due to the agent never calling the network callback in the
case of an agent disconnect. Network would wait indefinitely for the
credentials, and disallow any future connect attempts.

To fix this agent_finalize_pending can be called in agent_disconnect
with a NULL reply which behaves the same as if there was an
internal timeout and ultimately allows network to fail the connection
2021-04-09 11:36:08 -05:00
James Prestwood 379ec4b952 netdev: implement netdev_set_pmk
The 8021x offloading procedure still does EAP in userspace which
negotiates the PMK. The kernel then expects to obtain this PMK
from userspace by calling SET_PMK. This then allows the firmware
to begin the 4-way handshake.

Using __eapol_install_set_pmk_func to install netdev_set_pmk,
netdev now gets called into once EAP finishes and can begin
the final userspace actions prior to the firmware starting
the 4-way handshake:

 - SET_PMK using PMK negotiated with EAP
 - Emit SETTING_KEYS event
 - netdev_connect_ok

One thing to note is that the kernel provides no way of knowing if
the 4-way handshake completed. Assuming SET_PMK/SET_STATION come
back with no errors, IWD assumes the PMK was valid. If not, or
due to some other issue in the 4-way, the kernel will send a
disconnect.
2021-04-09 11:33:20 -05:00
James Prestwood 026ec40e1c netdev: add CONNECTION_TYPE_8021X_OFFLOAD
This adds a new type for 8021x offload as well as support in
building CMD_CONNECT.

As described in the comment, 8021x offloading is not particularly
similar to PSK as far as the code flow in IWD is concerned. There
still needs to be an eapol_sm due to EAP being done in userspace.
This throws somewhat of a wrench into our 'is_offload' cases. And
as such this connection type is handled specially.
2021-04-09 11:32:34 -05:00
James Prestwood 93b49a72ac eapol: add PMK installer support
802.1x offloading needs a way to call SET_PMK after EAP finishes.
In the same manner as set_tk/gtk/igtk a new 'install_pmk' function
was added which eapol can call into after EAP completes.
2021-04-09 11:32:21 -05:00
Denis Kenzior 3284ed4e8e eapol: Work around an apparent GCC 8.3 bug
With GCC 8.3 on Rasberry Pi, iwd sends invalid EAPoL 1_of_4 packets:

< PAE: len 99                                                          8.785095
    Interface Index: 27
    EAPoL: len 99
        Protocol Version: 2 (802.1X-2004)
        Type: 3 (Key)
        Length: 95
        Checking mic len 16
        Frame len 99
        key data len 22
        Checking mic len 24
        Frame len 107
        Bad MIC len, malformed packet?
        02 03 00 5f 02 00 8a 00 10 00 00 00 00 00 00 00  ..._............
        02 94 40 a3 da c3 2b aa b7 a6 a5 5f 25 0a ae 74  ..@...+...._%..t
        b0 8d e2 62 9c 90 c9 e9 fd a5 33 1b e1 b4 9b 81  ...b......3.....
        42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  B...............
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        00 00 16

The trouble seems to be that eapol_key_data_append() correctly sets the
key_data_length field (the last 2 bytes of the message), but the actual
packet_length is not being set properly.

Dropping to O0 optimization level results in GCC correctly computing
the packet length.
2021-04-07 16:47:40 -05:00
James Prestwood 6c9f72380d netdev: use l_idle_create for disconnect idle
The chances were extremely low, but using l_idle_oneshot
could end up causing a invalid memory access if the netdev
went down while waiting for the disconnect idle callback.

Instead netdev can keep track of the idle with l_idle_create
and remove it if the netdev goes down prior to the idle callback.
2021-04-06 12:32:30 -05:00
James Prestwood 51fc2453ba netdev: fix spelling error 2021-04-05 17:49:36 -05:00
James Prestwood 135ad0880e sae: remove authenticate timeout handler
This fixes an infinite loop issue when authenticate frames time
out. If the AP is not responding IWD ends up retrying indefinitely
due to how SAE was handling this timeout. Inside sae_auth_timeout
it was actually sending another authenticate frame to reject
the SAE handshake. This, again, resulted in a timeout which called
the SAE timeout handler and repeated indefinitely.

The kernel resend behavior was not taken into account when writing
the SAE timeout behavior and in practice there is actually no need
for SAE to do much of anything in response to a timeout. The
kernel automatically resends Authenticate frames 3 times which mirrors
IWDs SAE behavior anyways. Because of this the authenticate timeout
handler can be completely removed, which will cause the connection
to fail in the case of an autentication timeout.
2021-04-05 17:47:42 -05:00
James Prestwood fc4739f2db netdev: fix crash from carefully timed Connect()
This crash was caused from the disconnect_cb being called
immediately in cases where send_disconnect was false. The
previous patch actually addressed this separately as this
flag was being set improperly which will, indirectly, fix
one of the two code paths that could cause this crash.

Still, there is a situation where send_disconnect could
be false and in this case IWD would still crash. If IWD
is waiting to queue the connect item and netdev_disconnect
is called it would result in the callback being called
immediately. Instead we can add an l_idle as to allow the
callback to happen out of scope, which is what station
expects.

Prior to this patch, the crashing behavior can be tested using
the following script (or some variant of it, your system timing
may not be the same as mine).

iwctl station wlan0 disconnect
iwctl station wlan0 connect <network1> &
sleep 0.02
iwctl station wlan0 connect <network2>

++++++++ backtrace ++++++++
0  0x7f4e1504e530 in /lib64/libc.so.6
1  0x432b54 in network_get_security() at src/network.c:253
2  0x416e92 in station_handshake_setup() at src/station.c:937
3  0x41a505 in __station_connect_network() at src/station.c:2551
4  0x41a683 in station_disconnect_onconnect_cb() at src/station.c:2581
5  0x40b4ae in netdev_disconnect() at src/netdev.c:3142
6  0x41a719 in station_disconnect_onconnect() at src/station.c:2603
7  0x41a89d in station_connect_network() at src/station.c:2652
8  0x433f1d in network_connect_psk() at src/network.c:886
9  0x43483a in network_connect() at src/network.c:1183
10 0x4add11 in _dbus_object_tree_dispatch() at ell/dbus-service.c:1802
11 0x49ff54 in message_read_handler() at ell/dbus.c:285
12 0x496d2f in io_callback() at ell/io.c:120
13 0x495894 in l_main_iterate() at ell/main.c:478
14 0x49599b in l_main_run() at ell/main.c:521
15 0x495cb3 in l_main_run_with_signal() at ell/main.c:647
16 0x404add in main() at src/main.c:490
17 0x7f4e15038b25 in /lib64/libc.so.6
2021-04-05 17:23:41 -05:00
James Prestwood d008b93444 netdev: add check for running work item in netdev_disconnect
The send_disconnect flag was being improperly set based only
on connect_cmd_id being zero. This does not take into account
the case of CMD_CONNECT having finished but not EAPoL. In this
case we do need to send a disconnect.
2021-04-05 17:23:28 -05:00
James Prestwood 1c0b001b53 wiphy: add wiphy_radio_work_is_running
This provides a way to know if a work item is actually running
vs only been queued and waiting to run.
2021-04-05 16:58:43 -05:00
James Prestwood 9e412f9fdd netdev: allow PSK offload for FT AKMs
This adds a new connection type, TYPE_PSK_OFFLOAD, which
allows the 4-way handshake to be offloaded by the firmware.
Offloading will be used if the driver advertises support.

The CMD_ROAM event path was also modified to take into account
handshake offloading. If the handshake is offloaded we still
must issue GET_SCAN, but not start eapol since the firmware
takes care of this.
2021-04-02 17:24:03 -05:00
James Prestwood f5c5efa033 wiphy: allow FT AKM to be used if Auth/Assoc is not supported
Until now FT was only supported via Auth/Assoc commands which barred
any fullmac cards from using FT AKMs. With PSK offload support these
cards can do FT but only when offloading is used.
2021-04-02 17:23:07 -05:00
James Prestwood 81e3dc6ae6 netdev: fix CMD_ROAM for open networks
In the FW scan callback eapol was being stared unconditionally which
isn't correct as roaming on open networks is possible. Instead check
that a SM exists just like is done in netdev_connect_event.
2021-04-02 17:18:12 -05:00
James Prestwood 44625373bc netdev: better handle disconnect after FW scan
This should have been updated along with the connect and roam
event separation. Since netdev_connect_event is not being
re-used for CMD_ROAM the comment did not make sense anymore.
Still, there needs to be a check to ensure we were not disconnected
while waiting for GET_SCAN to come back.
2021-04-02 17:18:02 -05:00
James Prestwood 0d6b572ca5 netdev: separate netdev_{roam,connect}_event
netdev_connect_event was being reused for parsing of CMD_ROAM
attributes which made some amount of sense since these events
are nearly identical, but due to the nature of firmware roaming
there really isn't much IWD needs to parse from CMD_ROAM. In
addition netdev_connect_event was getting rather complicated
since it had to handle both CMD_ROAM and CMD_CONNECT.

The only bits of information IWD needs to parse from CMD_ROAM
is the roamed BSSID, authenticator IEs, and supplicant IEs. Since
this is so limited it now makes little sense to reuse the entire
netdev_connect_event function, and intead only parse what is
needed for CMD_ROAM.
2021-04-02 13:04:45 -05:00
James Prestwood c390deafcb netdev: move request IE parsing into function
Moves the parsing of NL80211_ATTR_REQ_IE into its own parsing
function for use elsewhere.
2021-04-02 13:04:19 -05:00
Denis Kenzior ca085d799d station: Do not set or use the offload bit
station should be isolated as much as possible from the details of the
driver type and how a particular AKM is handled under the hood.  It will
be up to wiphy to pick the best AKM for a given bss.  netdev in turn
will pick how to drive the particular AKM that was picked.
2021-03-31 11:27:10 -05:00
Denis Kenzior d79e883e93 netdev: Introduce connection types
Currently netdev handles SoftMac and FullMac drivers mostly in the same
way, by building CMD_CONNECT nl80211 commands and letting the kernel
figure out the details.  Exceptions to this are FILS/OWE/SAE AKMs which
are only supported on SoftMac drivers by using
CMD_AUTHENTICATE/CMD_ASSOCIATE.

Recently, basic support for SAE (WPA3-Personal) offload on FullMac cards
was introduced.  When offloaded, the control flow is very different than
under typical conditions and required additional logic checks in several
places.  The logic is now becoming quite complex.

Introduce a concept of a connection type in order to make it clearer
what driver and driver features are being used for this connection.  In
the future, connection types can be expanded with 802.1X handshake
offload, PSK handshake offload and CMD_EXTERNAL_AUTH based SAE
connections.
2021-03-31 10:48:05 -05:00
Denis Kenzior e30345d699 ie: Add IE_AKM_IS_FILS macro 2021-03-31 10:05:55 -05:00
Denis Kenzior fa3fad37ce ie: Ad IE_AKM_IS_FT 2021-03-31 10:05:44 -05:00
James Prestwood b5b815ef16 wiphy: Use wiphy_select_akm in wiphy_can_connect
Commit 6e8b76527 added a switch statement for AKM suites which
was not correct as this is a bitmask and may contain multiple
values. Intead we can rely on wiphy_select_akm which is a more
robust check anyways.

Fixes: 6e8b765278 ("wiphy: add check for CMD_AUTH/CMD_ASSOC support")
2021-03-30 17:29:04 -05:00
James Prestwood 19ce2d86dd netdev: remove unneeded goto/return code
All possible paths led to the same result so it was
simplified to remove two goto's and a return call.
2021-03-29 15:48:50 -05:00
James Prestwood a04d4423f8 sae: add counter for associate retries
If there is an associate timeout, retry a few times in case
it was just a fluke. At this point SAE is fully negotiated
so it makes sense to attempt to save the connection.
2021-03-29 15:48:50 -05:00
James Prestwood 90485cb2ee netdev: better handle associate timeouts with auth_protos
Any auth proto which did not implement the assoc_timeout handler
could end up getting 'stuck' forever if there was an associate
timeout. This is because in the event of an associate timeout IWD
only sets a few flags and relies on the connect event to actually
handle the failure. The problem is a connect event never comes
if the failure was a timeout.

To fix this we can explicitly fail the connection if the auth
proto has not implemented assoc_timeout or if it returns false.
2021-03-29 15:48:50 -05:00
James Prestwood 28a7dd7fba station: get neighbor report after roaming
In the same vein as requesting a neighbor report after
connecting for the first time, it should also be done
after a roam to obtain the latest neighbor information.
2021-03-29 14:12:02 -05:00
James Prestwood 9b682d43db station: unify firmware/normal roaming
This doesn't change much functionally but does unify the
two roaming paths by ending with 'station_roamed()'.
2021-03-29 14:11:45 -05:00
James Prestwood 21e95dd2d8 station: clear out roam frequencies after roam 2021-03-29 14:11:37 -05:00
James Prestwood c2330c5332 station: add Security key to GetDiagnostics 2021-03-29 13:18:01 -05:00
James Prestwood 2c2c1e3ebf diagnostic: add diagnostic_akm_suite_to_security
Converts ie_rsn_akm_suite values (and WPA1 hint) into a more
human readable security string such as:

WPA2-Personal, WPA3-Personal, WPA2-Personal + FT etc.
2021-03-29 13:17:36 -05:00
Denis Kenzior e730baac4a station: Make sure to reset scanning property
When we cancel a quick scan that has already been triggered, the
Scanning property is never reset to false.  This doesn't fully reflect
the actual scanning state of the hardware since we don't (yet) abort
the scan, but at least corrects the public API behavior.

{Network} [/net/connman/iwd/0/7/73706733_psk] Connected = False
{Station} [/net/connman/iwd/0/7] Scanning = True
{Station} [/net/connman/iwd/0/7] State = connecting
{Station} [/net/connman/iwd/0/7] ConnectedNetwork =
/net/connman/iwd/0/7/73706733_psk
{Network} [/net/connman/iwd/0/7/73706733_psk] Connected = True
2021-03-29 10:44:02 -05:00
Denis Kenzior 9a67a21bd2 station: Add a warning of rekey fails 2021-03-24 13:10:32 -05:00
Denis Kenzior d958239da9 eapol: Don't ignore EAPoL protocol version 2010
Some newer Cisco APs seem to send this protocol version by default
2021-03-22 17:47:53 -05:00
James Prestwood 73b247d72f netdev: prevent crash with open networks
The SAE offload changes assumed a handshake object would
exist in netdev, which is not the case for open networks.
2021-03-22 17:46:05 -05:00
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 b17f27f04d netdev: add SAE offload support
SAE offload support requires some minor tweaks to CMD_CONNECT
as well as special checks once the connect event comes in. Since
at this point we are fully connected.
2021-03-22 14:15:56 -05:00
James Prestwood edad26b4be handshake: add offload flag
If true, this flag indicates the handshake is being offloaded to
the kernel/hardware.
2021-03-22 14:15:44 -05:00
James Prestwood 997c54f185 wiphy: check SAE offload in wiphy_can_connect
This allows this wiphy_can_connect to pass for an SAE BSS
if the hardware does not support user space SAE, but does
support SAE offload.
2021-03-22 14:14:16 -05:00
James Prestwood 3e3ef284de wiphy: check SAE offload in wiphy_select_akm
This allows an SAE AKM to be selected if the hardware does not
support SAE in userspace, but does support SAE offload.
2021-03-22 14:12:50 -05:00
James Prestwood af3d0d21a0 wiphy: add getter for 'supports_cmds_auth_assoc' 2021-03-22 14:12:32 -05:00
James Prestwood 5033b5a24d netdev: parse SIGNAL_AVG when building diagnostics object 2021-03-16 11:25:53 -05:00
James Prestwood fb0a1fba2a diagnostic: include AverageRSSI in GetDiagnostics 2021-03-16 11:25:39 -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 4577ee01f2 network: replace l_queue_get_entries loop
After adding network_bss_update, network now has a match_addr
queue function which can be used to replace an unneeded
l_queue_get_entries loop with l_queue_find.
2021-03-15 14:47:30 -05:00
James Prestwood 88d0a6a7c0 network: add network_bss_update
This will swap out a scan_bss object with a duplicate that may
exist in a networks bss_list. The duplicate will be removed by
since the object is owned by station it is assumed that it will
be freed elsewhere.
2021-03-15 14:47:07 -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 2a46ab3042 wiphy: parse NL80211_ATTR_ROAM_SUPPORT flag
This tells us if the hardware is going to automatically
roam. We need this to know if station roaming logic should
be disabled.
2021-03-15 13:32:08 -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 e8c87c8b42 scan: add scan_get_firmware_scan
Adds support for getting firmware scan results from the kernel.
This is intended to be used after the firmware roamed automatically
and the scan result is require for handshake initialization.

The scan 'request' is competely separate from the normal scan
queue, though scan_results, scan_request, and the scan_context
are all used for consistency and code reuse.
2021-03-15 13:14:16 -05:00
Denis Kenzior 0c0d9e5696 iwd: Use test_bit from ell 2021-03-12 13:49:23 -06:00
Denis Kenzior f51025e143 util: Remove unused util_bit_field 2021-03-11 22:35:13 -06:00
Denis Kenzior 74ec6530cb eap-pwd: Use bit_field from ell 2021-03-11 22:35:03 -06:00
Denis Kenzior 113c1086e2 fils: Use bit_field from ell 2021-03-11 22:34:26 -06:00
Denis Kenzior d60c58f595 ie: Use bit_field from ell 2021-03-11 22:33:21 -06:00
Denis Kenzior 3dae0592b0 eapol: Use bit_field from ell 2021-03-11 22:33:06 -06:00
Denis Kenzior a941d4169f util: Remove unused util_set_bit 2021-03-11 22:24:05 -06:00
Denis Kenzior 666402870e wiphy: Use ell's set_bit 2021-03-11 22:23:52 -06:00
Denis Kenzior 17cf4da726 build: Add useful.h to files that use minsize
Now that minsize has been moved out of ell/util.h to ell/minsize.h
2021-03-11 21:55:57 -06:00
Andrew Zaborowski 926ab2accf p2p: Build P2P and WFD IEs for group's management frames
Register P2P group's vendor IE writers using the new API to build and
attach the necessary P2P IE and WFD IEs to the (Re)Association Response,
Probe Response and Beacon frames sent by the GO.
2021-03-11 21:49:23 -06:00
Andrew Zaborowski a6b7624033 p2p: Parse P2P IEs and WFD IEs in Association Requests
Roughly validate the IEs and save some information for use in our own
IEs. p2p_extract_wfd_properties and p2p_device_validate_conn_wfd are
being moved unchanged to be usable in p2p_group_event without forward
declarations and to be next to p2p_build_wfd_ie.
2021-03-11 21:48:43 -06:00
Andrew Zaborowski f868c2989c ap: Handle most WSC IEs using ap_write_extra_ies
Make the WSC IE processing and writing more self-contained (i.e. so that
it can be more easily moved to a separate file if desired) by using the
new ap_write_extra_ies() mechanism.
2021-03-11 21:47:05 -06:00
Andrew Zaborowski 18a63f91fd ap: Write extra frame IEs from the user
Add an API for the ap.h users to add extra IEs to outgoing management
frames: beacons, etc.
2021-03-11 21:46:49 -06:00
Denis Kenzior f7b5bd4a79 treewide: Use ell's useful.h header 2021-03-11 21:46:09 -06:00
Andrew Zaborowski c19fd0ee78 ap: Pass frame IEs from clients to the ap_state user
Pass the string IEs from the incoming STA association frames to
the user in the AP event data.  I drop
ap_event_station_added_data.rsn_ie because that probably wasn't
going to ever be useful and the RSN IE is included in the .assoc_ies
array in any case.
2021-03-10 16:42:03 -06:00
Andrew Zaborowski 71ba94121d ap: Make ap_update_beacon public
Let users call ap_update_beacon when a value has changed which should be
reflected in the beacon IEs.
2021-03-10 16:42:01 -06:00
James Prestwood bc3d285c5e netdev: use NL80211_STA_INFO_SIGNAL rather than average
Since GET_STATION (and in turn GetDiagnostics) gets the most
current station info this attribute serves as a better indication
of the current signal strength. In addition full mac cards don't
appear to always have the average attribute.
2021-03-10 15:10:41 -06:00
James Prestwood f89270325f nl80211util: add WIPHY_FREQ to parse_attrs support 2021-03-10 15:08:19 -06:00
Denis Kenzior 0ba0418b53 iwd: remove uninitialized_var
No instances of this macro now exist.  If future instances crop up, the
better approach would be to use pragma directives to quiet such warnings
and allow static analysis to catch any issues.
2021-03-10 12:05:43 -06:00
Denis Kenzior 07eea03cca eap: Rework handle_response logic
Expanded packets with a 0 vendor id need to be treated just like
non-expanded ones.  This led to very nasty looking if statements
throughout this function.  Fix that by introducing a nested function
to take care of the response type normalization.  This also allows us to
drop uninitialized_var usage.
2021-03-10 12:03:49 -06:00
Denis Kenzior a483ec7b68 eap: Fix Expanded Nak processing
Expanded Nak packet contains (possibly multiple) 8 byte chunks that
contain the type (1 byte, always '254') vendor-id (3 bytes) and
vendor-type (4) bytes.

Unfortunately the current logic was reading the vendor-id at the wrong
offset (0 instead of 1) and so the extracted vendor-type was incorrect.

Fixes: 17c569ba4c ("eap: Add authenticator method logic and API")
2021-03-09 18:28:42 -06:00
Denis Kenzior 28e58887ec eap: Don't try to pass NAKs into eap_type_to_str
If we received a Nak or an Expanded Nak packet, the intent was to print
our own method type.  Instead we tried to print the Nak type contents.
Fix that by always passing in our method info to eap_type_to_str.

Fixes: 17c569ba4c ("eap: Add authenticator method logic and API")
2021-03-09 18:25:51 -06:00
Denis Kenzior 7de5b4adef treewide: replace util_mem_is_zero with l_memeqzero 2021-03-09 15:40:35 -06:00
Denis Kenzior a2926bd3ed watchlist: Remove '__' prefix from static functions
The '__' prefix is meant for private, semi-private,
inner implementation or otherwise special APIs that
are typically exposed in a header.  In the case of watchlist, these
functions were static and do not fit the above description.  Remove the
__ prefix accordingly.
2021-03-09 15:28:36 -06:00
Andrew Zaborowski 3621e998c9 ap: Add missing ap_config_free() in error path 2021-03-05 16:20:30 -06:00
Andrew Zaborowski e714e72e05 utils: Add util_netmask_from_prefix 2021-02-26 11:01:03 -06:00
Andrew Zaborowski b689100c1c ap: Print error messages in dhcp_load_settings 2021-02-26 11:00:25 -06:00
Andrew Zaborowski cdb2c2b3e3 ap: Fix an inet_aton error check
inet_aton returns 0 on error, not a negative number.
2021-02-26 10:59:35 -06:00
Andrew Zaborowski fd934aa39e ap: Don't use L_AUTO_FREE_VAR with l_settings
L_AUTO_FREE_VAR only causes l_free to be called on the variable that is
freed and may leak the rest of the l_settings object's memory.
2021-02-26 10:59:22 -06:00
Marcel Holtmann 25ec652423 manager: If driver is not provided, then use default interfaces 2021-02-18 21:43:56 +01:00
Andrew Zaborowski e8ad4f10b0 ap: Drop an outdated TODO comment 2021-02-18 14:00:30 -06:00
Alvin Šipraga 6b6d0de163 doc: describe InitialPeriodicScanInterval setting 2021-02-12 09:57:10 -06:00
Alvin Šipraga ff82133050 scan: add InitialPeriodicScanInterval setting 2021-02-12 09:57:10 -06:00
Alvin Šipraga 2df581d1ff doc: describe MaximumPeriodicScanIntervalSetting 2021-02-12 09:57:10 -06:00
Alvin Šipraga 88f2b44bba scan: add MaximumPeriodicScanInterval setting 2021-02-12 09:57:10 -06:00
Daniel Lin c68e9fc0a6 resolve: configure systemd-resolved's MulticastDNS= setting
When using iwd.conf:[General].EnableNetworkConfiguration=true, it is not
possible to configure systemd.network:[Network].MulticastDNS= as
systemd-networkd considers the link to be unmanaged. This patch allows
iwd to configure that setting on systemd-resolved directly.
2021-02-11 15:06:01 -06:00
James Prestwood 6421b3c5c1 netdev: always register for single CQM threshold
If the extended feature for CQM levels was not supported no CQM
registration would happen, not even for a single level. This
caused IWD to completely lose the ability to roam since it would
only get notified when the kernel was disconnecting, around -90
dBm, not giving IWD enough time to roam.

Instead if the extended feature is not supported we can still
register for the event, just without multiple signal levels.
2021-02-10 12:09:28 -06:00
Andrew Zaborowski 0b5e7ab7bb crypto: Check for l_cipher_decrypt error 2021-02-10 11:56:24 -06:00
Denis Kenzior f0d811b79c backtrace: Avoid null-dereferencing strchr result 2021-02-09 10:30:48 -06:00
Denis Kenzior fa9ae4acb7 scan: Put an upper bound on the scan interval 2021-02-09 09:31:05 -06:00
James Prestwood 6930987aa6 network: free psk on error 2021-02-08 16:10:21 -06:00
Denis Kenzior 0854592cc6 p2p: Do not leak 'str'
DeviceType setting is stored in 'str', but is never freed.  Fix that.
2021-02-08 16:02:42 -06:00
Denis Kenzior 2b2b6185e4 eap-tls: Fix potential memory leak
client-cert might be leaked if ClientKey loading fails
2021-02-08 15:56:30 -06:00
Denis Kenzior f7df7939e6 eap-wsc: Fix possible memory leaks
While parsing WSC registrar settings, the variable 'str' which is used
in multiple areas can be leaked.  Fix that.
2021-02-08 15:46:45 -06:00
James Prestwood 9885568b47 adhoc: fix missing call to va_end
Since only one switch case uses this, va_start/end were just
moved into that case specifically.
2021-02-08 15:16:39 -06:00
Denis Kenzior 6ad50ac49b ap: Make sure strerror argument is positive 2021-02-08 15:05:54 -06:00
James Prestwood f046bed225 ap: massage code to make static analysis happy
There is no functional change here but checking the return
value makes static analysis much happier. Checking the
return and setting the default inside the if clause is also
consistent with how IWD does it many other places.
2021-02-08 14:24:06 -06:00
James Prestwood 0ae3e1c59d ap: free passphrase on error 2021-02-08 14:23:54 -06:00
Denis Kenzior fb217479d2 netdev: Scan & Retry CMD_AUTHENTICATE
Handle situations where the BSS we're trying to connect to is no longer
in the kernel scan result cache.  Normally, the kernel will re-scan the
target frequency if this happens on the CMD_CONNECT path, and retry the
connection.

Unfortunately, CMD_AUTHENTICATE path used for WPA3, OWE and FILS does
not have this scanning behavior.  CMD_AUTHENTICATE simply fails with
a -ENOENT error.  Work around this by trying a limited scan of the
target frequency and re-trying CMD_AUTHENTICATE once.
2021-02-08 11:53:29 -06: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 603988476a netdev: Ignore locally generated deauth frames
Fixes: 2bebb4bdc7 ("netdev: Handle deauth frames prior to
association")
2021-02-04 13:54:33 -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 454cee12d4 scan: Use kernel-reported time-stamp if provided 2021-02-03 13:35:46 -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
Denis Kenzior 4015222f89 scan: Reorganize scan.h to follow coding-style M9 2021-02-03 13:34:37 -06:00
Denis Kenzior f0e0060ddc scan: Make scan_freq_set_contains const-correct 2021-02-03 13:34:28 -06:00
Denis Kenzior 79928e69cb Revert "scan: Drop unused frequency list parsing"
This reverts commit 520ad56f83.
2021-02-03 13:34:23 -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
James Prestwood 676ee1e4d2 ap: tie diagnostic interface to AP Start/Stop
The diagnostic interface serves no purpose until the AP has
been started. Any calls on it will return an error so instead
it makes more sense to bring it up when the AP is started, and
down when the AP is stopped.
2021-02-02 15:54:56 -06:00
James Prestwood ec15ef1d34 ap: add Name property
Its useful being able to refer to the network Name/SSID once
an AP is started. For example opening an iwctl session with an
already started AP provides no way of obtaining the SSID.
2021-02-02 15:53:25 -06:00
Denis Kenzior 2bebb4bdc7 netdev: Handle deauth frames prior to association
In some cases the AP can send a deauthenticate frame right after
accepting our authentication.  In this case the kernel never properly
sends a CMD_CONNECT event with a failure, even though CMD_COONNECT was
used to initiate the connection.  Try to work around that by detecting
that a Deauthenticate event arrives prior to any Associte or Connect
events and handle this case as a connect failure.
2021-02-02 15:27:50 -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
Andrew Zaborowski 074bc52717 eapol,ap: Remove assumption of single cipher in authenticator IE
Allow the user of the eapol_sm & handshake_state APIs to have multiple
pairwise ciphers listed in the authenticator IE.
2021-02-01 10:06:21 -06:00
Andrew Zaborowski 436c5a45e4 ap: Set the group cipher when sending START_AP
Seems this was overlooked because an initial version of ap.c didn't have
group traffic support.
2021-02-01 10:05:55 -06:00
Andrew Zaborowski 065f19b479 ap: Fix cleanup on ap_parse_new_station_ies errors 2021-01-29 20:06:18 -06:00
James Prestwood 756158dfc9 knownnetworks: sanitize known_network.freq on load
An invalid known_network.freq file containing several UUID
groups which have the same 'name' key results in memory leaks
in IWD. This is because the file is loaded and the group's
are iterated without detecting duplicates. This leads to the
same network_info's known_frequencies being set/overridden
multiple times.

To fix this we just check if the network_info already has a
UUID set. If so remove the stale entry.

There may be other old, invalid, or stale entries from previous
versions of IWD, or a user misconfiguring the file. These will
now also be removed during load.
2021-01-29 17:48:03 -06:00
James Prestwood 7b2ce98abd station: fix leak on parse_neighbor_report 2021-01-29 17:22:20 -06:00
James Prestwood 9f33740d41 ap: fix off by one error
The RSN element was not being allocated properly which caused
an invalid read in some cases.
2021-01-29 15:04:10 -06:00
Denis Kenzior ed0f3e87ca netdev: Fix re-entrancy bug in netdev_shutdown
netdev_shutdown calls queue_destroy on the netdev_list, which in turn
calls netdev_free.  netdev_free invokes the watches to notify them about
the netdev being removed.  Those clients, or anything downstream can
still invoke netdev_find.  Unfortunately queue_destroy is not re-entrant
safe, so netdev_find might return stale data.  Fix that by using
l_queue_peek_head / l_queue_pop_head instead.

src/station.c:station_enter_state() Old State: connecting, new state:
connected
^CTerminate
src/netdev.c:netdev_free() Freeing netdev wlan1[6]
src/device.c:device_free()
Removing scan context for wdev 100000001
src/scan.c:scan_context_free() sc: 0x4ae9ca0
src/netdev.c:netdev_free() Freeing netdev wlan0[48]
src/device.c:device_free()
src/station.c:station_free()
src/netconfig.c:netconfig_destroy()
==103174== Invalid read of size 8
==103174==    at 0x467AA9: l_queue_find (queue.c:346)
==103174==    by 0x43ACFF: netconfig_reset (netconfig.c:1027)
==103174==    by 0x43AFFC: netconfig_destroy (netconfig.c:1123)
==103174==    by 0x414379: station_free (station.c:3369)
==103174==    by 0x414379: station_destroy_interface (station.c:3466)
==103174==    by 0x47C80C: interface_instance_free (dbus-service.c:510)
==103174==    by 0x47C80C: _dbus_object_tree_remove_interface
(dbus-service.c:1694)
==103174==    by 0x47C99C: _dbus_object_tree_object_destroy
(dbus-service.c:795)
==103174==    by 0x409A87: netdev_free (netdev.c:770)
==103174==    by 0x4677AE: l_queue_clear (queue.c:107)
==103174==    by 0x4677F8: l_queue_destroy (queue.c:82)
==103174==    by 0x40CDC1: netdev_shutdown (netdev.c:5089)
==103174==    by 0x404736: iwd_shutdown (main.c:78)
==103174==    by 0x404736: iwd_shutdown (main.c:65)
==103174==    by 0x46BD61: handle_callback (signal.c:78)
==103174==    by 0x46BD61: signalfd_read_cb (signal.c:104)
2021-01-29 15:02:19 -06:00
Denis Kenzior bd6d19e084 netdev: Squash memory leak on module_init failure
In the case of module_init failing due to a module that comes after
netdev, the netdev module doesn't clean up netdev_list properly.

==6254== 24 bytes in 1 blocks are still reachable in loss record 1 of 1
==6254==    at 0x483777F: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6254==    by 0x4675ED: l_malloc (util.c:61)
==6254==    by 0x46909D: l_queue_new (queue.c:63)
==6254==    by 0x406AE4: netdev_init (netdev.c:5038)
==6254==    by 0x44A7B3: iwd_modules_init (module.c:152)
==6254==    by 0x404713: nl80211_appeared (main.c:171)
==6254==    by 0x4713DE: process_unicast (genl.c:993)
==6254==    by 0x4713DE: received_data (genl.c:1101)
==6254==    by 0x46E00B: io_callback (io.c:118)
==6254==    by 0x46D20C: l_main_iterate (main.c:477)
==6254==    by 0x46D2DB: l_main_run (main.c:524)
==6254==    by 0x46D2DB: l_main_run (main.c:506)
==6254==    by 0x46D502: l_main_run_with_signal (main.c:656)
==6254==    by 0x403EDB: main (main.c:490)
2021-01-29 13:39:20 -06:00
James Prestwood aefcaf8559 ap: handle GET_KEY error setting RSC to zero
Rather than the previous hack which disabled group traffic it
was found that the GTK RSC could be manually set to zero which
allows group traffic. This appears to fix AP mode on brcmfmac
along with the previous fixes. This is not documented in
nl80211, but appears to work with this driver.
2021-01-29 13:15:36 -06:00
James Prestwood 4635e095ba ap: rename ap_parse_ie to be more descriptive
This is only used for NEW_STATION parsing so name appropriately
2021-01-29 13:15:24 -06:00
James Prestwood 32028f6daf ap: add DEL_STATION path to fullmac AP handling
This is how a fullmac card tells userspace that a station has
left. This fixes the issue where the same client cannot re-connect
to the same AP multiple times. ap_new_station was renamed to
ap_handle_new_station for consistency.
2021-01-29 11:36:09 -06:00
James Prestwood 7429b2162d ap: allow no group traffic on GET_KEY error
Some fullmac cards were found to be buggy with getting the GTK
where it returns a BIP key for the GTK index, even after creating
a GTK with NEW_KEY explicitly. In an effort to get these cards
semi-working we can treat this just as a warning and continue with
the handshake without a GTK set which disables group traffic. A
warning is printed in this case so the user is not completely in
the dark.
2021-01-28 13:41:43 -06:00
Alvin Šipraga a04b61ec77 netdev: preserve cur_rssi_low across reassociation
Fix an issue with the recent changes to signal monitoring from commit
f456501b ("station: retry roaming unless notified of a high RSSI"):

    1. driver sends NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
    2. netdev->cur_rssi_low changes from FALSE to TRUE
    3. netdev sends NETDEV_EVENT_RSSI_THRESHOLD_LOW to station
    4. on roam reassociation, cur_rssi_low is reset to FALSE
    5. station still assumes RSSI is low, periodically roams
       until netdev sends NETDEV_EVENT_RSSI_THRESHOLD_HIGH
    6. driver sends NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
    7. netdev->cur_rssi_low doesn't change (still FALSE)
    8. netdev never sends NETDEV_EVENT_RSSI_THRESHOLD_HIGH
    9. station remains stuck in an infinite roaming loop

The commit in question introduced the logic in (5). Previously the
assumption in station was - like in netdev - that if the signal was
still low, the driver would send a duplicate LOW event after
reassociation. This change makes netdev follow the same new logic as
station, i.e. assume the same signal state (LOW/HIGH) until told
otherwise by the driver.
2021-01-28 13:40:10 -06:00
James Prestwood 63c8df78a3 ap: handle NEW_STATION for fullmac cards
Since fullmac cards handle auth/assoc in firmware IWD must
react differently while in AP mode just as it does in station.
For fullmac cards a NEW_STATION event is emitted post association
and from here the 4-way handshake can begin. In this NEW_STATION
handler a new sta_state is created and the needed members are
set in order to inject us back into the normal code execution
for softmac post association (i.e. creating group keys and
starting the 4-way handshake). From here everything works the
same as softmac.
2021-01-28 13:25:18 -06:00
Denis Kenzior 6db352a82d manager: UseDefaultInterface for bcmsdh_sdmmc
This driver is used on some ARM based devices
2021-01-27 09:58:34 -06:00
Andrew Zaborowski 6f62056fcf eap-tls: Use the right variable in settings check 2021-01-27 09:52:47 -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
Andrew Zaborowski 5c95c5cc16 netconfig: Set more correct buffer length
Use INET_ADDRSTRLEN as the IPv4 address buffer size to avoid confusion.
2021-01-25 14:01:58 -06:00
Andrew Zaborowski 54e3bb385a doc: Specify the DNS format as string lists 2021-01-25 14:01:58 -06:00
Andrew Zaborowski d6e99c1197 doc: Update EAP-TLS client key setting information 2021-01-25 14:01:58 -06:00
Andrew Zaborowski 84cae48c1b eap-tls: Make use of l_cert_load_container_file
Switch EAP-TLS-ClientCert and EAP-TLS-ClientKey to use
l_cert_load_container_file for file loading so that the file format is
autodetected.  Add new setting EAP-TLS-ClientKeyBundle for loading both
the client certificate and private key from one file.
2021-01-25 14:01:58 -06:00
Andrew Zaborowski b0aa1e4e88 eap-tls: Drop EAP-{TTLS,PEAP}-Client{Cert,Key}
As requested move the client certificate and private key loading from
eap-tls-common.c to eap-tls.c.  No man page change needed because those
two settings weren't documented in it in the first place.
2021-01-25 14:01:58 -06:00
James Prestwood 9c33572aee ap: add AP diagnostic interface
This adds a new AccessPointDiagnostic interface. This interface
provides similar low level functionality as StationDiagnostic, but
for when IWD is in AP mode. This uses netdev_get_all_stations
which will dump all stations, parse, and return each station in
an individual callback. Once the dump is complete the destroy is
called and all data is packaged as an array of dictionaries.
2021-01-22 15:00:48 -06:00
James Prestwood 158dc40340 station: refactor to use diagnostic_info_to_dict 2021-01-22 14:59:47 -06:00
James Prestwood b5d927ec3b diagnostic: commonize the building of diagnostic dict
AP mode will use the same structure for its diagnostic interface
and mostly the same dictionary keys. Apart from ConnectedBss and
Address being different, the remainder are the same so the
diagnostic_station_info to DBus dictionary conversion has been made
common so both station and AP can use it to build its diagnostic
dictionaries.
2021-01-22 14:41:20 -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 e03b1e263d build: add After=network-pre.target to service files
systemd specifies a special passive target unit 'network-pre.target'
which may be pulled in by services that want to run before any network
interface is brought up or configured. Correspondingly, network
management services such as iwd and ead should specify
After=network-pre.target to ensure a proper ordering with respect to
this special target. For more information on network-pre.target, see
systemd.special(7).

Two examples to explain the rationale of this change:

1. On one of our embedded systems running iwd, a oneshot service is
   run on startup to configure - among other things - the MAC address of
   the wireless network interface based on some data in an EEPROM.
   Following the systemd documentation, the oneshot service specifies:

        Before=network-pre.target
        Wants=network-pre.target

   ... to ensure that it is run before any network management software
   starts. In practice, before this change, iwd was starting up and
   connecting to an AP before the service had finished. iwd would then
   get kicked off by the AP when the MAC address got changed. By
   specifying After=network-pre.target, systemd will take care to avoid
   this situation.

2. An administrator may wish to use network-pre.target to ensure
   firewall rules are applied before any network management software is
   started. This use-case is described in the systemd documentation[1].
   Since iwd can be used for IP configuration, it should also respect
   the After=network-pre.target convention.

Note that network-pre.target is a passive unit that is only pulled in if
another unit specifies e.g. Wants=network-pre.target. If no such unit
exists, this change will have no effect on the order in which systemd
starts iwd or ead.

[1] https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
2021-01-22 14:17:16 -06:00
Alvin Šipraga 947d7c611b doc: describe RoamRetryInterval setting 2021-01-22 13:48:02 -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
James Prestwood 8e03d56688 netdev: add netdev_get_all_stations
This is a nl80211 dump version of netdev_get_station aimed at
AP mode. This will dump all stations, parse into
netdev_station_info structs, and call the callback for each
individual station found. Once the dump is completed the destroy
callback is called.
2021-01-20 14:01:15 -06:00
James Prestwood 8620698b66 dbus: add AccessPointDiagnostic interface 2021-01-20 14:01:10 -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
James Prestwood 93b5a5a4ae netdev: parse expected throughput in netdev_get_station 2021-01-14 14:58:33 -06:00