Commit Graph

2996 Commits

Author SHA1 Message Date
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
James Prestwood 0ba73ec139 netdev: parse rates in netdev_get_station 2021-01-14 14:57:19 -06:00
James Prestwood 08de8186c6 netdev: update RSSI polling to use station info parser 2021-01-12 13:39:14 -06:00
James Prestwood cf17d42972 netdev: add netdev_get_station/current_station
This adds a generalized API for GET_STATION. This API handles
calling and parsing the results into a new structure,
netdev_station_info. This results structure will hold any
data needed by consumers of netdev_get_station. A helper API
(netdev_get_current_station) was added as a convenience which
automatically passes handshake->aa as the MAC.

For now only the RSSI is parsed as this is already being
done for RSSI polling/events. Looking further more info will
be added such as rx/tx rates and estimated throughput.
2021-01-12 13:39:07 -06:00
James Prestwood 09b124f073 dbus: add helper for appending a dictionary
Arrays of dictionaries are quite common, and for basic
types this API makes things much more convenient by
putting all the enter/append/leave calls in one place.
2021-01-12 13:19:38 -06:00
James Prestwood 668b61ff3a dbus: add diagnostic interface definition 2021-01-11 14:51:48 -06:00
Andrew Zaborowski 9ef3d51f87 crypto: Update l_pkcs5_pbkdf2 call after rename 2021-01-07 14:05:40 -06:00
Andrew Zaborowski 047b0e71a1 eap-tls: Dump server certificate when IWD_TLS_DEBUG set 2021-01-04 12:17:00 -06:00
Carlo Abelli d3606cd255 doc: move EnableIPv6 under Network
The EnableIPv6 option is incorrectly documented under General but should
be documented under Network instead.
2020-12-22 09:35:48 -06:00
Andrew Zaborowski f5a30a1cfc station: Don't expire BSSes between freq subset scans
Add a parameter to station_set_scan_results to allow skipping the
removal of old BSSes.  In the DBus-triggered scan only expire BSSes
after having gone through the full supported frequency set.

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

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

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

Hopefully this is similar when using other drivers although I can easily
imagine a driver that parallelizes 2.4GHz and 5GHz channel probing using
two radios, or uses 2, 4 or another number of dual-band radios to probe
2, 4, ... channels simultanously.  We'd then lose some of the
performance benefit.  The faster scan results may be worth the longer
overall scan time anyway.
I'm also assuming that the wiphy's supported frequency list is exactly
what was scanned when we passed no frequency list to
NL80211_CMD_TRIGGER_SCAN and we won't get errors for passing some
frequency that shouldn't have been scanned.
2020-12-17 20:15:37 -06:00
James Prestwood f39d1b4ac2 netconfig: add ACD client for static configuration
When the IP is configured to be static we can now use ACD in
order to check that the IP is available and not already in
use. If a conflict is found netconfig will be reset and no IP
will be set on the interface. The ACD client is left with
the default 'defend once' policy, and probes are not turned
off. This will increase connection time, but for static IP's
it is the best approach.
2020-12-08 16:29:09 -06:00
James Prestwood 4353110684 doc: use real example for APRanges
The docs just specified what a IP prefix looks like, not an
actual example. Though its not recommended to just copy paste
blindly, its still useful to have some value in the man pages
that actually works if someone just wants to get a DHCP server
working.
2020-12-02 16:12:56 -06:00
Denis Kenzior 278abc66be netconfig: Also set the domains obtained from IPv6 2020-12-02 10:55:05 -06:00
Denis Kenzior 967b7e75e3 resolve: Handle empty dns/domain lists
In the strange case that the dns list or the domain list are empty and
openresolv is being used, delete the openresolv entry instance instead
of trying to set it to an empty value
2020-12-02 10:55:05 -06:00
Alvin Šipraga b647f8e1f0 network: clear info of removed known network before disconnect
Make sure to erase the network_info of a known network that has been
removed before disconnecting any stations connected to it. This fixes
the following warning observed when forgetting a connected network:

  WARNING: ../git/src/network.c:network_rank_update() condition n < 0 failed

This also fixes a bug where such a forgotten network would incorrectly
appear as the first element in the response to GetOrderedNetworks().  By
clearing the network_info, network_rank_update() properly negates the
rank of the now-unknown network.
2020-12-01 09:54:52 -06:00
James Prestwood ccf265b943 netconfig: fix freeing invalid pointer
If l_rtnl_ifaddr4_extract does not set the values they would
get freed. Instead initialize to NULL so the cleanup free is
a no op.
2020-11-23 23:29:54 -06:00
Denis Kenzior ebc42ccecf netconfig: Don't re-create address on RENEWAL
==5279== 104 bytes in 2 blocks are definitely lost in loss record 1 of 1
==5279==    at 0x4C2F0CF: malloc (vg_replace_malloc.c:299)
==5279==    by 0x4655CD: l_malloc (util.c:61)
==5279==    by 0x47116B: l_rtnl_address_new (rtnl.c:136)
==5279==    by 0x438F4B: netconfig_get_dhcp4_address (netconfig.c:429)
==5279==    by 0x438F4B: netconfig_ipv4_dhcp_event_handler
(netconfig.c:735)
==5279==    by 0x491C77: dhcp_client_event_notify (dhcp.c:332)
==5279==    by 0x491C77: dhcp_client_rx_message (dhcp.c:810)
==5279==    by 0x492A88: _dhcp_default_transport_read_handler
(dhcp-transport.c:151)
==5279==    by 0x46BECB: io_callback (io.c:118)
==5279==    by 0x46B10C: l_main_iterate (main.c:477)
==5279==    by 0x46B1DB: l_main_run (main.c:524)
==5279==    by 0x46B3EA: l_main_run_with_signal (main.c:646)
==5279==    by 0x403ECE: main (main.c:490)
2020-11-23 14:59:20 -06:00
Andrew Zaborowski 7c7831b53d doc: Update iwd.network.5 with changes from wiki
Fix the AlwaysRandomizeAddress setting name.

Add the stricter specification of the extension syntax.

Clarify that GTC and MD5 can't be used as outer EAP methods with wifi.
2020-11-19 14:21:42 -06:00
Denis Kenzior 69e86f4d21 netconfig: Remove tracking of addresses
Tracking of addresses that weren't set by us seemed a bit questionable.
Take this out for now.  If this is ever needed, then a queue with
l_rtnl_address objects should be used.
2020-11-19 14:19:17 -06:00
Denis Kenzior 6f5ec005e9 netconfig: Rework IPv4 address handling
Introduce a new v4_address member which will hold the currently
configured IPV4 address (static or obtained via DHCP).  Use the new
l_rtnl_address class for this.

As a side-effect, lease expiration will now properly remove the
configured address.
2020-11-19 14:19:13 -06:00
Denis Kenzior eb151efc81 netconfig: Rework static IPv6 address handling
This patch converts the code to use the new l_rtnl_address class.  The
settings parsing code will now return an l_rtnl_address object which
can be installed directly.

Also, address removal path for static addresses has been removed, since
netconfig_reset() sets disable_ipv6 setting to '1', which will remove
all IPV6 addresses for the interface.
2020-11-19 13:28:38 -06:00
Denis Kenzior b6cf9ef866 netconfig: Rework static IPv6 route handling
This patch converts the code to use the new l_rtnl_route class instead
of using l_rtnl_route6* utilities.  The settings parsing code will now
return an l_rtnl_route object which can be installed directly.

Also, the route removal path has been removed since netconfig_reset()
sets disable_ipv6 setting to '1' which will remove all IPV6 routes and
addresses for the interface.
2020-11-19 13:08:51 -06:00
Denis Kenzior 3890431090 netconfig: Install search domains obtained from DHCPv6 2020-11-18 12:00:17 -06:00
Denis Kenzior dcaf0150b9 netconfig: Re-start DHCPv6 client
If lease expired or was not obtained initially, re-start the DHCPv6
client.
2020-11-18 10:39:29 -06:00
Denis Kenzior c46a5d7c84 netconfig: Install DNS addresses obtained from DHCPv6
This also changes the resolve API a little bit to act as a 'set' API
instead of an incremental 'add' API.  This is actually easier to manage
in the resolve module since both systemd and resolvconf want changes
wholesale and not incrementally.
2020-11-18 10:39:16 -06:00
James Prestwood 845658bd32 station: get neighbor reports early
Waiting to request neighbor reports until we are in need of a roam
delays the roam time, and probably isn't as reliable since we are
most likely in a low RSSI state. Instead the neighbor report can
be requested immediately after connecting, saved, and used if/when
a roam is needed. The existing behavior is maintained if the early
neighbor report fails where a neighbor report is requested at the
time of the roam.

The code which parses the reports was factored out and shared
between the existing (late) neighbor report callback and the early
neighbor report callback.
2020-11-16 18:14:07 -06:00
James Prestwood fedfda9fb5 simauth: check driver for NULL before canceling request
If the ofono modem got removed before it was fully initialized this
could cause a crash.
2020-11-16 17:04:30 -06:00
Denis Kenzior 95df3e660b doc: Describe EnableIPv6 setting 2020-11-16 16:14:03 -06:00
Denis Kenzior 6f893dbc31 doc: Document IPv6 related network settings 2020-11-16 16:02:24 -06:00
Denis Kenzior 53c9a692fa netconfig: Add configs for controlling IPV6 support 2020-11-16 16:02:24 -06:00
Jonathan Liu 5e9f1a6806 ap: Fix handshake state gtk not being set
handshake_state_set_authenticator_ie must be called to set group_cipher
in struct handshake_shake before handshake_set_gtk_state, otherwise
handshake_set_gtk_state is unable to determine the key length to set
handshake state gtk.

Fixes: 4bc20a0979 ("ap: Start EAP-WSC authentication with WSC enrollees")
2020-11-16 13:35:51 -06:00
Denis Kenzior bb876953ac netconfig: Start RA & DHCPv6 clients
For now the RA client is ran automatically when DHCPv6 client starts.
RA takes care of installing / deleting prefix routes and installing the
default gateway.  If Router Advertisements indicate support DHCPv6, then
DHCPv6 transactions are kicked off and the address is set / removed
automatically.

Stateless configuration is not yet supported.
2020-11-12 15:36:56 -06:00
James Prestwood 1106514a38 netdev: remove handling of beacon loss event 2020-11-04 13:40:52 -06:00
James Prestwood 836beb1276 station/wsc: remove beacon loss handling
Modern kernels ~5.4+ have changed the way lost beacons are
reported and effectively make the lost beacon event useless
because it is immediately followed by a disconnect event. This
does not allow IWD enough time to do much of anything before
the disconnect comes in and we are forced to fully re-connect
to a different AP.
2020-11-04 13:40:25 -06:00
James Prestwood 32db13aef8 doc: document DHCP server options in AP profiles 2020-11-04 13:38:35 -06:00
James Prestwood 946a67502b doc: add APRanges documentation 2020-11-04 13:37:55 -06:00
James Prestwood 39ca2c3e05 doc: add man pages for AP provisioning files 2020-11-04 13:37:18 -06:00
James Prestwood acb31477c1 ap: make APRanges optional
If EnableNetworkConfiguration was enabled ap.c required that
APRanges also be set. This prevents IWD from starting which
effects a perfectly valid station configuration. Instead if
APRanges is not provided IWD still allows ap_init to pass but
DHCP just will not be enabled.
2020-11-03 13:58:23 -06:00
James Prestwood 5420fdaf01 ap: fixup incorrect return
If an RTNL address change fails -EIO should be returned, not
false (aka "success").
2020-11-02 14:23:53 -06:00
James Prestwood e1b3e73c2b ap: allow DHCP settings in provisioning files
Users can now supply an AP provisioning file containing an [IPv4]
section and define various DHCP settings:

[IPv4]
Address=<address>
Netmask=<netmask>
Gateway=<gateway>
IPRange=<start_address>,<end_address>
DNSList=<dns1>,<dns2>,...<dnsN>
LeaseTime=<lease_time>

There are a few notes/requirements to keep in mind when using a
provisioning file:

 - All settings are optional but [IPv4].Address is required if the
   interface does not already have an address set.
 - If no [IPv4].Address is defined in the provisioning file and the AP
   interface does not already have an address set, StartWithConfig()
   will fail with -EINVAL.
 - If a provisioning file is provided it will take precedence, and the
   AP will not pull from the IP pool.
 - A provisioning file containing an IPv4 section assumes DHCP is being
   enabled and will override [General].EnableNetworkConfiguration.
 - Any address that AP sets on the interface will be deleted when the AP
   is stopped.
2020-11-02 13:47:24 -06:00
James Prestwood 5153b88cbe ap: add StartProfile DBus method
Users can now start an AP from settings based on a profile
on disk. The only argument is the SSID which will be used to
lookup the profile. If no profile is found a NotFound error
will be returned. Any invalid profiles will result in an
Invalid return.
2020-11-02 13:39:25 -06:00
James Prestwood c0149f1106 frame-xchg: fix invalid read
This seems to happen occationally with testAP (potentially others).
The invalid read appears to happen when the frame_xchg_tx_cb detects
an early status and no ACK. In this particular case there is no
retry interval so we reach the retry limit and 'done' the frame.
This frees the 'fx' data all before the destroy callback can get
called. Once we finally return and the destroy callback is called
'fx' is freed and we see the invalid write.

==206== Memcheck, a memory error detector
==206== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==206== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==206== Command: iwd -p rad1,rad2,rad3,rad4 -d
==206== Parent PID: 140
==206==
==206== Invalid write of size 4
==206==    at 0x4493A0: frame_xchg_tx_destroy (frame-xchg.c:941)
==206==    by 0x46DAF6: destroy_request (genl.c:673)
==206==    by 0x46DAF6: process_unicast (genl.c:1002)
==206==    by 0x46DAF6: received_data (genl.c:1101)
==206==    by 0x46AA4B: io_callback (io.c:118)
==206==    by 0x469D6C: l_main_iterate (main.c:477)
==206==    by 0x469E1B: l_main_run (main.c:524)
==206==    by 0x469E1B: l_main_run (main.c:506)
==206==    by 0x46A02B: l_main_run_with_signal (main.c:646)
==206==    by 0x403E78: main (main.c:490)
==206==  Address 0x4c59c6c is 172 bytes inside a block of size 176 free'd
==206==    at 0x483B9F5: free (vg_replace_malloc.c:538)
==206==    by 0x40F14C: destroy_work (wiphy.c:248)
==206==    by 0x40F14C: wiphy_radio_work_done (wiphy.c:1578)
==206==    by 0x44A916: frame_xchg_tx_cb (frame-xchg.c:930)
==206==    by 0x46DAD9: process_unicast (genl.c:993)
==206==    by 0x46DAD9: received_data (genl.c:1101)
==206==    by 0x46AA4B: io_callback (io.c:118)
==206==    by 0x469D6C: l_main_iterate (main.c:477)
==206==    by 0x469E1B: l_main_run (main.c:524)
==206==    by 0x469E1B: l_main_run (main.c:506)
==206==    by 0x46A02B: l_main_run_with_signal (main.c:646)
==206==    by 0x403E78: main (main.c:490)
==206==  Block was alloc'd at
==206==    at 0x483A809: malloc (vg_replace_malloc.c:307)
==206==    by 0x4643CD: l_malloc (util.c:61)
==206==    by 0x44AF8C: frame_xchg_startv (frame-xchg.c:1155)
==206==    by 0x44B2A4: frame_xchg_start (frame-xchg.c:1108)
==206==    by 0x42BC55: ap_send_mgmt_frame (ap.c:709)
==206==    by 0x42F513: ap_probe_req_cb (ap.c:1869)
==206==    by 0x449752: frame_watch_unicast_notify (frame-xchg.c:233)
==206==    by 0x46DA2F: dispatch_unicast_watches (genl.c:961)
==206==    by 0x46DA2F: process_unicast (genl.c:980)
==206==    by 0x46DA2F: received_data (genl.c:1101)
==206==    by 0x46AA4B: io_callback (io.c:118)
==206==    by 0x469D6C: l_main_iterate (main.c:477)
==206==    by 0x469E1B: l_main_run (main.c:524)
==206==    by 0x469E1B: l_main_run (main.c:506)
==206==    by 0x46A02B: l_main_run_with_signal (main.c:646)
==206==
2020-11-02 11:39:03 -06:00
Denis Kenzior 304627e086 scan: Fix crash when a canceled scan gets aborted 2020-10-30 14:06:31 -05:00
James Prestwood 18d1c752f4 ap: add support for DHCPv4 server
The DHCP server can be enabled by enabling network configuration
with [General].EnableNetworkConfiguration. If an IP is not set
on the interface before the AP is started a valid IP range must
also be provided under [General].APRanges in IP prefix format e.g.

[General]
EnableNetworkConfiguration=true
APRanges=192.168.1.1/24

Each AP started will get assigned a new subnet within the range
specified by APRanges as to not conflict with other AP interfaces.
If there are no subnets left in the pool when an AP is started
it will fail with -EEXIST. Any AP's that are stopped will release
their subnet back into the pool to be used with other APs.

The DHCP IP pool will be automatically chosen by the ELL DHCP
implementation (+1 the AP's IP to *.254). The remaining DHCP
settings will be defaults chosen by ELL (DNS, lease time, etc).
2020-10-27 16:19:47 -05:00
James Prestwood 42605c9e76 util: add util_ip_prefix_tohl
Parses an IP prefix notation string into prefix, start, end, and
netmask. All values are returned in host order.
2020-10-26 16:16:12 -05:00
James Prestwood b7e2a98628 ap: add error out param to ap_start
This allows the caller to extract a bit more information about what
exactly went wrong.
2020-10-26 14:30:34 -05:00
Andrew Zaborowski 1f89ebb86a station: Fix .Scanning being reset early
periodic_scan_stop is called whenever we exit the autoscan state but a
periodic scan may not be running at the time.  If we have a
user-triggered scan running, or the autoconnect_quick scan, and we reset
Scanning to false before that scan finished, a client could en up
calling GetOrderedNetwork too early and not receiving the scan results.
2020-10-14 13:01:18 -05:00
Andrew Zaborowski 9815fb38cf network: Check if network busy before new connection
Check if we have an ongoing agent call before starting a new connection
attempt and potentially overwriting network->agent_request.
2020-10-08 10:08:20 -05:00
Andrew Zaborowski 758dba214e station: Make Disconnect() cancel ConnectHiddenNetwork()
ConnectHiddenNetwork can be seen a triggering this sequence:
1. the active scan,
2. the optional agent request,
3. the Authentication/Association/4-Way Handshake/netconfig,
4. connected state

Currently Disconnect() interrupts 3 and 4, allow it to also interrupt
state 1.  It's difficult to tell whether we're in state 2 from within
station.c.
2020-10-08 08:54:01 -05:00
Andrew Zaborowski d5c7b47745 p2p: Respond to Probe Requests when in discovery
Since our DBus API and our use cases only support initiating connections
and not accepting incoming connections we don't really need to reply to
Probe Requests on the P2P-Device interface.  Start doing it firstly so
that we can test the scenario where we get discovered and pre-authorized
to connect in an autotest (wpa_supplicant doesn't seem to have a way to
authorize everyone, which is probably why most Wi-Fi Display dongles
don't do it and instead reply with "Fail: Information not available" and
then restart connection from their side) and secondly because the spec
wants us to do it.
2020-09-29 13:14:28 -05:00
Andrew Zaborowski ef902c5f7e p2p: Fix adding peers from Probe Request info
Make sure dev->peer_list is non-NULL before using l_queue_push_tail()
same as we do when the peer info comes from a Probe Response (active
scan in Find Phase).  Otherwise peers discovered through Probe Requests
before any Probe Responses are received will be lost.
2020-09-29 13:14:12 -05:00
Andrew Zaborowski 520ad56f83 scan: Drop unused frequency list parsing 2020-09-29 13:14:06 -05:00
Andrew Zaborowski 975696c5e0 wscutil: Fix subcategory string lookup
The device type category array is indexed by the category ID so if we're
skipping i == 0 in the iteration, we should also skip the 0'th element
in device_type_categories.
2020-09-29 13:11:07 -05:00
Andrew Zaborowski fab764967b frame-xchg: Cancel NL80211_CMD_FRAME commands when interrupted
The callback for the FRAME command was causing a crash in
wiphy_radio_work_done when not cancelled when the wiphy was being
removed from the system.  This was likely to happen if this radio work
item was waiting for another item to finish.  When the first one was
being cancelled due to the wiphy being removed, this one would be
started and immediately stopped by the radio work queue.

Now this crash could be fixed by dropping all frame exchange instances
on an interface that is being removed which is easy to do, but properly
cancelling the commands saves us the headache of analysing whether
there's a race condition in other situations where a frame exchange is
being aborted.
2020-09-29 13:10:23 -05:00
Andrew Zaborowski 3de345e903 frame-xchg: Add no-cck-rate flag only for P2P interfaces
We want to use this flag only on the interfaces with one of the three
P2P iftypes so set the flag automatically depending on the iftype from
the last 'config' notification.
2020-09-29 13:09:05 -05:00
Andrew Zaborowski c51e187462 ap: Use frame-xchg when sending frames
Convert ap_send_mgmt_frame() to use frame_xchg_start for sending frames,
this fixes among other things the ACK-received checks.

One side effect is that we're no longer sending Probe Responses with the
don't-wait-for-ack flag because frame-xchg doesn't support it, but other
AP implementations don't use that flag either.

Another side-effect is that we do use the no-cck-rate flag
unconditionally, something we may want to fix but would need to add
another parameter to frame-xchg.
2020-09-21 22:13:38 -05:00
Andrew Zaborowski 311e91b944 p2p: Free response frame payloads 2020-09-21 22:13:32 -05:00
Andrew Zaborowski c58b91dfd4 p2p: Free parsed frame data in p2p_go_negotiation_confirm_cb 2020-09-21 22:13:24 -05:00
Andrew Zaborowski 47596c67d3 p2p: Free peer->wfd in p2p_peer_free 2020-09-21 22:13:21 -05:00
Andrew Zaborowski ee4e1368d2 p2p: Try IP allocation during 4-Way handshake on client 2020-09-16 17:25:44 -05:00
Andrew Zaborowski 68cb9d38bf p2p: Start a basic P2P Group after GO Negotiation
Use the ap.c API to start an AP on a P2P_GO interface after we've been
selected as the GO in the GO Negotiation.
2020-09-16 17:25:44 -05:00
Andrew Zaborowski 185b676f31 ap: Rename wpa2_psk to wpa2_passphrase on DBus
Use the passphrase naming instead of PSK.
2020-09-16 17:25:44 -05:00
Andrew Zaborowski fbe7e0bd36 ap: Support working without passphrase
Add a "psk" setting to allow the user to pass the binary PSK directly
instead of generating it from the passphrase and the SSID.  In that case
we'll only send the PSK to WSC enrollees.
2020-09-16 17:25:44 -05:00
Andrew Zaborowski 1f68696578 ap: Pass "ops" struct to ap_start()
Pass the event callback function pointer in a "struct ap_ops" instead of
as individual ap_start() argument to make adding new callbacks easier.
2020-09-16 17:25:34 -05:00
Andrew Zaborowski 8e9a2fe05d treewide: Use l_settings_{set,get}_bytes 2020-09-16 16:46:02 -05:00
James Prestwood 18531a524f plugin: remove plugin source 2020-09-16 14:31:21 -05:00
James Prestwood 83a9de58c2 ofono: convert to module 2020-09-16 14:31:07 -05:00
James Prestwood bbcfde8743 plugins: remove dependency on ELL plugins
There has been a desire to remove the ELL plugin dependency from
IWD which is the only consumer of the plugin API. This removes
the dependency and prepares the tree for converting the existing
ofono plugin into a regular module.

sim_hardcoded was removed completely. This was originall implemented
before full ofono support purely to test the IWD side of EAP-SIM/AKA.
Since the ofono plugin (module-to-be) is now fully implemented there
really isn't a need for sim_hardcoded.
2020-09-16 14:30:14 -05:00
James Prestwood 2a8d7d4835 adhoc: delay setting Started
The Started property was being set in the Join IBSS callback which
isn't really when the IBSS has been started. The kernel automatically
scans for IBSS networks which takes some time. Its better to wait
on setting Started until we get the Join IBSS event.
2020-09-14 16:44:53 -05:00
James Prestwood e8888fab2e adhoc: print handshake failure reason 2020-09-14 16:26:41 -05:00
James Prestwood cd90097ce1 adhoc: start both eapol SM's
Commit 1f910f84b4 ("eapol: Use eapol_start in authenticator mode too")
introduced the requirement that authentication eapol_sm objects also had
to be started via eapol_start.  Adhoc was never updated to do that.
2020-09-14 16:25:03 -05:00
James Prestwood ffe9ce8034 station: print which BSS is being connected to
For multi-bss networks its nice to know which BSS is being connected
to. The ranking can hint at it, but blacklisting or network capabilities
could effect which network is actually chosen. An explicit debug print
makes debugging much easier.
2020-09-14 16:03:04 -05:00
Andrew Zaborowski e1393501e7 netconfig: Don't bswap IP netmasks for __builtin_popcountl
The __builtin_popcountl() value shouldn't change with the endianness.
2020-09-14 11:45:18 -05:00
Andrew Zaborowski 159afd7f18 eapol: IP Allocation KDE support authenticator side
Again the hs->support_ip_allocation flag is used for two purposes here,
first the user signals whether to support this mechanism through this
flag, then it reads the flag to find out if an IP was allocated.
2020-09-14 11:45:15 -05:00
Andrew Zaborowski ddf111d2c4 eapol: IP Allocation KDE support
Support IP allocation during the 4-Way Handshake as defined in the P2P
spec.  This is the supplicant side implementation.

The API requires the user to set hs->support_ip_allocation true before
eapol_start().  On HANDSHAKE_EVENT_COMPLETE, if this same flag is still
set, we've received the IP lease, the netmask and the authenticator's
IP from the authenticator and there's no need to start DHCP.  If the
flag is cleared, the user needs to use DHCP.
2020-09-14 11:45:12 -05:00
Andrew Zaborowski 4fa4cc5867 p2p: Add GO-side of GO Negotiation (responder)
Allow the possibility of becoming the Group-owner when we parse the GO
Negotiation Request, build GO Negotiation Response and parse the GO
Negotiation Confirmation, i.e. if we're responding to a negotiation
initiated by the peer after it needed to request user action.

Until now the code assumed we can't become the GO or we'd report error.
2020-09-14 11:39:25 -05:00
Andrew Zaborowski 52810ba445 p2p: Add GO-side of GO Negotiation (initiator)
Allow the possibility of becoming the Group-owner when we build the GO
Negotiation Request, parse GO Negotiation Response and build the GO
Negotiation Confirmation, i.e. if we're the initiator of the
negotiation.

Until now the code assumed we can't become the GO or we'd report error.
2020-09-14 11:39:25 -05:00
Andrew Zaborowski 116b36e943 p2putil: Add p2p_get_random_string
Add a utility to select random characters from the set defined in P2P
v1.7 Section 3.2.1.  In this version the assumption is that we're only
actually using this for the two SSID characters.
2020-09-14 11:39:25 -05:00
Andrew Zaborowski fbb0776716 ap: Fix setting the basic rate in Supported Rates IE 2020-09-14 11:39:25 -05:00
Andrew Zaborowski 1eb2735239 ap: Fix NULL ap->rates
Make sure ap->rates is non-NULL both with and without no_cck_rates.
2020-09-14 11:39:20 -05:00
Fabrice Fontaine 0a6de7932a ap: fix build with uclibc
explicit_bzero is used in src/ap.c since commit
d55e00b31d but src/missing.h is not
included, as a result build with uclibc fails on:

/srv/storage/autobuild/run/instance-1/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/9.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: src/ap.o: in function `ap_probe_req_cb':
ap.c:(.text+0x23d8): undefined reference to `explicit_bzero'

Fixes:
 - http://autobuild.buildroot.org/results/c7a0096a269bfc52bd8e23d453d36d5bfb61441d
2020-09-11 13:42:58 -05:00
Andrew Zaborowski c7b072ff21 ap: Accept P2P wildcard SSIDs in probe requests
Add the special case "DIRECT-" SSID, called the P2P Wildcard SSID, in
ap_probe_req_cb so as not to reject those Probe Requests on the basis of
ssid mismatch.  I'd have preferred to keep all the P2P-specific bits in
p2p.c but in this case there's little point in adding a generic
config setting for SSID-matching quirks.
2020-09-09 14:52:44 -05:00
Andrew Zaborowski 0d2d34c353 p2p: Consistently use the conn_ prefix for variables
Prefix all the struct p2p_device members that are part of the connection
state with the "conn_" string for consistency.  If we needed to support
multiple client connections, these members are the ones that would
probably land in a separate structure, without that prefix.
2020-09-09 13:05:36 -05:00
Andrew Zaborowski d511b4b782 p2p: Free parsed frame data in p2p_go_negotiation_resp_cb 2020-09-09 13:05:07 -05:00
Andrew Zaborowski 6bba989913 p2p: Use WSC_RF_BAND_2_4_GHZ constant instead of 0x01 2020-09-09 13:05:01 -05:00
Andrew Zaborowski 0fc97d2674 p2p: Move p2p_device_discovery_stop calls to connect_failed
Move a few the calls to p2p_device_discovery_stop() done right after
p2p_connect_failed() directly to that function to reduce duplication.
2020-09-09 13:04:22 -05:00
Andrew Zaborowski 0fad5fef71 p2p: Do provisioning scan from the Interface Address
For WSC we should have been sending our probe requests from the same
address we're going to be doing EAP-WSC with the GO.  Somehow I was able
to connect to most devices without that but other implementations seem
to use the Interface Address (the P2P-Client's MAC), not the Device
Address (P2P-Device's MAC).  We could switch the order to first create
the new interface and scan from it is simpler to use the scan_context we
already have created on the device interface and set a different mac.
2020-09-09 13:04:18 -05:00
Andrew Zaborowski 9335680cd8 scan: Add optional source_mac scan parameter
This is similar to randomize_mac_addr_hint but it sets a specific source
MAC address for our probe frames.
2020-09-09 13:02:02 -05:00
Andrew Zaborowski 4bc20a0979 ap: Start EAP-WSC authentication with WSC enrollees
After association and sending the SET_STATION commands, set up the
handshake_state and eapol_sm for EAP-WSC and start the handshake.
2020-08-28 10:50:59 -05:00
Andrew Zaborowski 7a7c580ffc ap: Parse WSC PBC association request and build response
Check the conditions for PBC enrollee registration when we receive the
Association Request with WSC IE and indicate to the enrollee whether we
accept the association using a WSC IE in the Association Response.
After this, a NULL sta->assoc_rsne indicates that the station is not
establishing the RSNA and is a WSC enrollee.
2020-08-28 10:49:16 -05:00
Andrew Zaborowski 99112c9317 ap: WSC Probe Request processing logic
Implement the caching of WSC probe requests -- when an Enrollee later
associates to start registration we need to have its Probe Request on
file.  Also use this cache for PBC "Session Overlap" detection.
2020-08-28 10:35:58 -05:00
Andrew Zaborowski 43c101ab14 ap: Push Button mode API and beacon changes
This adds the API for putting the AP in Push Button mode, which we'll
need to P2P GO side but may be useful on its own too.  A WSC IE is added
to our beacons and probe responses indicating whether the PBC mode is
active.
2020-08-28 10:32:58 -05:00
Andrew Zaborowski 1f89311798 ap: Stop ongoing handshake on reassociation
On a new association or re-association, in addition to forgetting a
complete RSN Association, also stop the EAPoL SM to stop any ongoing
handshake.

Do this in a new function ap_stop_handshake that is now used in a few
places that had copies of the same few lines.  I'll be adding some more
lines to this function for WSC support.
2020-08-28 10:32:01 -05:00
Andrew Zaborowski 2231179b97 eapol: Handle the use_eapol_start flag on authenticator
Reuse this flag on the authenticator side with a slightly different
meaning: when it's true we're forced to wait for the EAPoL-Start before
sending the first EAPoL-EAP frame to the supplicant, such as is required
in a WSC enrollee registration when the Association Request didn't have
a v2.0 WSC IE.
2020-08-28 10:29:36 -05:00
Andrew Zaborowski 66e9d4fca9 wscutil: Add wsc_build_beacon
For consistency also update wsc_build_probe_response to use the same
__builtin_popcount based rf_bands check.
2020-08-28 10:29:06 -05:00
Andrew Zaborowski 8c1bf5385e wscutil: Use a utility for building authorized_macs
Add the wfa_build_authorized_macs function (wfa_ prefix following the
wfa_extract_ naming) and use it in wsc_build_probe_response.  The logic
is changed slightly to treat the first 6-zeros address in the array as
the end of the array.
2020-08-28 10:28:15 -05:00
Andrew Zaborowski 1449b8fbc4 ap: Fix incoming Probe Request BSSID check
Setting 'match' false wouldn't do anything because it was already false.
If the frame is addressed to some other non-broadcast address ignore it
directly and exit ap_probe_req_cb.
2020-08-27 14:04:02 -05:00
Andrew Zaborowski 137309c998 ap: Drop unused variable 2020-08-27 14:02:03 -05:00
Andrew Zaborowski d55e00b31d ap: Move AP parameters to a struct
To limit the number of ap_start parameters, group basic AP config
parameters in the ap_config struct that is passed as a pointer and owned
by the ap_state.
2020-08-27 14:00:28 -05:00
Andrew Zaborowski 7713e00992 eap-wsc: In WSC-R read UUID-E from settings
The intent was to read the UUID-E from the settings rather than generate
it from the enrollee's MAC because it needs to match the UUID-E from
enrolee's Probe Requests, fix this.  The UUID-E supplied in the unit
test was being ignored but the test still passed because the supplied
UUID-E was generated the same way we generated it in eap-wsc.c.
2020-08-27 13:53:46 -05:00
Andrew Zaborowski e4b1d4202f eap: Re-send Identity Request on EAPoL-Start
It looks like clients sometimes miss our unsolicited Identity Request
and need a resend.
2020-08-27 13:53:12 -05:00
Andrew Zaborowski a4fa91a695 p2p: Build our Probe Response using connection data
When we're sending our probe response to the same peer that we're
currently connected or connecting to, use current WSC Configuration
Methods, UUID-E and WFD IE selected for this connection attempt, not the
ones we'd use when discovering peers or being discovered by peers.
In the case of the WFD IE, the "Available for WFD Session" flag is going
to differ between the two cases -- we may be unavailable for other peers
but we're still available for the peer we're trying to start the WFD
session with.
2020-08-25 16:52:41 -05:00
Andrew Zaborowski 619a5ed43b p2p: Fix the WSC Config Methods in GO Negotiation Response
When we send our GO Negotiation Response, send the Configuration Method
selected for the current connection rather than the accepted methods mask
that we hold in dev->device_info.
2020-08-25 16:52:29 -05:00
Andrew Zaborowski 19ab25f1d6 p2p: Send the right UUID-E in probe request WSC IEs
When building the scan IEs for our provisioning scans, use the UUID-E
based on the Interface Address, not the Device Address, as that is what
wsc.c will be using to in the registration protocol.

Eventually we may have to base the UUID-E on the Device Address or
something else that is persistent, and pass the actual UUID-E to wsc.c,
as the Interface Address is randomly generated on every connect attempt.
IIRC the UUID-E is supposed to be persistent.
2020-08-25 16:51:51 -05:00
Andrew Zaborowski 8173ded0eb wscutil: Allow 0-length attributes in wsc_attr_builder
wsc_attr_builder_start_attr and wsc_attr_builder_free look at
builder->curlen to see whether the TLV's length needs to be updated to
include the previous attribute.  If builder->curlen is 0
wsc_attr_builder_start_attr assumes there's no previous attribute and
starts writing at current builder->offset.  If the previous attribute
length was 0 curlen would stay at 0 and that attribute would get
overwritten with the new one.  To solve this add the 4 bytes of the T
and L to curlen as soon as a new attribute is started, and subtract
them when writing the L value.  The alternative would be to set a flag
to say whether an attribute was started.

The spec explicitly allows 0-length attributes in section 12:
"The variable length string attributes, e.g., Device Name, are encoded
without null-termination, i.e., no 0x00 octets added to the end of the
value. If the string is empty, the attribute length is set to zero."
2020-08-25 16:47:34 -05:00
Denis Kenzior 8840d4623d resolve: Support .add_domain_name for resolvconf
Add ability to populate search domains for resolvconf based systems.
Search domains are added using the 'search' directive and added using
the <ifname>.domain key into resolvconf.
2020-08-21 22:41:49 -05:00
Denis Kenzior 65fdc8f2fe resolve: Refactor resolvconf implementation
Introduce a new resolvconf_invoke function that takes care of all the
details of invoking resolvconf and simplify the code a bit.

Introduce have_dns that tracks whether DNS servers were actually
provided.  If no DNS info was provided, do not invoke resolvconf to
remove it.

Instead of interface index, resolvconf is now invoked with the printable
name of the interface and the dns entries are placed in the "dns"
protocol.  This makes it a bit simpler to add additional info to
resolvconf instead of trying to generate a monolithic entry.
2020-08-21 22:41:49 -05:00
Denis Kenzior e58a818ce9 resolve: Refactor resolve module
Resolve module does not currently track any state that has been set on
a per ifindex basis.  This was okay while the set of information we
supported was quite small.  However, with dhcpv6 support being prepared,
a more flexible framework is needed.

Change the resolve API to allocate and return an instance for a given
ifindex that has the ability to track information that was provided.
2020-08-21 22:41:32 -05:00
Denis Kenzior ac5ddda56f treewide: Add missing netdev module dependencies 2020-08-20 11:49:01 -05:00
Denis Kenzior b0fe62af5a scan: free wfd member
Found using lsan:

==29896==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 9 byte(s) in 1 object(s) allocated from:
    #0 0x7fcd41e0c710 in __interceptor_malloc /var/tmp/portage/sys-devel/gcc-8.2.0-r6/work/gcc-8.2.0/libsanitizer/asan/asan_malloc_linux.cc:86
    #1 0x606abd in l_malloc ell/util.c:62
    #2 0x460230 in ie_tlv_vendor_ie_concat src/ie.c:140
    #3 0x4605d1 in ie_tlv_extract_wfd_payload src/ie.c:216
    #4 0x4a8773 in scan_parse_bss_information_elements src/scan.c:1105
    #5 0x4a94a8 in scan_parse_attr_bss src/scan.c:1181
    #6 0x4a99f8 in scan_parse_result src/scan.c:1238
    #7 0x4abe4e in get_scan_callback src/scan.c:1451
    #8 0x6442d9 in process_unicast ell/genl.c:979
    #9 0x6453ff in received_data ell/genl.c:1087
    #10 0x62e1a4 in io_callback ell/io.c:126
    #11 0x628fca in l_main_iterate ell/main.c:473
    #12 0x6294e8 in l_main_run ell/main.c:520
    #13 0x629d8b in l_main_run_with_signal ell/main.c:642
    #14 0x40681b in main src/main.c:505
    #15 0x7fcd40a55bdd in __libc_start_main (/lib64/libc.so.6+0x21bdd)
2020-08-20 11:11:44 -05:00
Andrew Zaborowski df60f0ace6 eap-wsc: Handle the M{1,3,5,7} messages
Parse, validate and respond to the M1, M3, M5 and M7 messages and send
the M2, M4, M6 and M8.
2020-08-17 09:42:40 -05:00
Andrew Zaborowski e768f034a3 eap-wsc: Registrar mode message processing
This commit has all the changes to extend and generalise the current
eap-wsc.c code to handle both the Enrollee and Registrar side of the
protocol, reusing existing functions and structures.
2020-08-17 09:40:25 -05:00
Andrew Zaborowski 50f2b3d0ca eap-wsc: Registrar mode settings loading
Alongside the current EAP-WSC enrollee side support, add the initial
part of registrar side.  In the same file, register a new method with
the name string of "WSC-R".  In this patch only the load_settings
method is added.  validate_identity and handle_response are added in
later patches.
2020-08-17 09:38:16 -05:00
Andrew Zaborowski 4c64e0d560 eapol: Basic EAP support in authenticator mode
Handle EAPoL-EAP frames using our eap.c methods in authenticator mode
same as we do on the supplicant side.  The user (ap.c) will only need to
set a valid 8021x_settings in the handshake object, same as on the
supplicant side.
2020-08-17 09:33:51 -05:00
Andrew Zaborowski 17c569ba4c eap: Add authenticator method logic and API
The goal is to add specifically EAP-WSC registrar side and it looks like
extending our EAP and EAPoL code to support both supplicant and
authenticator-side methods is simpler than adding just EAP-WSC as a
special case.

Since EAP-WSC always ends in an EAP failure, I haven't actually tested
the success path.
2020-08-17 09:28:49 -05:00
Andrew Zaborowski 1f910f84b4 eapol: Use eapol_start in authenticator mode too
On the supplicant side eapol_register would only register the eapol_sm
on a given netdev to start receiving frames and an eapol_start call is
required for the state machine to start executing.  On the authenticator
side we shouldn't have the "early frame" problem but there's no reason
for the semantics of the two methods to be different.  Somehow we were
doing everything in eapol_register and not using eapol_start if
hs->authenticator was true, so bring this in line with the supplicant
side and require eapol_start to be called also from ap.c.
2020-08-17 09:25:50 -05:00
Andrew Zaborowski 49f38b0d2e station: Don't call network_rank_update with NULL network
Move the update of station->networks_sorted order to before we set
station->connected_network NULL to avoid a crash when we attempt to
use the NULL pointer.
2020-08-17 09:25:33 -05:00
Alvin Šipraga bfd8cead95 treewide: guard compare functions against signed integer overflow
Besides being undefined behaviour, signed integer overflow can cause
unexpected comparison results. In the case of network_rank_compare(),
a connected network with rank INT_MAX would cause newly inserted
networks with negative rank to be inserted earlier in the ordered
network list. This is reflected in the GetOrderedMethods() DBus method
as can be seen in the following iwctl output:

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

This fixes the documented behaviour of GetOrderedNetworks() DBus method,
which states that the currently connected network is always at the
beginning of the returned array.
2020-08-14 10:55:22 -05:00
Denis Kenzior 4fbfa76fc5 wiphy: Fix not attempting WPA3 connections for APs in transition mode
Fix a logic error which prevented iwd from using SAE/WPA3 when
attempting to connect to APs that are in transition mode.  The SAE/WPA3
check incorrectly required mfpr bit to be set, which is true for
APs in WPA3-Personal only mode, but is set to 0 for APs in
WPA3-Personal transition mode.

This patch also adds a bit more diagnostic output to help diagnose
causes for connections where WPA3 is not attempted even when advertised
by the AP.
2020-08-13 14:27:14 -05:00
Denis Kenzior 9e98a74efd common: Remove duplicate AKM 2020-08-13 13:43:31 -05:00
Andrew Zaborowski 0480989a73 eap-wsc: Zero a temporary buffer before freeing 2020-08-13 10:39:48 -05:00
Andrew Zaborowski 45d74ac1ed eap-wsc: Validate enrollee_nonce (N1) in M{2,4,6,8} 2020-08-13 10:39:17 -05:00
Andrew Zaborowski c826dd0052 eap: Simplify sending EAP method responses
Replace the usage of eap_send_response() in the method implementations
with a new eap_method_respond that skips the redundant "type" parameter.
The new eap_send_packet is used inside eap_method_respond and will be
reused for sending request packets in authenticator side EAP methods.
2020-08-13 10:36:43 -05:00
Andrew Zaborowski 8a5861d3f5 eapol: Use eapol_sm_write in authenticator mode
Throughout the supplicant mode we'd use the eapol_sm_write wrapper but
in the authenticator mode we'd call __eapol_tx_packet directly.  Adapt
eapol_sm_write to use the right destination address and use it
consistently.
2020-08-13 10:14:21 -05:00
Andrew Zaborowski 225a28f364 eapol: Don't try setting protocol_version in eapol_rx_auth_packet
In authenticator mode we'll always have protocol_version set from the
start so the condition is always going to be false.
2020-08-13 10:14:05 -05:00
Andrew Zaborowski b40d7460b3 eapol: Don't re-build the AP RSNE in authenticator mode
sm->handshake already contains our RSN/WPA IE so there's no need to
rebuild it for msg 3/4, especially since we hardcode the fact that we
only support one pairwise cipher.  If we start declaring more supported
ciphers and need to include a second RSNE we can first parse
sm->hs->authenticator_ie into a struct ir_rsn_info, overwrite the cipher
and rebuild it from that struct.

This way we duplicate less code and we hardcode fewer facts about the AP
in eapol.c which also helps in adding EAP-WSC.
2020-08-13 10:12:07 -05:00
Andrew Zaborowski 69259b3a3f eapol: Use the require_handshake flag for FILS
In both FT or FILS EAPoL isn't used for the initial handshake and only
for the later re-keys.  For FT we added the
eapol_sm_set_require_handshake mechanism to tell EAPoL to not require
the initial handshake and we can re-use it for FILS.
2020-08-13 10:10:54 -05:00
Andrew Zaborowski a95cd4f0fa wscutil: Handle a deprecated network key format
Implement a note from the spec saying that implementations should handle
NUL-terminated Network Keys inside credentials structures.
2020-08-13 10:10:51 -05:00
Mathy Vanhoef f22ba5aebb eapol: prevent key reinstallation on retransmitted Msg4/4
Currently an adversary can retransmit EAPOL Msg4/4 to make the AP
reinstall the PTK. Against older Linux kernels this can subsequently
be used to decrypt, replay, and possibly decrypt frames. See the
KRACK attacks research at krackattacks.com for attack scenarios.
In this case no machine-in-the-middle position is needed to trigger
the key reinstallation.

Fix this by using the ptk_complete boolean to track when the 4-way
handshake has completed (similar to its usage for clients). When
receiving a retransmitted Msg4/4 accept this frame but do not reinstall
the PTK.

Credits to Chris M. Stone, Sam Thomas, and Tom Chothia of Birmingham
University to help discover this issue.
2020-08-12 09:51:20 -05:00
Andrew Zaborowski 59ce53ceb2 ap: Add authorized_macs parameter 2020-08-04 10:41:45 -05:00
Andrew Zaborowski 887f679023 ap: Add a no_cck_rates flag 2020-08-04 10:41:45 -05:00
Andrew Zaborowski 30933423fd ap: Put a public api between AP logic and DBus code
Separate AP logic from DBus code, add a public API to make the AP
logic reusable from other files.
2020-08-04 10:41:42 -05:00
Andrew Zaborowski 1d852e10ad scan: Always allocate results->bss_list
Instead of creating the results->bss_list l_queue lazily, always create
one before sending the GET_SCAN command.  This is to make sure that an
empty list is passed to the scan callback (e.g. in station.c) instead of
a NULL.  Passing NULL has been causing difficult to debug crashes in
station.c, in fact I think I've been seeing them for over a year now
but can't be sure.  station_set_scan_results has been taking ownership
of the new BSS list and, if station->connected_bss was not on the list,
it would try to add it not realizing that l_queue_push_tail() was doing
nothing.  Always passing a valid list may help us prevent similar
problems in the future.

The crash might start with:
==120489== Invalid read of size 8
==120489==    at 0x425D38: network_bss_select (network.c:709)
==120489==    by 0x415BD1: station_try_next_bss (station.c:2263)
==120489==    by 0x415E31: station_retry_with_status (station.c:2323)
==120489==    by 0x415E31: station_connect_cb (station.c:2367)
==120489==    by 0x407E66: netdev_connect_failed (netdev.c:569)
==120489==    by 0x40B93D: netdev_connect_event (netdev.c:1801)
==120489==    by 0x40B93D: netdev_mlme_notify (netdev.c:3678)
2020-08-04 10:30:07 -05:00