Commit Graph

123 Commits

Author SHA1 Message Date
James Prestwood 701a5cc41e network: store HESSID and NAI Realms in network object
Hotspot networks are supposed to include an HESSID in the scan
results. This is more or less an identifier for the overall
network. In addition, the NAI Realms can be obtained via ANQP
and should be the same for each BSS. Since both HESSID and NAI
realms should be the same for a given network in range we can
store these values in the network object itself. This also allows
us to easily find hotspot configuration files by looking at
the HESSID/NAI Realms directly in the network object as opposed
to individual scan_bss's.
2019-06-26 13:23:22 -05:00
Denis Kenzior 4cfcb9c88d network: Convert to use IWD_MODULE 2019-05-22 10:20:10 -05:00
Tim Kourt c3e79a4f2a network: Introduce a concept of known frequencies
Each known network (previously connected) will have a set
of known frequencies associated with it, e.g. a set of
frequencies from all BSSs observed. The list of known
frequencies is sorted with the most recently observed
frequency in the head.
2019-04-15 12:29:48 -05:00
Tim Kourt 531bb3f0b5 knownnetworks: Load Autoconnect along with other settings
Previously, 'Autoconnect' setting was loaded only at the
connection time, this patch makes autoconnect to load along
with other settings.
2019-04-11 10:55:22 -05:00
Marcel Holtmann 3f3e778719 build: Add support for including fallbacks for missing defines 2019-04-03 18:34:22 +02:00
Andrew Zaborowski 3ca8a18b4e network: Clear psk and passphrase copies before freeing 2019-03-22 14:04:08 -05:00
James Prestwood 64dedd9aa5 network: add APIs to blacklist BSS's per-network
Certain error conditions require that a BSS be blacklisted only for
the duration of the current connection. The existing blacklist
does not allow for this, and since this blacklist is shared between
all interfaces it doesnt make sense to use it for this purpose.

Instead, each network object can contain its own blacklist of
scan_bss elements. New elements can be added with network_blacklist_add.
The blacklist is cleared when the connection completes, either
successfully or not.

Now inside network_bss_select both the per-network blacklist as well as
the global blacklist will be checked before returning a BSS.
2019-03-01 13:08:01 -06:00
James Prestwood 025ca0d4d3 network: allow network_bss_select to skip blacklist
If we have a BSS list where all BSS's have been blacklisted we still
need a way to force a connection to that network, instead of having
to wait for the blacklist entry to expire. network_bss_select now
takes a boolean 'fallback_to_blacklist' which causes the selection
to still return a connectable BSS even if the entire list was
blacklisted.

In most cases this is set to true, as these cases are initiated by
DBus calls. The only case where this is not true is inside
station_try_next_bss, where we do want to honor the blacklist.
This both prevents an explicit connect call (where all BSS's are
blacklisted) from trying all the blacklisted BSS's, as well as the
autoconnect case where we simply should not try to connect if all
the BSS's are blacklisted.

There are is some implied behavior here that may not be obvious:

On an explicit DBus connect call IWD will attempt to connect to
any non-blacklisted BSS found under the network. If unsuccessful,
the current BSS will be blacklisted and IWD will try the next
in the list. This will repeat until all BSS's are blacklisted,
and in this case the connect call will fail.

If a connect is tried again when all BSS's are blacklisted IWD
will attempt to connect to the first connectable blacklisted
BSS, and if this fails the connect call will fail. No more
connection attempts will happen until the next DBus call.
2019-01-31 12:36:58 -06:00
James Prestwood 45cc0fd918 network/station: add BSS blacklisting
If IWD fails to connect to a BSS we can attempt to connect to a different
BSS under the same network and blacklist the first BSS. In the case of an
incorrect PSK (MMPDU code 2 or 23) we will still fail the connection.

station_connect_cb was refactored to better handle the dbus case. Now the
netdev result switch statement is handled before deciding whether to send
a dbus reply. This allows for both cases where we are trying to connect
to the next BSS in autoconnect, as well as in the dbus case.
2019-01-30 13:23:38 -06:00
Denis Kenzior 782bd4a7ae network: Reset connected_time when forgetting
If a network is being forgotten, then make sure to reset connected_time.
Otherwise the rank logic thinks that the network is known which can
result in network_find_rank_index returning -1.

Found by sanitizer:
src/network.c:1329:23: runtime error: index -1 out of bounds for type
	'double [64]'
2019-01-11 17:28:10 -06:00
Andrew Zaborowski 47bb5b5f72 network: Generate the PSK as soon as we have a passphrase
In the name of failing earlier try to generate the PSK from the
passphrase as soon as we receive the passphrase or read it from the
file, mainly to validate it has the right number of characters.
The passphrase length currently gets validates inside
crypto_psk_from_passphrase which will be called when we receive a new
passphrase from the agent or when the config file has no PSK in it.  We
do not do this when there's already both the PSK and the passphrase
available in the settings -- we can add that separately if needed.
2018-12-03 14:17:30 -06:00
Denis Kenzior 712a92cc4c network: Simplify is_rsn logic
In the current version SECURITY_PSK was handled inside the is_rsn block
while the SECURITY_8021X was off in its own block.  This was weird and a
bit misleading.  Simplify the code flow through the use of a goto and
decrease the nesting level.

Also optimize out unnecessary use of scan_bss_get_rsn_info
2018-11-15 11:37:20 -06:00
Denis Kenzior 5bfbdd5a01 network: Check Autoconnectable as the first condition 2018-11-15 11:31:39 -06:00
Denis Kenzior c146490567 network: Introduce __bss_is_sae
This takes an rsn_info pointer directly so that some calls to
scan_bss_get_rsn_info can be optimized
2018-11-15 11:29:13 -06:00
James Prestwood ad242a796a network: fix 8021x autoconnect
In network_autoconnect, when the network was SECURITY_8021X there was no
check (for SECURITY_PSK) before calling network_load_psk. Since the
provisioning file was for an 8021x network neither PreSharedKey or
Passphrase existed so this would always fail. This fixes the 8021x failure
in testConnectAutoconnect.
2018-11-15 11:20:06 -06:00
Andrew Zaborowski 0b5dceab27 network: Don't require PSK if Passphrase present
Refactor the network->psk and network->passphrase loading and saving
logic to not require the PreSharedKey entry in the psk config file and
to generate network->psk lazily on request.  Still cache the computed
PSK in memory and in the .psk file to avoid recomputing it which uses
many syscalls.  While there update the ask_psk variable to
ask_passphrase because we're specifically asking for the passphrase.
2018-11-05 12:43:16 -06:00
Marcel Holtmann 554e4f55db build: Fix includes for using with -std=c99 compiler option 2018-11-01 22:37:11 +01:00
Marcel Holtmann 9335602ba0 network: Removed unneeded include for src/watchlist.h 2018-11-01 10:19:26 +01:00
James Prestwood 996a18e934 network: free EAP_CACHE_NEVER secret types
When freeing a network secrets any secrets labeled with CACHE_NEVER
would get removed from the secret queue but never actually freed.
2018-09-19 14:33:23 -05:00
Tim Kourt b5aefede95 network: add check for the existing settings
In the case of the open networks with hidden SSIDs
the settings object is already created.

Valgrind:
==4084==    at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
==4084==    by 0x43B44D: l_malloc (util.c:62)
==4084==    by 0x43E3FA: l_settings_new (settings.c:83)
==4084==    by 0x41D101: network_connect_new_hidden_network (network.c:1053)
==4084==    by 0x4105B7: station_hidden_network_scan_results (station.c:1733)
==4084==    by 0x419817: scan_finished (scan.c:1165)
==4084==    by 0x419CAA: get_scan_done (scan.c:1191)
==4084==    by 0x443562: destroy_request (genl.c:139)
==4084==    by 0x4437F7: process_unicast (genl.c:424)
==4084==    by 0x4437F7: received_data (genl.c:534)
==4084==    by 0x440958: io_callback (io.c:123)
==4084==    by 0x43FDED: l_main_iterate (main.c:376)
==4084==    by 0x43FEAB: l_main_run (main.c:423)
2018-09-19 11:52:33 -05:00
Denis Kenzior 25f36f5644 station: Move remaining connect/re-connect/roam logic 2018-09-04 23:57:14 -05:00
Denis Kenzior 12ce9debec station: Move device_disconnect to station 2018-09-04 23:57:14 -05:00
Denis Kenzior 187ea7f5d1 device/network: Use station_is_busy 2018-09-04 23:57:14 -05:00
Denis Kenzior dcfdd0ccde network: Use station_foreach
Instead of __iwd_device_foreach api, use the newly introduced
station_foreach API
2018-09-04 23:57:14 -05:00
Denis Kenzior 993a69cef8 network: Make network station centric 2018-09-04 23:57:14 -05:00
Denis Kenzior 738faa7657 network: Pass connected state to network_rank_update 2018-09-04 23:57:14 -05:00
Denis Kenzior 966cad3696 network: Remove unused function 2018-09-04 23:57:14 -05:00
Andrew Zaborowski da96b5c51c network: Use is_known to save queue lookups
Now that the is_known field is back use it instead of searching the
"networks" queue where possible.
2018-08-20 11:37:07 -05:00
Denis Kenzior 47beec30f9 network: Implement Network.KnownNetwork property 2018-08-14 14:57:16 -05:00
James Prestwood 920b307431 network: require Passphrase on psk files
For an SAE network, the raw passphrase is required. For this reason,
known network psk files should now always contain a 'Passphrase' entry.

If a psk file is found without a Passphrase entry the agent will be asked
for the Passphrase before connecting. This will update the legacy psk
file with the Passphrase entry.
2018-08-13 20:40:59 -05:00
Denis Kenzior c38b77d0c0 network: Fix syncing the PSK on 1st connection
The previous change did not consider the case of the PSK being written
for the very first time.  In this case storage_network_open would return
NULL and an empty file would be written.

Change this so that if storage_network_open fails, then the current
network settings are written to disk and not a temporary.
2018-08-10 12:13:44 -05:00
Andrew Zaborowski abeed797c0 network: Reload settings in network_sync_psk
Reload the network settings from disk before calling
storage_network_sync in network_sync_psk to avoid potentially
overwriting changes made to the storage by user since the connection
attempt started.  This won't account for all situations but it
covers some of them and doesn't cost us much.
2018-08-10 09:44:16 -05:00
Andrew Zaborowski 4b4875e6cf knownnetworks: Watch filesystem events in STORAGEDIR
Update the known networks list and network properties on file creations,
removals and modifications.  We watch for these filesystem events using
ell's fswatch and react accordingly.
2018-08-09 10:35:37 -05:00
Andrew Zaborowski ca270e9de2 network: Drop actions to be handled by filesystem watch 2018-08-09 10:27:28 -05:00
Andrew Zaborowski 4ffb97faa1 eap: Add secret cache policy types
eap_append_secret now takes a new cache_policy parameter which can be
used by the EAP method to signal that the value received from the agent
is to never be cached, i.e. each value can only be used once.  The
parameter value should be EAP_CACHE_NEVER for this and we use this in
value EAP-GTC where the secret tokens are one time use.  The
EAP_CACHE_TEMPORARY value is used in other methods, it preserves the
default behaviour where a secret can be cached for as long as the
network stays in range (this is the current implementation more than a
design choice I believe, I didn't go for a more specific enum name as
this may still change I suppose).
2018-08-08 19:43:05 -05:00
James Prestwood 35278ae108 network: save passphrase in network
SAE needs access to the raw passphrase, not the PSK which network
saves. This changes saves the passphrase in network and handshake
objects, as well as adds getters to both objects so SAE can retrieve
the passphrase.
2018-08-07 17:39:16 -05:00
Andrew Zaborowski e1634baae4 storage: Take enum security instead of string as parameter
Make the network_storage_* functions uniformly accept an enum value
instead of a string so that he conversion to string doesn't need to
happen in all callers.
2018-08-01 09:38:52 -05:00
Andrew Zaborowski 319b6416de network: Stop tracking network last seen times
Drop the corresponding network_info field, function and D-Bus property.
The last seen times didn't seem useful but if a client needs them it can
probably implement the same logic with the information already available
through DBus.
2018-07-31 10:55:32 -05:00
Andrew Zaborowski 215162a49e network: Don't free known networks in network_info_put
Fix a double free resulting from network.c freeing a known network when
it goes out of range due to a missing check.
2018-07-30 08:55:27 -05:00
Andrew Zaborowski 97913c6f9a network: Refactor and move Known Networks management
Until now network.c managed the list of network_info structs including
for known networks and networks that are seen in at least one device's
scan results, with the is_known flag to distinguish known networks.
Each time the list was processed though the code was either interested
in one subset of networks or the other.  Split the list into a Known
Networks list and the list of other networks seen in scans.  Move all
code related to Known Networks to knownnetworks.c, this simplifies
network.h.  It also gets rid of network_info_get_known which actually
returned the list of all network_infos (not just for known networks),
which logically should have been private to network.c.  Update device.c
and scan.c to use functions specific to Known Networks instead of
filtering the lists by the is_known flag.

This will also allow knownnetworks.c to export DBus objects and/or
properties for the Known Networks information because it now knows when
Known Networks are added, removed or modified by IWD.
2018-07-25 09:40:14 -05:00
Andrew Zaborowski c2abc212ad network: Make networks_connected return void
The return value from network_connected is not checked and even if one
of the storage operations fails the function should probably continue
so only print a message on error.
2018-07-23 11:46:49 -05:00
Denis Kenzior 87108984bc network: set Hidden=true for new hidden networks 2018-07-11 16:09:42 -05:00
Tim Kourt d8c8ebdf3a device: enable connection to the hidden networks
1) Change signature of process_bss to return a confirmation
   that bss has been added to a network otherwise we can
   discard it.

2) Implements logic for the discovery and connection to
   a hidden network.
2018-07-11 15:36:14 -05:00
Tim Kourt 72c6862255 network: add network info accessors
This adds the accessors for the hidden field in network
info. In addition, it provides a lookup of the network infos
by ssid and security type.
2018-07-11 15:20:55 -05:00
Tim Kourt d2feb535a5 network: implement a counter for the hidden networks 2018-07-11 10:36:40 -05:00
Tim Kourt d1a8e191e9 network: introduce connect API for the hidden nets 2018-07-11 10:19:43 -05:00
Denis Kenzior fb1296e9c0 network: Add network_info_get_known 2018-07-02 13:03:03 -05:00
Denis Kenzior 057b019550 network: Use __device_connect_network
In network_autoconnect, use the low-level version of
device_connect_network
2018-07-02 12:28:10 -05:00
Tim Kourt 5ded4890a6 network: introduce the concept of hidden networks 2018-06-29 13:51:12 -05:00
Tim Kourt ef5110869b network: Add stub for network_info_has_hidden 2018-06-28 15:06:11 -05:00