2018-08-31 20:24:26 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-04-16 23:51:42 +02:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation. All rights reserved.
|
2018-08-31 20:24:26 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2018-11-01 22:37:11 +01:00
|
|
|
#define _GNU_SOURCE
|
2018-09-01 23:21:28 +02:00
|
|
|
#include <stdio.h>
|
2018-08-31 20:24:26 +02:00
|
|
|
#include <errno.h>
|
2018-09-04 20:48:18 +02:00
|
|
|
#include <time.h>
|
2018-11-01 22:37:11 +01:00
|
|
|
#include <sys/time.h>
|
2021-01-22 14:37:01 +01:00
|
|
|
#include <limits.h>
|
2018-09-04 20:48:18 +02:00
|
|
|
#include <linux/if_ether.h>
|
2018-08-31 20:24:26 +02:00
|
|
|
|
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2021-06-04 16:20:47 +02:00
|
|
|
#include "ell/useful.h"
|
2018-08-31 20:24:26 +02:00
|
|
|
#include "src/util.h"
|
|
|
|
#include "src/iwd.h"
|
2019-11-07 23:33:51 +01:00
|
|
|
#include "src/module.h"
|
2018-08-31 20:24:26 +02:00
|
|
|
#include "src/common.h"
|
2018-09-04 17:40:45 +02:00
|
|
|
#include "src/watchlist.h"
|
2018-08-31 20:24:26 +02:00
|
|
|
#include "src/scan.h"
|
|
|
|
#include "src/netdev.h"
|
2018-09-05 00:32:18 +02:00
|
|
|
#include "src/dbus.h"
|
2018-09-01 00:44:10 +02:00
|
|
|
#include "src/wiphy.h"
|
2018-08-31 20:24:26 +02:00
|
|
|
#include "src/network.h"
|
2018-09-05 00:32:18 +02:00
|
|
|
#include "src/knownnetworks.h"
|
2018-09-01 00:44:10 +02:00
|
|
|
#include "src/ie.h"
|
|
|
|
#include "src/handshake.h"
|
2018-08-31 20:24:26 +02:00
|
|
|
#include "src/station.h"
|
2019-01-29 21:36:12 +01:00
|
|
|
#include "src/blacklist.h"
|
|
|
|
#include "src/mpdu.h"
|
2019-04-22 19:11:46 +02:00
|
|
|
#include "src/erp.h"
|
2019-06-26 00:21:01 +02:00
|
|
|
#include "src/netconfig.h"
|
2019-06-27 00:15:57 +02:00
|
|
|
#include "src/anqp.h"
|
2019-07-15 21:27:02 +02:00
|
|
|
#include "src/anqputil.h"
|
2021-01-22 21:38:42 +01:00
|
|
|
#include "src/diagnostic.h"
|
2021-04-19 23:58:53 +02:00
|
|
|
#include "src/frame-xchg.h"
|
2021-11-03 23:15:01 +01:00
|
|
|
#include "src/sysfs.h"
|
2021-11-30 00:12:59 +01:00
|
|
|
#include "src/band.h"
|
2022-09-27 21:47:28 +02:00
|
|
|
#include "src/ft.h"
|
2022-11-17 14:56:10 +01:00
|
|
|
#include "src/eap.h"
|
|
|
|
#include "src/eap-tls-common.h"
|
|
|
|
#include "src/storage.h"
|
2018-08-31 20:24:26 +02:00
|
|
|
|
|
|
|
static struct l_queue *station_list;
|
2018-09-05 04:50:18 +02:00
|
|
|
static uint32_t netdev_watch;
|
2019-10-25 04:15:17 +02:00
|
|
|
static uint32_t mfp_setting;
|
2021-01-22 14:37:01 +01:00
|
|
|
static uint32_t roam_retry_interval;
|
2019-10-25 06:18:23 +02:00
|
|
|
static bool anqp_disabled;
|
2021-11-03 23:15:01 +01:00
|
|
|
static bool supports_arp_evict_nocarrier;
|
|
|
|
static bool supports_ndisc_evict_nocarrier;
|
2021-09-15 19:36:18 +02:00
|
|
|
static struct watchlist event_watches;
|
2022-11-17 14:56:10 +01:00
|
|
|
static uint32_t known_networks_watch;
|
2023-09-28 14:41:27 +02:00
|
|
|
static uint32_t allowed_bands;
|
2018-08-31 20:24:26 +02:00
|
|
|
|
2018-09-15 04:53:01 +02:00
|
|
|
struct station {
|
|
|
|
enum station_state state;
|
|
|
|
struct watchlist state_watches;
|
|
|
|
struct scan_bss *connected_bss;
|
|
|
|
struct network *connected_network;
|
2019-07-24 03:12:57 +02:00
|
|
|
struct scan_bss *connect_pending_bss;
|
|
|
|
struct network *connect_pending_network;
|
2018-09-15 04:53:01 +02:00
|
|
|
struct l_queue *autoconnect_list;
|
|
|
|
struct l_queue *bss_list;
|
2018-11-09 01:25:21 +01:00
|
|
|
struct l_queue *hidden_bss_list_sorted;
|
2018-09-15 04:53:01 +02:00
|
|
|
struct l_hashmap *networks;
|
|
|
|
struct l_queue *networks_sorted;
|
|
|
|
struct l_dbus_message *connect_pending;
|
2020-06-10 03:22:19 +02:00
|
|
|
struct l_dbus_message *hidden_pending;
|
2018-09-15 04:53:01 +02:00
|
|
|
struct l_dbus_message *disconnect_pending;
|
|
|
|
struct l_dbus_message *scan_pending;
|
2021-01-14 21:54:40 +01:00
|
|
|
struct l_dbus_message *get_station_pending;
|
2018-09-15 04:53:01 +02:00
|
|
|
struct signal_agent *signal_agent;
|
2019-03-22 22:17:43 +01:00
|
|
|
uint32_t dbus_scan_id;
|
2019-04-16 23:51:42 +02:00
|
|
|
uint32_t quick_scan_id;
|
2018-10-06 02:55:55 +02:00
|
|
|
uint32_t hidden_network_scan_id;
|
2021-09-18 00:58:38 +02:00
|
|
|
struct l_queue *owe_hidden_scan_ids;
|
2018-09-15 04:53:01 +02:00
|
|
|
|
|
|
|
/* Roaming related members */
|
|
|
|
struct timespec roam_min_time;
|
|
|
|
struct l_timeout *roam_trigger_timeout;
|
|
|
|
uint32_t roam_scan_id;
|
|
|
|
uint8_t preauth_bssid[6];
|
|
|
|
|
|
|
|
struct wiphy *wiphy;
|
|
|
|
struct netdev *netdev;
|
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
struct l_queue *anqp_pending;
|
|
|
|
|
2019-09-27 21:52:17 +02:00
|
|
|
struct netconfig *netconfig;
|
|
|
|
|
2020-11-17 00:54:00 +01:00
|
|
|
/* Set of frequencies to scan first when attempting a roam */
|
|
|
|
struct scan_freq_set *roam_freqs;
|
2022-09-27 21:47:24 +02:00
|
|
|
struct l_queue *roam_bss_list;
|
2020-11-17 00:54:00 +01:00
|
|
|
|
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 02:28:58 +01:00
|
|
|
/* Frequencies split into subsets by priority */
|
|
|
|
struct scan_freq_set *scan_freqs_order[3];
|
|
|
|
unsigned int dbus_scan_subset_idx;
|
|
|
|
|
2022-08-04 20:51:09 +02:00
|
|
|
uint32_t wiphy_watch;
|
|
|
|
|
2022-09-27 21:47:28 +02:00
|
|
|
struct wiphy_radio_work_item ft_work;
|
|
|
|
|
2023-10-30 14:48:37 +01:00
|
|
|
uint64_t last_roam_scan;
|
|
|
|
|
2018-09-15 04:53:01 +02:00
|
|
|
bool preparing_roam : 1;
|
2020-06-30 19:34:41 +02:00
|
|
|
bool roam_scan_full : 1;
|
2018-09-15 04:53:01 +02:00
|
|
|
bool signal_low : 1;
|
|
|
|
bool ap_directed_roaming : 1;
|
|
|
|
bool scanning : 1;
|
|
|
|
bool autoconnect : 1;
|
2021-09-16 21:00:01 +02:00
|
|
|
bool autoconnect_can_start : 1;
|
2023-05-02 20:59:41 +02:00
|
|
|
bool netconfig_after_roam : 1;
|
2018-09-15 04:53:01 +02:00
|
|
|
};
|
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
struct anqp_entry {
|
|
|
|
struct station *station;
|
|
|
|
struct network *network;
|
|
|
|
uint32_t pending;
|
|
|
|
};
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
/*
|
|
|
|
* Used as entries for the roam list since holding scan_bss pointers directly
|
|
|
|
* from station->bss_list is not 100% safe due to the possibility of the
|
|
|
|
* hardware scanning and overwriting station->bss_list.
|
|
|
|
*/
|
|
|
|
struct roam_bss {
|
|
|
|
uint8_t addr[6];
|
|
|
|
uint16_t rank;
|
|
|
|
int32_t signal_strength;
|
2023-08-31 14:39:23 +02:00
|
|
|
bool ft_failed: 1;
|
2022-09-27 21:47:24 +02:00
|
|
|
};
|
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
static struct roam_bss *roam_bss_from_scan_bss(const struct scan_bss *bss,
|
|
|
|
uint16_t rank)
|
2022-09-27 21:47:24 +02:00
|
|
|
{
|
|
|
|
struct roam_bss *rbss = l_new(struct roam_bss, 1);
|
|
|
|
|
|
|
|
memcpy(rbss->addr, bss->addr, 6);
|
2023-08-31 14:39:23 +02:00
|
|
|
rbss->rank = rank;
|
2022-09-27 21:47:24 +02:00
|
|
|
rbss->signal_strength = bss->signal_strength;
|
2023-08-31 14:39:23 +02:00
|
|
|
rbss->ft_failed = false;
|
2022-09-27 21:47:24 +02:00
|
|
|
|
|
|
|
return rbss;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int roam_bss_rank_compare(const void *a, const void *b, void *user_data)
|
|
|
|
{
|
|
|
|
const struct roam_bss *new_bss = a, *bss = b;
|
|
|
|
|
|
|
|
if (bss->rank == new_bss->rank)
|
|
|
|
return (bss->signal_strength >
|
|
|
|
new_bss->signal_strength) ? 1 : -1;
|
|
|
|
|
|
|
|
return (bss->rank > new_bss->rank) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2018-09-04 22:33:46 +02:00
|
|
|
struct wiphy *station_get_wiphy(struct station *station)
|
|
|
|
{
|
|
|
|
return station->wiphy;
|
|
|
|
}
|
|
|
|
|
2018-09-04 22:34:17 +02:00
|
|
|
struct netdev *station_get_netdev(struct station *station)
|
|
|
|
{
|
|
|
|
return station->netdev;
|
|
|
|
}
|
|
|
|
|
2018-09-04 22:38:56 +02:00
|
|
|
struct network *station_get_connected_network(struct station *station)
|
|
|
|
{
|
|
|
|
return station->connected_network;
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:26:13 +02:00
|
|
|
bool station_is_busy(struct station *station)
|
|
|
|
{
|
2022-10-09 15:27:44 +02:00
|
|
|
return station->state != STATION_STATE_DISCONNECTED &&
|
2019-03-22 22:17:45 +01:00
|
|
|
station->state != STATION_STATE_AUTOCONNECT_FULL &&
|
2022-10-09 15:27:44 +02:00
|
|
|
station->state != STATION_STATE_AUTOCONNECT_QUICK;
|
2018-09-04 23:26:13 +02:00
|
|
|
}
|
|
|
|
|
2019-03-22 22:17:45 +01:00
|
|
|
static bool station_is_autoconnecting(struct station *station)
|
|
|
|
{
|
|
|
|
return station->state == STATION_STATE_AUTOCONNECT_FULL ||
|
|
|
|
station->state == STATION_STATE_AUTOCONNECT_QUICK;
|
|
|
|
}
|
|
|
|
|
2022-09-28 20:33:50 +02:00
|
|
|
static bool station_is_roaming(struct station *station)
|
|
|
|
{
|
|
|
|
return station->state == STATION_STATE_ROAMING ||
|
|
|
|
station->state == STATION_STATE_FT_ROAMING ||
|
|
|
|
station->state == STATION_STATE_FW_ROAMING;
|
|
|
|
}
|
|
|
|
|
2021-08-13 21:47:08 +02:00
|
|
|
static bool station_debug_event(struct station *station, const char *name)
|
|
|
|
{
|
|
|
|
struct l_dbus_message *signal;
|
|
|
|
|
|
|
|
if (!iwd_is_developer_mode())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
l_debug("StationDebug.Event(%s)", name);
|
|
|
|
|
|
|
|
signal = l_dbus_message_new_signal(dbus_get_bus(),
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DEBUG_INTERFACE, "Event");
|
|
|
|
|
|
|
|
l_dbus_message_set_arguments(signal, "sav", name, 0);
|
|
|
|
|
|
|
|
return l_dbus_send(dbus_get_bus(), signal) != 0;
|
|
|
|
}
|
|
|
|
|
2019-03-22 22:17:42 +01:00
|
|
|
static void station_property_set_scanning(struct station *station,
|
|
|
|
bool scanning)
|
|
|
|
{
|
|
|
|
if (station->scanning == scanning)
|
|
|
|
return;
|
|
|
|
|
|
|
|
station->scanning = scanning;
|
|
|
|
|
|
|
|
l_dbus_property_changed(dbus_get_bus(),
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_INTERFACE, "Scanning");
|
|
|
|
}
|
|
|
|
|
2019-01-29 21:36:11 +01:00
|
|
|
static void station_enter_state(struct station *station,
|
|
|
|
enum station_state state);
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
static void network_add_foreach(struct network *network, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_queue_insert(station->autoconnect_list, network,
|
|
|
|
network_rank_compare, NULL);
|
|
|
|
}
|
|
|
|
|
2021-05-25 01:04:05 +02:00
|
|
|
static int station_autoconnect_next(struct station *station)
|
2018-09-01 22:15:47 +02:00
|
|
|
{
|
2021-05-07 22:26:17 +02:00
|
|
|
struct network *network;
|
2018-09-01 22:15:47 +02:00
|
|
|
int r;
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
if (!station->autoconnect_list)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2021-05-07 22:26:17 +02:00
|
|
|
while ((network = l_queue_pop_head(station->autoconnect_list))) {
|
|
|
|
const char *ssid = network_get_ssid(network);
|
|
|
|
struct scan_bss *bss = network_bss_select(network, false);
|
2021-05-04 17:09:18 +02:00
|
|
|
|
2021-05-19 16:56:59 +02:00
|
|
|
l_debug("autoconnect: Trying SSID: %s", ssid);
|
2018-09-01 22:15:47 +02:00
|
|
|
|
2021-05-19 16:56:59 +02:00
|
|
|
if (!bss) {
|
|
|
|
l_debug("autoconnect: No suitable BSSes found");
|
2019-01-29 21:36:12 +01:00
|
|
|
continue;
|
2021-05-19 16:56:59 +02:00
|
|
|
}
|
2019-01-29 21:36:12 +01:00
|
|
|
|
2021-05-19 16:56:59 +02:00
|
|
|
l_debug("autoconnect: '%s' freq: %u, rank: %u, strength: %i",
|
|
|
|
util_address_to_string(bss->addr),
|
|
|
|
bss->frequency, bss->rank,
|
|
|
|
bss->signal_strength);
|
2018-09-01 22:15:47 +02:00
|
|
|
|
2021-05-19 16:56:59 +02:00
|
|
|
r = network_autoconnect(network, bss);
|
2019-01-29 21:36:11 +01:00
|
|
|
if (!r) {
|
2021-02-05 01:06:02 +01:00
|
|
|
if (station->quick_scan_id) {
|
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
|
|
|
station->quick_scan_id);
|
|
|
|
station->quick_scan_id = 0;
|
2021-03-29 17:35:31 +02:00
|
|
|
station_property_set_scanning(station, false);
|
2021-02-05 01:06:02 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 01:04:05 +02:00
|
|
|
return 0;
|
2022-01-11 18:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("autoconnect: network_autoconnect: %s (%d)",
|
|
|
|
strerror(-r), r);
|
2018-09-01 22:15:47 +02:00
|
|
|
}
|
2021-05-25 01:04:05 +02:00
|
|
|
|
|
|
|
return -ENOENT;
|
2018-09-01 22:15:47 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
static void station_autoconnect_start(struct station *station)
|
|
|
|
{
|
2021-09-16 21:00:01 +02:00
|
|
|
if (!station->autoconnect_can_start)
|
|
|
|
return;
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
if (!station_is_autoconnecting(station))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!l_queue_isempty(station->anqp_pending))
|
|
|
|
return;
|
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
if (!l_queue_isempty(station->owe_hidden_scan_ids))
|
|
|
|
return;
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
if (L_WARN_ON(station->autoconnect_list))
|
|
|
|
l_queue_destroy(station->autoconnect_list, NULL);
|
|
|
|
|
2022-02-10 21:54:00 +01:00
|
|
|
l_debug("");
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
station->autoconnect_list = l_queue_new();
|
|
|
|
station_network_foreach(station, network_add_foreach, station);
|
|
|
|
station_autoconnect_next(station);
|
2021-09-16 21:00:01 +02:00
|
|
|
station->autoconnect_can_start = false;
|
2021-09-16 21:49:25 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
static void bss_free(void *data)
|
|
|
|
{
|
|
|
|
struct scan_bss *bss = data;
|
|
|
|
|
|
|
|
scan_bss_free(bss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void network_free(void *data)
|
|
|
|
{
|
|
|
|
struct network *network = data;
|
|
|
|
|
|
|
|
network_remove(network, -ESHUTDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool process_network(const void *key, void *data, void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = data;
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
if (!network_bss_list_isempty(network)) {
|
2018-09-04 21:42:35 +02:00
|
|
|
bool connected = network == station->connected_network;
|
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
/* Build the network list ordered by rank */
|
2018-09-04 21:42:35 +02:00
|
|
|
network_rank_update(network, connected);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
|
|
|
l_queue_insert(station->networks_sorted, network,
|
|
|
|
network_rank_compare, NULL);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Drop networks that have no more BSSs in range */
|
|
|
|
l_debug("No remaining BSSs for SSID: %s -- Removing network",
|
|
|
|
network_get_ssid(network));
|
|
|
|
network_remove(network, -ERANGE);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *iwd_network_get_path(struct station *station,
|
|
|
|
const char *ssid,
|
|
|
|
enum security security)
|
|
|
|
{
|
|
|
|
static char path[256];
|
|
|
|
unsigned int pos, i;
|
|
|
|
|
|
|
|
pos = snprintf(path, sizeof(path), "%s/",
|
|
|
|
netdev_get_path(station->netdev));
|
|
|
|
|
|
|
|
for (i = 0; ssid[i] && pos < sizeof(path); i++)
|
2023-03-17 21:19:09 +01:00
|
|
|
pos += snprintf(path + pos, sizeof(path) - pos, "%02hhx",
|
|
|
|
ssid[i]);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
|
|
|
snprintf(path + pos, sizeof(path) - pos, "_%s",
|
|
|
|
security_to_str(security));
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct network *station_network_find(struct station *station, const char *ssid,
|
|
|
|
enum security security)
|
|
|
|
{
|
|
|
|
const char *path = iwd_network_get_path(station, ssid, security);
|
|
|
|
|
|
|
|
return l_hashmap_lookup(station->networks, path);
|
|
|
|
}
|
|
|
|
|
2018-11-09 01:25:21 +01:00
|
|
|
static int bss_signal_strength_compare(const void *a, const void *b, void *user)
|
|
|
|
{
|
|
|
|
const struct scan_bss *new_bss = a;
|
|
|
|
const struct scan_bss *bss = b;
|
|
|
|
|
2020-08-14 15:40:33 +02:00
|
|
|
return (bss->signal_strength > new_bss->signal_strength) ? 1 : -1;
|
2018-11-09 01:25:21 +01:00
|
|
|
}
|
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
/*
|
|
|
|
* Returns the network object the BSS was added to or NULL if ignored.
|
|
|
|
*/
|
2018-09-05 02:05:20 +02:00
|
|
|
static struct network *station_add_seen_bss(struct station *station,
|
2018-09-01 23:21:28 +02:00
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
struct network *network;
|
|
|
|
enum security security;
|
|
|
|
const char *path;
|
|
|
|
char ssid[33];
|
2021-06-04 16:20:47 +02:00
|
|
|
uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, "
|
2021-06-04 16:20:47 +02:00
|
|
|
"strength: %i, data_rate: %u.%u",
|
2018-09-01 23:21:28 +02:00
|
|
|
util_address_to_string(bss->addr),
|
|
|
|
util_ssid_to_utf8(bss->ssid_len, bss->ssid),
|
2021-06-04 16:20:47 +02:00
|
|
|
bss->frequency, bss->rank, bss->signal_strength,
|
|
|
|
kbps100 / 10, kbps100 % 10);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
|
|
|
if (util_ssid_is_hidden(bss->ssid_len, bss->ssid)) {
|
2018-11-09 01:25:21 +01:00
|
|
|
l_debug("BSS has hidden SSID");
|
|
|
|
|
|
|
|
l_queue_insert(station->hidden_bss_list_sorted, bss,
|
|
|
|
bss_signal_strength_compare, NULL);
|
2018-09-01 23:21:28 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ssid, bss->ssid, bss->ssid_len);
|
|
|
|
ssid[bss->ssid_len] = '\0';
|
|
|
|
|
2018-10-03 23:37:44 +02:00
|
|
|
if (!(bss->capability & IE_BSS_CAP_ESS)) {
|
|
|
|
l_debug("Ignoring non-ESS BSS \"%s\"", ssid);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-02-24 18:04:55 +01:00
|
|
|
if (scan_bss_get_security(bss, &security) < 0)
|
2021-08-12 21:07:21 +02:00
|
|
|
return NULL;
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
/* Hidden OWE transition network */
|
2021-09-22 20:26:51 +02:00
|
|
|
if (security == SECURITY_NONE && bss->rsne && bss->owe_trans) {
|
|
|
|
struct ie_owe_transition_info *info = bss->owe_trans;
|
2021-09-18 00:58:38 +02:00
|
|
|
/*
|
|
|
|
* WiFi Alliance OWE Specification v1.1 - Section 2.2.1:
|
|
|
|
*
|
|
|
|
* "2. An OWE AP shall use two different SSIDs, one for OWE
|
|
|
|
* and one for Open"
|
|
|
|
*
|
|
|
|
* "4. The OWE BSS shall include the OWE Transition Mode element
|
|
|
|
* in all Beacon and Probe Response frames to encapsulate
|
|
|
|
* the BSSID and SSID of the Open BSS"
|
|
|
|
*
|
|
|
|
* Meaning the hidden SSID should not match the SSID in the
|
|
|
|
* hidden network's OWE IE. Might as well restrict BSSID as well
|
|
|
|
* to be safe.
|
|
|
|
*
|
|
|
|
* In addition this SSID must be a valid utf8 string otherwise
|
|
|
|
* we could not look up the network. Note that this is not true
|
|
|
|
* for the open BSS IE, it can be non-utf8.
|
|
|
|
*/
|
2021-09-22 20:26:51 +02:00
|
|
|
if (!util_ssid_is_utf8(info->ssid_len, info->ssid))
|
2021-09-18 00:58:38 +02:00
|
|
|
return NULL;
|
|
|
|
|
2021-09-22 20:26:51 +02:00
|
|
|
if (!memcmp(info->ssid, bss->ssid, bss->ssid_len))
|
2021-09-18 00:58:38 +02:00
|
|
|
return NULL;
|
|
|
|
|
2021-09-22 20:26:51 +02:00
|
|
|
if (!memcmp(info->bssid, bss->addr, 6))
|
2021-09-18 00:58:38 +02:00
|
|
|
return NULL;
|
|
|
|
|
2021-09-22 20:26:51 +02:00
|
|
|
memcpy(ssid, info->ssid, info->ssid_len);
|
|
|
|
ssid[info->ssid_len] = '\0';
|
2021-09-18 00:58:38 +02:00
|
|
|
|
|
|
|
l_debug("Found hidden OWE network, using %s for network lookup",
|
|
|
|
ssid);
|
|
|
|
}
|
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
path = iwd_network_get_path(station, ssid, security);
|
|
|
|
|
|
|
|
network = l_hashmap_lookup(station->networks, path);
|
|
|
|
if (!network) {
|
2018-09-04 22:45:37 +02:00
|
|
|
network = network_create(station, ssid, security);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
|
|
|
if (!network_register(network, path)) {
|
|
|
|
network_remove(network, -EINVAL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_hashmap_insert(station->networks,
|
|
|
|
network_get_path(network), network);
|
|
|
|
l_debug("Added new Network \"%s\" security %s",
|
|
|
|
network_get_ssid(network), security_to_str(security));
|
|
|
|
}
|
|
|
|
|
|
|
|
network_bss_add(network, bss);
|
|
|
|
|
|
|
|
return network;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bss_match(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct scan_bss *bss_a = a;
|
|
|
|
const struct scan_bss *bss_b = b;
|
|
|
|
|
2021-02-03 19:55:18 +01:00
|
|
|
if (memcmp(bss_a->addr, bss_b->addr, sizeof(bss_a->addr)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (bss_a->ssid_len != bss_b->ssid_len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !memcmp(bss_a->ssid, bss_b->ssid, bss_a->ssid_len);
|
2018-09-01 23:21:28 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
struct bss_expiration_data {
|
|
|
|
struct scan_bss *connected_bss;
|
|
|
|
uint64_t now;
|
2021-02-03 17:31:24 +01:00
|
|
|
const struct scan_freq_set *freqs;
|
2019-04-11 21:14:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SCAN_RESULT_BSS_RETENTION_TIME (30 * 1000000)
|
|
|
|
|
|
|
|
static bool bss_free_if_expired(void *data, void *user_data)
|
|
|
|
{
|
|
|
|
struct scan_bss *bss = data;
|
|
|
|
struct bss_expiration_data *expiration_data = user_data;
|
|
|
|
|
|
|
|
if (bss == expiration_data->connected_bss)
|
|
|
|
/* Do not expire the currently connected BSS. */
|
|
|
|
return false;
|
|
|
|
|
2021-02-03 17:31:24 +01:00
|
|
|
/* Keep any BSSes that are not on the frequency list */
|
|
|
|
if (!scan_freq_set_contains(expiration_data->freqs, bss->frequency))
|
|
|
|
return false;
|
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
if (l_time_before(expiration_data->now,
|
|
|
|
bss->time_stamp + SCAN_RESULT_BSS_RETENTION_TIME))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bss_free(bss);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-03 17:31:24 +01:00
|
|
|
static void station_bss_list_remove_expired_bsses(struct station *station,
|
|
|
|
const struct scan_freq_set *freqs)
|
2019-04-11 21:14:24 +02:00
|
|
|
{
|
|
|
|
struct bss_expiration_data data = {
|
|
|
|
.now = l_time_now(),
|
|
|
|
.connected_bss = station->connected_bss,
|
2021-02-03 17:31:24 +01:00
|
|
|
.freqs = freqs,
|
2019-04-11 21:14:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
l_queue_foreach_remove(station->bss_list, bss_free_if_expired, &data);
|
|
|
|
}
|
|
|
|
|
2019-08-19 20:11:59 +02:00
|
|
|
struct nai_search {
|
|
|
|
struct network *network;
|
|
|
|
const char **realms;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool match_nai_realms(const struct network_info *info, void *user_data)
|
|
|
|
{
|
|
|
|
struct nai_search *search = user_data;
|
|
|
|
|
|
|
|
if (!network_info_match_nai_realm(info, search->realms))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
network_set_info(search->network, (struct network_info *) info);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-12 21:14:11 +02:00
|
|
|
static bool match_pending(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct anqp_entry *entry = a;
|
|
|
|
|
|
|
|
return entry->pending != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_anqp(void *data)
|
|
|
|
{
|
|
|
|
struct anqp_entry *entry = data;
|
|
|
|
|
2020-07-09 02:04:34 +02:00
|
|
|
if (entry->pending)
|
|
|
|
anqp_cancel(entry->pending);
|
|
|
|
|
2020-06-12 21:14:11 +02:00
|
|
|
l_free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool anqp_entry_foreach(void *data, void *user_data)
|
|
|
|
{
|
|
|
|
struct anqp_entry *e = data;
|
|
|
|
|
2021-09-15 19:36:18 +02:00
|
|
|
WATCHLIST_NOTIFY(&event_watches, station_event_watch_func_t,
|
|
|
|
STATION_EVENT_ANQP_FINISHED, e->network);
|
2020-06-12 21:14:11 +02:00
|
|
|
|
|
|
|
remove_anqp(e);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
static void station_anqp_response_cb(enum anqp_result result,
|
|
|
|
const void *anqp, size_t anqp_len,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct anqp_entry *entry = user_data;
|
|
|
|
struct station *station = entry->station;
|
|
|
|
struct network *network = entry->network;
|
|
|
|
struct anqp_iter iter;
|
|
|
|
uint16_t id;
|
|
|
|
uint16_t len;
|
|
|
|
const void *data;
|
|
|
|
char **realms = NULL;
|
2019-08-19 20:11:59 +02:00
|
|
|
struct nai_search search;
|
2019-06-27 00:15:57 +02:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2020-07-09 02:04:34 +02:00
|
|
|
if (result != ANQP_SUCCESS) {
|
2019-06-27 00:15:57 +02:00
|
|
|
/* TODO: try next BSS */
|
|
|
|
goto request_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
anqp_iter_init(&iter, anqp, anqp_len);
|
|
|
|
|
|
|
|
while (anqp_iter_next(&iter, &id, &len, &data)) {
|
|
|
|
switch (id) {
|
|
|
|
case ANQP_NAI_REALM:
|
|
|
|
if (realms)
|
|
|
|
break;
|
|
|
|
|
|
|
|
realms = anqp_parse_nai_realms(data, len);
|
|
|
|
if (!realms)
|
|
|
|
goto request_done;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 20:11:59 +02:00
|
|
|
if (!realms)
|
|
|
|
goto request_done;
|
|
|
|
|
|
|
|
search.network = network;
|
|
|
|
search.realms = (const char **)realms;
|
|
|
|
|
|
|
|
known_networks_foreach(match_nai_realms, &search);
|
2019-06-27 00:15:57 +02:00
|
|
|
|
2019-09-11 20:45:56 +02:00
|
|
|
l_strv_free(realms);
|
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
request_done:
|
2020-06-12 21:14:11 +02:00
|
|
|
entry->pending = 0;
|
2019-06-27 00:15:57 +02:00
|
|
|
|
2020-06-12 21:14:11 +02:00
|
|
|
/* Return if there are other pending requests */
|
|
|
|
if (l_queue_find(station->anqp_pending, match_pending, NULL))
|
2019-08-28 18:14:31 +02:00
|
|
|
return;
|
|
|
|
|
2020-06-12 21:14:11 +02:00
|
|
|
/* Notify all watchers now that every ANQP request has finished */
|
|
|
|
l_queue_foreach_remove(station->anqp_pending, anqp_entry_foreach, NULL);
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
station_autoconnect_start(station);
|
2019-06-27 00:15:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_start_anqp(struct station *station, struct network *network,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
uint8_t anqp[256];
|
|
|
|
uint8_t *ptr = anqp;
|
|
|
|
struct anqp_entry *entry;
|
|
|
|
|
2019-07-24 22:09:46 +02:00
|
|
|
if (!bss->hs20_capable)
|
2019-07-13 00:23:31 +02:00
|
|
|
return false;
|
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
/* Network already has ANQP data/HESSID */
|
2019-08-19 20:11:59 +02:00
|
|
|
if (network_get_info(network))
|
2019-06-27 00:15:57 +02:00
|
|
|
return false;
|
|
|
|
|
2019-07-12 23:40:17 +02:00
|
|
|
if (anqp_disabled) {
|
|
|
|
l_debug("Not querying AP for ANQP data (disabled)");
|
2019-06-27 00:15:57 +02:00
|
|
|
return false;
|
2019-07-12 23:40:17 +02:00
|
|
|
}
|
2019-06-27 00:15:57 +02:00
|
|
|
|
|
|
|
entry = l_new(struct anqp_entry, 1);
|
|
|
|
entry->station = station;
|
|
|
|
entry->network = network;
|
|
|
|
|
|
|
|
l_put_le16(ANQP_QUERY_LIST, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
l_put_le16(2, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
l_put_le16(ANQP_NAI_REALM, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
l_put_le16(ANQP_VENDOR_SPECIFIC, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
/* vendor length */
|
|
|
|
l_put_le16(7, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
*ptr++ = 0x50;
|
|
|
|
*ptr++ = 0x6f;
|
|
|
|
*ptr++ = 0x9a;
|
|
|
|
*ptr++ = 0x11; /* HS20 ANQP Element type */
|
|
|
|
*ptr++ = ANQP_HS20_QUERY_LIST;
|
|
|
|
*ptr++ = 0; /* reserved */
|
|
|
|
*ptr++ = ANQP_HS20_OSU_PROVIDERS_NAI_LIST;
|
|
|
|
|
2019-07-12 23:00:02 +02:00
|
|
|
/*
|
|
|
|
* TODO: Additional roaming consortiums can be queried if indicated
|
|
|
|
* by the roaming consortium IE. The IE contains up to the first 3, and
|
|
|
|
* these are checked in hs20_find_settings_file.
|
|
|
|
*/
|
|
|
|
|
2020-07-09 02:04:34 +02:00
|
|
|
entry->pending = anqp_request(netdev_get_wdev_id(station->netdev),
|
|
|
|
netdev_get_address(station->netdev), bss, anqp,
|
|
|
|
ptr - anqp, station_anqp_response_cb,
|
|
|
|
entry, NULL);
|
2019-06-27 00:15:57 +02:00
|
|
|
if (!entry->pending) {
|
|
|
|
l_free(entry);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_queue_push_head(station->anqp_pending, entry);
|
|
|
|
|
2021-09-15 19:36:18 +02:00
|
|
|
WATCHLIST_NOTIFY(&event_watches, station_event_watch_func_t,
|
|
|
|
STATION_EVENT_ANQP_STARTED, network);
|
2019-06-27 00:15:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
static bool network_has_open_pair(struct network *network, struct scan_bss *owe)
|
|
|
|
{
|
|
|
|
const struct l_queue_entry *entry;
|
2021-09-22 20:26:51 +02:00
|
|
|
struct ie_owe_transition_info *owe_info = owe->owe_trans;
|
2021-09-18 00:58:38 +02:00
|
|
|
|
|
|
|
for (entry = network_bss_list_get_entries(network); entry;
|
|
|
|
entry = entry->next) {
|
|
|
|
struct scan_bss *open = entry->data;
|
2021-09-22 20:26:51 +02:00
|
|
|
struct ie_owe_transition_info *open_info = open->owe_trans;
|
2021-09-18 00:58:38 +02:00
|
|
|
|
2021-11-07 01:41:37 +01:00
|
|
|
/* AP does not advertise owe transition */
|
|
|
|
if (!open_info)
|
|
|
|
continue;
|
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
/*
|
|
|
|
* Check if this is an Open/Hidden pair:
|
|
|
|
*
|
|
|
|
* Open SSID equals the SSID in OWE IE
|
|
|
|
* Open BSSID equals the BSSID in OWE IE
|
|
|
|
*
|
|
|
|
* OWE SSID equals the SSID in Open IE
|
|
|
|
* OWE BSSID equals the BSSID in Open IE
|
|
|
|
*/
|
2021-09-22 20:26:51 +02:00
|
|
|
if (open->ssid_len == owe_info->ssid_len &&
|
|
|
|
open_info->ssid_len == owe->ssid_len &&
|
|
|
|
!memcmp(open->ssid, owe_info->ssid,
|
2021-09-18 00:58:38 +02:00
|
|
|
open->ssid_len) &&
|
2021-09-22 20:26:51 +02:00
|
|
|
!memcmp(open_info->ssid, owe->ssid,
|
2021-09-18 00:58:38 +02:00
|
|
|
owe->ssid_len) &&
|
2021-09-22 20:26:51 +02:00
|
|
|
!memcmp(open->addr, owe_info->bssid, 6) &&
|
|
|
|
!memcmp(open_info->bssid, owe->addr, 6))
|
2021-09-18 00:58:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_owe_transition_results(int err, struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
struct network *network = userdata;
|
|
|
|
struct station *station = network_get_station(network);
|
|
|
|
struct scan_bss *bss;
|
|
|
|
|
|
|
|
station_property_set_scanning(station, false);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while ((bss = l_queue_pop_head(bss_list))) {
|
|
|
|
/*
|
|
|
|
* Don't handle the open BSS, hidden BSS, BSS with no OWE
|
|
|
|
* Transition IE, or an IE with a non-utf8 SSID
|
|
|
|
*/
|
2021-09-22 20:26:51 +02:00
|
|
|
if (!bss->rsne || !bss->owe_trans ||
|
2021-09-18 00:58:38 +02:00
|
|
|
util_ssid_is_hidden(bss->ssid_len, bss->ssid) ||
|
2021-09-22 20:26:51 +02:00
|
|
|
!util_ssid_is_utf8(bss->owe_trans->ssid_len,
|
|
|
|
bss->owe_trans->ssid))
|
2021-09-18 00:58:38 +02:00
|
|
|
goto free;
|
|
|
|
|
|
|
|
/* Check if we have an open BSS that matches */
|
|
|
|
if (!network_has_open_pair(network, bss))
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
l_debug("Adding OWE transition network "MAC" to %s",
|
|
|
|
MAC_STR(bss->addr), network_get_ssid(network));
|
|
|
|
|
|
|
|
l_queue_push_tail(station->bss_list, bss);
|
|
|
|
network_bss_add(network, bss);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
free:
|
|
|
|
scan_bss_free(bss);
|
|
|
|
}
|
|
|
|
|
|
|
|
l_queue_destroy(bss_list, NULL);
|
|
|
|
|
|
|
|
done:
|
|
|
|
l_queue_pop_head(station->owe_hidden_scan_ids);
|
|
|
|
|
|
|
|
WATCHLIST_NOTIFY(&event_watches, station_event_watch_func_t,
|
|
|
|
STATION_EVENT_OWE_HIDDEN_FINISHED, network);
|
|
|
|
|
|
|
|
station_autoconnect_start(station);
|
|
|
|
|
|
|
|
return err == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_owe_transition_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = user_data;
|
|
|
|
struct station *station = network_get_station(network);
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
l_debug("OWE transition scan trigger failed: %i", err);
|
|
|
|
|
|
|
|
l_queue_pop_head(station->owe_hidden_scan_ids);
|
|
|
|
|
|
|
|
WATCHLIST_NOTIFY(&event_watches, station_event_watch_func_t,
|
|
|
|
STATION_EVENT_OWE_HIDDEN_FINISHED, network);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("OWE transition scan triggered");
|
|
|
|
|
|
|
|
station_property_set_scanning(station, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foreach_add_owe_scan(struct network *network, void *data)
|
|
|
|
{
|
|
|
|
struct station *station = data;
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
struct l_queue *list = NULL;
|
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
if (network_get_security(network) != SECURITY_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (entry = network_bss_list_get_entries(network); entry;
|
|
|
|
entry = entry->next) {
|
|
|
|
struct scan_bss *open = entry->data;
|
|
|
|
|
2021-09-22 20:26:51 +02:00
|
|
|
if (!open->owe_trans)
|
2021-09-18 00:58:38 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* only want the open networks with WFA OWE IE */
|
|
|
|
if (open->rsne)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* BSS already in network object */
|
2021-09-22 20:26:51 +02:00
|
|
|
if (network_bss_find_by_addr(network, open->owe_trans->bssid))
|
2021-09-18 00:58:38 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
list = l_queue_new();
|
|
|
|
|
|
|
|
l_queue_push_tail(list, open);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
id = scan_owe_hidden(netdev_get_wdev_id(station->netdev), list,
|
|
|
|
station_owe_transition_triggered,
|
|
|
|
station_owe_transition_results, network, NULL);
|
|
|
|
|
|
|
|
l_queue_destroy(list, NULL);
|
|
|
|
|
|
|
|
if (!id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!station->owe_hidden_scan_ids)
|
|
|
|
station->owe_hidden_scan_ids = l_queue_new();
|
|
|
|
|
|
|
|
l_queue_push_tail(station->owe_hidden_scan_ids, L_UINT_TO_PTR(id));
|
|
|
|
|
|
|
|
WATCHLIST_NOTIFY(&event_watches, station_event_watch_func_t,
|
|
|
|
STATION_EVENT_OWE_HIDDEN_STARTED, network);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_process_owe_transition_networks(struct station *station)
|
|
|
|
{
|
|
|
|
station_network_foreach(station, foreach_add_owe_scan, station);
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:47:01 +01:00
|
|
|
static bool bss_free_if_ssid_not_utf8(void *data, void *user_data)
|
|
|
|
{
|
|
|
|
struct scan_bss *bss = data;
|
|
|
|
|
|
|
|
if (util_ssid_is_hidden(bss->ssid_len, bss->ssid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (util_ssid_is_utf8(bss->ssid_len, bss->ssid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_debug("Dropping scan_bss '%s', with non-utf8 SSID",
|
|
|
|
util_address_to_string(bss->addr));
|
|
|
|
bss_free(bss);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
/*
|
2019-04-11 21:14:24 +02:00
|
|
|
* Used when scan results were obtained; either from scan running
|
|
|
|
* inside station module or scans running in other state machines, e.g. wsc
|
2018-09-01 23:21:28 +02:00
|
|
|
*/
|
2019-04-11 21:14:24 +02:00
|
|
|
void station_set_scan_results(struct station *station,
|
2021-02-03 17:31:24 +01:00
|
|
|
struct l_queue *new_bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
2021-09-16 20:47:01 +02:00
|
|
|
bool trigger_autoconnect)
|
2018-09-01 23:21:28 +02:00
|
|
|
{
|
|
|
|
const struct l_queue_entry *bss_entry;
|
2019-04-11 21:14:24 +02:00
|
|
|
struct network *network;
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2021-02-03 18:47:01 +01:00
|
|
|
l_queue_foreach_remove(new_bss_list, bss_free_if_ssid_not_utf8, NULL);
|
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
while ((network = l_queue_pop_head(station->networks_sorted)))
|
|
|
|
network_bss_list_clear(network);
|
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
l_queue_clear(station->hidden_bss_list_sorted, NULL);
|
|
|
|
|
2021-05-07 22:26:17 +02:00
|
|
|
l_queue_destroy(station->autoconnect_list, NULL);
|
2021-09-16 21:49:25 +02:00
|
|
|
station->autoconnect_list = NULL;
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2021-02-03 17:31:24 +01:00
|
|
|
station_bss_list_remove_expired_bsses(station, freqs);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
for (bss_entry = l_queue_get_entries(station->bss_list); bss_entry;
|
|
|
|
bss_entry = bss_entry->next) {
|
|
|
|
struct scan_bss *old_bss = bss_entry->data;
|
|
|
|
struct scan_bss *new_bss;
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
new_bss = l_queue_find(new_bss_list, bss_match, old_bss);
|
|
|
|
if (new_bss) {
|
|
|
|
if (old_bss == station->connected_bss)
|
|
|
|
station->connected_bss = new_bss;
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
bss_free(old_bss);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_bss == station->connected_bss) {
|
|
|
|
l_warn("Connected BSS not in scan results");
|
2018-09-01 23:21:28 +02:00
|
|
|
station->connected_bss->rank = 0;
|
2019-04-11 21:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
l_queue_push_tail(new_bss_list, old_bss);
|
2018-09-01 23:21:28 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 21:14:24 +02:00
|
|
|
l_queue_destroy(station->bss_list, NULL);
|
|
|
|
|
|
|
|
for (bss_entry = l_queue_get_entries(new_bss_list); bss_entry;
|
|
|
|
bss_entry = bss_entry->next) {
|
|
|
|
struct scan_bss *bss = bss_entry->data;
|
|
|
|
struct network *network = station_add_seen_bss(station, bss);
|
2018-09-01 23:21:28 +02:00
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
if (!network)
|
|
|
|
continue;
|
|
|
|
|
2021-09-16 22:49:25 +02:00
|
|
|
/* Cached BSS entry, this should have been processed already */
|
|
|
|
if (!scan_freq_set_contains(freqs, bss->frequency))
|
|
|
|
continue;
|
|
|
|
|
2021-09-16 21:49:25 +02:00
|
|
|
station_start_anqp(station, network, bss);
|
2019-04-11 21:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
station->bss_list = new_bss_list;
|
|
|
|
|
|
|
|
l_hashmap_foreach_remove(station->networks, process_network, station);
|
2019-06-27 00:15:57 +02:00
|
|
|
|
2021-09-16 21:00:01 +02:00
|
|
|
station->autoconnect_can_start = trigger_autoconnect;
|
|
|
|
station_autoconnect_start(station);
|
2018-09-01 23:21:28 +02:00
|
|
|
}
|
|
|
|
|
2019-01-25 20:23:12 +01:00
|
|
|
static void station_reconnect(struct station *station);
|
|
|
|
|
2018-09-01 00:44:10 +02:00
|
|
|
static void station_handshake_event(struct handshake_state *hs,
|
|
|
|
enum handshake_event event,
|
2019-10-28 15:04:57 +01:00
|
|
|
void *user_data, ...)
|
2018-09-01 00:44:10 +02:00
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct network *network = station->connected_network;
|
2019-10-28 15:04:57 +01:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, user_data);
|
2018-09-01 00:44:10 +02:00
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case HANDSHAKE_EVENT_STARTED:
|
|
|
|
l_debug("Handshaking");
|
|
|
|
break;
|
|
|
|
case HANDSHAKE_EVENT_SETTING_KEYS:
|
|
|
|
l_debug("Setting keys");
|
|
|
|
|
2021-07-06 18:46:33 +02:00
|
|
|
/* If we got here, then our settings work. Update if needed */
|
|
|
|
network_sync_settings(network);
|
2018-09-01 00:44:10 +02:00
|
|
|
break;
|
|
|
|
case HANDSHAKE_EVENT_FAILED:
|
2019-10-28 15:04:57 +01:00
|
|
|
netdev_handshake_failed(hs, va_arg(args, int));
|
2018-09-01 00:44:10 +02:00
|
|
|
break;
|
2019-01-25 20:23:12 +01:00
|
|
|
case HANDSHAKE_EVENT_REKEY_FAILED:
|
2021-03-24 19:10:32 +01:00
|
|
|
l_warn("Unable to securely rekey on this hw/kernel...");
|
2019-01-25 20:23:12 +01:00
|
|
|
station_reconnect(station);
|
|
|
|
break;
|
2021-07-16 00:06:34 +02:00
|
|
|
case HANDSHAKE_EVENT_TRANSITION_DISABLE:
|
|
|
|
{
|
|
|
|
const uint8_t *td = va_arg(args, const uint8_t *);
|
|
|
|
size_t len = va_arg(args, size_t);
|
|
|
|
|
|
|
|
network_set_transition_disable(network, td, len);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-01 00:44:10 +02:00
|
|
|
case HANDSHAKE_EVENT_COMPLETE:
|
2019-01-25 20:23:12 +01:00
|
|
|
case HANDSHAKE_EVENT_SETTING_KEYS_FAILED:
|
2019-10-28 15:05:00 +01:00
|
|
|
case HANDSHAKE_EVENT_EAP_NOTIFY:
|
2021-08-23 16:14:22 +02:00
|
|
|
case HANDSHAKE_EVENT_P2P_IP_REQUEST:
|
2023-01-11 21:15:38 +01:00
|
|
|
case HANDSHAKE_EVENT_REKEY_COMPLETE:
|
2018-09-01 00:44:10 +02:00
|
|
|
/*
|
2020-01-21 07:21:38 +01:00
|
|
|
* currently we don't care about any other events. The
|
2018-09-01 00:44:10 +02:00
|
|
|
* netdev_connect_cb will notify us when the connection is
|
|
|
|
* complete.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2019-10-28 15:04:57 +01:00
|
|
|
|
|
|
|
va_end(args);
|
2018-09-01 00:44:10 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 20:30:36 +02:00
|
|
|
static int station_build_handshake_rsn(struct handshake_state *hs,
|
|
|
|
struct wiphy *wiphy,
|
|
|
|
struct network *network,
|
|
|
|
struct scan_bss *bss)
|
2018-09-01 00:44:10 +02:00
|
|
|
{
|
2021-09-28 17:46:55 +02:00
|
|
|
const struct l_settings *settings = iwd_get_config();
|
2018-09-01 00:44:10 +02:00
|
|
|
enum security security = network_get_security(network);
|
|
|
|
bool add_mde = false;
|
2021-08-03 23:40:43 +02:00
|
|
|
struct erp_cache_entry *erp_cache = NULL;
|
2018-11-16 23:22:55 +01:00
|
|
|
struct ie_rsn_info bss_info;
|
|
|
|
uint8_t rsne_buf[256];
|
|
|
|
struct ie_rsn_info info;
|
2019-06-11 00:46:59 +02:00
|
|
|
uint8_t *ap_ie;
|
2021-09-28 17:46:55 +02:00
|
|
|
bool disable_ocv;
|
2022-02-25 23:03:38 +01:00
|
|
|
enum band_freq band;
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
memset(&info, 0, sizeof(info));
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2022-02-25 23:03:38 +01:00
|
|
|
if (!band_freq_to_channel(bss->frequency, &band))
|
|
|
|
goto not_supported;
|
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
memset(&bss_info, 0, sizeof(bss_info));
|
|
|
|
scan_bss_get_rsn_info(bss, &bss_info);
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2019-04-22 19:11:46 +02:00
|
|
|
if (bss_info.akm_suites & (IE_RSN_AKM_SUITE_FILS_SHA256 |
|
|
|
|
IE_RSN_AKM_SUITE_FILS_SHA384))
|
|
|
|
hs->support_fils = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this network 8021x we might have a set of cached EAP keys. If so
|
|
|
|
* wiphy may select FILS if supported by the AP.
|
|
|
|
*/
|
|
|
|
if (security == SECURITY_8021X && hs->support_fils)
|
2021-08-03 23:40:43 +02:00
|
|
|
erp_cache = network_get_erp_cache(network);
|
2019-04-22 19:11:46 +02:00
|
|
|
|
2021-07-27 20:59:52 +02:00
|
|
|
info.akm_suites = wiphy_select_akm(wiphy, bss, security,
|
2021-08-03 23:40:43 +02:00
|
|
|
&bss_info, erp_cache != NULL);
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
/*
|
|
|
|
* Special case for OWE. With OWE we still need to build up the
|
|
|
|
* handshake object with AKM/cipher info since OWE does the full 4-way
|
|
|
|
* handshake. But if this is a non-OWE open network, we can skip this.
|
|
|
|
*/
|
|
|
|
if (security == SECURITY_NONE &&
|
|
|
|
!(info.akm_suites & IE_RSN_AKM_SUITE_OWE))
|
|
|
|
goto open_network;
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
if (!info.akm_suites)
|
|
|
|
goto not_supported;
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
info.pairwise_ciphers = wiphy_select_cipher(wiphy,
|
|
|
|
bss_info.pairwise_ciphers);
|
|
|
|
info.group_cipher = wiphy_select_cipher(wiphy,
|
|
|
|
bss_info.group_cipher);
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
if (!info.pairwise_ciphers || !info.group_cipher)
|
|
|
|
goto not_supported;
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2019-06-11 00:46:59 +02:00
|
|
|
/* Management frame protection is explicitly off for OSEN */
|
|
|
|
if (info.akm_suites & IE_RSN_AKM_SUITE_OSEN) {
|
|
|
|
info.group_management_cipher =
|
|
|
|
IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC;
|
|
|
|
goto build_ie;
|
|
|
|
}
|
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
switch (mfp_setting) {
|
|
|
|
case 0:
|
2022-02-25 23:03:38 +01:00
|
|
|
if (band != BAND_FREQ_6_GHZ)
|
|
|
|
break;
|
|
|
|
|
|
|
|
l_error("MFP turned off by [General].ManagementFrameProtection,"
|
|
|
|
" 6GHz frequencies are disabled");
|
|
|
|
goto not_supported;
|
2018-11-16 23:22:55 +01:00
|
|
|
case 1:
|
|
|
|
info.group_management_cipher =
|
|
|
|
wiphy_select_cipher(wiphy,
|
|
|
|
bss_info.group_management_cipher);
|
|
|
|
info.mfpc = info.group_management_cipher != 0;
|
2022-02-25 23:03:38 +01:00
|
|
|
|
|
|
|
if (band != BAND_FREQ_6_GHZ)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!info.mfpc)
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 802.11ax Section 12.12.2
|
|
|
|
* The STA shall use management frame protection
|
|
|
|
* (MFPR=1) when using RSN.
|
|
|
|
*/
|
|
|
|
info.mfpr = true;
|
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
info.group_management_cipher =
|
|
|
|
wiphy_select_cipher(wiphy,
|
|
|
|
bss_info.group_management_cipher);
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
/*
|
|
|
|
* MFP required on our side, but AP doesn't support MFP
|
|
|
|
* or cipher mismatch
|
|
|
|
*/
|
|
|
|
if (info.group_management_cipher == 0)
|
2018-09-01 00:44:10 +02:00
|
|
|
goto not_supported;
|
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
info.mfpc = true;
|
|
|
|
info.mfpr = true;
|
|
|
|
break;
|
|
|
|
}
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
if (bss_info.mfpr && !info.mfpc)
|
|
|
|
goto not_supported;
|
|
|
|
|
2019-06-11 00:46:59 +02:00
|
|
|
build_ie:
|
2021-09-28 17:46:55 +02:00
|
|
|
if (!l_settings_get_bool(settings, "General", "DisableOCV",
|
|
|
|
&disable_ocv))
|
|
|
|
disable_ocv = false;
|
|
|
|
|
2021-10-19 23:52:47 +02:00
|
|
|
/*
|
|
|
|
* Obviously do not enable OCV if explicitly disabled or no AP support.
|
|
|
|
*
|
|
|
|
* Not obviously hostapd rejects OCV support if MFPC is not enabled.
|
|
|
|
* This is not really specified by the spec, but we have to work around
|
|
|
|
* this limitation.
|
|
|
|
*
|
|
|
|
* Another limitation is full mac cards. With limited testing it was
|
|
|
|
* seen that they do not include the OCI in the 4-way handshake yet
|
|
|
|
* still advertise the capability. Because of this OCV is disabled if
|
|
|
|
* any offload features are detected (since IWD prefers to use offload).
|
2022-09-16 00:07:29 +02:00
|
|
|
*
|
|
|
|
* TODO: For now OCV is disabled if the network is FT capable. This is
|
|
|
|
* being done until support in the kernel is added to
|
|
|
|
* automatically include the OCI element for the association
|
|
|
|
* request.
|
2021-10-19 23:52:47 +02:00
|
|
|
*/
|
|
|
|
info.ocvc = !disable_ocv && bss_info.ocvc && info.mfpc &&
|
2022-09-16 00:07:29 +02:00
|
|
|
!wiphy_can_offload(wiphy) &&
|
|
|
|
!IE_AKM_IS_FT(info.akm_suites);
|
2021-09-28 17:46:55 +02:00
|
|
|
|
2021-10-12 17:34:17 +02:00
|
|
|
/*
|
|
|
|
* IEEE 802.11-2020 9.4.2.24.4 states extended key IDs can only be used
|
|
|
|
* with CCMP/GCMP cipher suites. We also only enable support if the AP
|
|
|
|
* also indicates support.
|
|
|
|
*/
|
|
|
|
if (wiphy_supports_ext_key_id(wiphy) && bss_info.extended_key_id &&
|
2022-10-21 18:10:58 +02:00
|
|
|
IE_CIPHER_IS_GCMP_CCMP(info.pairwise_ciphers))
|
2021-10-08 20:07:24 +02:00
|
|
|
info.extended_key_id = true;
|
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
/* RSN takes priority */
|
|
|
|
if (bss->rsne) {
|
2019-06-11 00:46:59 +02:00
|
|
|
ap_ie = bss->rsne;
|
2018-11-16 23:22:55 +01:00
|
|
|
ie_build_rsne(&info, rsne_buf);
|
2019-06-11 00:46:59 +02:00
|
|
|
} else if (bss->wpa) {
|
|
|
|
ap_ie = bss->wpa;
|
2018-11-16 23:22:55 +01:00
|
|
|
ie_build_wpa(&info, rsne_buf);
|
2019-06-11 00:46:59 +02:00
|
|
|
} else if (bss->osen) {
|
|
|
|
ap_ie = bss->osen;
|
|
|
|
ie_build_osen(&info, rsne_buf);
|
|
|
|
} else
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
if (!handshake_state_set_authenticator_ie(hs, ap_ie))
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
if (!handshake_state_set_supplicant_ie(hs, rsne_buf))
|
|
|
|
goto not_supported;
|
2018-09-01 00:44:10 +02:00
|
|
|
|
2021-05-13 01:01:48 +02:00
|
|
|
if (IE_AKM_IS_FT(info.akm_suites))
|
2018-11-16 23:22:55 +01:00
|
|
|
add_mde = true;
|
|
|
|
|
2021-08-03 23:40:43 +02:00
|
|
|
/*
|
|
|
|
* If FILS was chosen, the ERP cache has been verified to exist. Take
|
|
|
|
* a reference now so it remains valid (in case of expiration) until
|
|
|
|
* FILS starts.
|
|
|
|
*/
|
2022-02-26 00:32:47 +01:00
|
|
|
if (IE_AKM_IS_FILS(hs->akm_suite))
|
2021-08-03 23:40:43 +02:00
|
|
|
hs->erp_cache = erp_cache;
|
|
|
|
else if (erp_cache)
|
|
|
|
erp_cache_put(erp_cache);
|
|
|
|
|
2018-11-16 23:22:55 +01:00
|
|
|
open_network:
|
2018-09-01 00:44:10 +02:00
|
|
|
if (security == SECURITY_NONE)
|
|
|
|
/* Perform FT association if available */
|
|
|
|
add_mde = bss->mde_present;
|
|
|
|
|
|
|
|
if (add_mde) {
|
|
|
|
uint8_t mde[5];
|
|
|
|
|
|
|
|
/* The MDE advertised by the BSS must be passed verbatim */
|
|
|
|
mde[0] = IE_TYPE_MOBILITY_DOMAIN;
|
|
|
|
mde[1] = 3;
|
|
|
|
memcpy(mde + 2, bss->mde, 3);
|
|
|
|
|
|
|
|
handshake_state_set_mde(hs, mde);
|
|
|
|
}
|
|
|
|
|
2018-09-19 20:30:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
not_supported:
|
2021-08-03 23:40:43 +02:00
|
|
|
if (erp_cache)
|
|
|
|
erp_cache_put(erp_cache);
|
|
|
|
|
2018-09-19 20:30:36 +02:00
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct handshake_state *station_handshake_setup(struct station *station,
|
|
|
|
struct network *network,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
struct wiphy *wiphy = station->wiphy;
|
2021-08-04 22:53:43 +02:00
|
|
|
const struct network_info *info = network_get_info(network);
|
2018-09-19 20:30:36 +02:00
|
|
|
struct handshake_state *hs;
|
2021-08-04 22:53:43 +02:00
|
|
|
const struct iovec *vendor_ies;
|
|
|
|
size_t iov_elems = 0;
|
2021-08-27 05:02:05 +02:00
|
|
|
struct ie_fils_ip_addr_request_info fils_ip_req;
|
2018-09-19 20:30:36 +02:00
|
|
|
|
|
|
|
hs = netdev_handshake_state_new(station->netdev);
|
|
|
|
|
|
|
|
handshake_state_set_event_func(hs, station_handshake_event, station);
|
|
|
|
|
|
|
|
if (station_build_handshake_rsn(hs, wiphy, network, bss) < 0)
|
|
|
|
goto not_supported;
|
|
|
|
|
2021-07-09 00:01:10 +02:00
|
|
|
handshake_state_set_authenticator_rsnxe(hs, bss->rsnxe);
|
|
|
|
|
2021-09-15 19:36:16 +02:00
|
|
|
if (network_handshake_setup(network, bss, hs) < 0)
|
2021-07-08 23:47:50 +02:00
|
|
|
goto not_supported;
|
2018-09-19 20:30:36 +02:00
|
|
|
|
2021-08-04 22:53:43 +02:00
|
|
|
vendor_ies = network_info_get_extra_ies(info, bss, &iov_elems);
|
|
|
|
handshake_state_set_vendor_ies(hs, vendor_ies, iov_elems);
|
|
|
|
|
2021-08-27 05:02:05 +02:00
|
|
|
/*
|
|
|
|
* It can't hurt to try the FILS IP Address Assigment independent of
|
|
|
|
* which auth-proto is actually used.
|
|
|
|
*/
|
|
|
|
if (station->netconfig && netconfig_get_fils_ip_req(station->netconfig,
|
|
|
|
&fils_ip_req)) {
|
|
|
|
hs->fils_ip_req_ie = l_malloc(32);
|
|
|
|
ie_build_fils_ip_addr_request(&fils_ip_req, hs->fils_ip_req_ie);
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:44:10 +02:00
|
|
|
return hs;
|
|
|
|
|
|
|
|
not_supported:
|
|
|
|
handshake_state_free(hs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-02-03 17:02:40 +01:00
|
|
|
static bool new_scan_results(int err, struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
2018-09-05 00:32:18 +02:00
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
|
2019-03-22 22:17:42 +01:00
|
|
|
station_property_set_scanning(station, false);
|
2018-09-05 00:32:18 +02:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
return false;
|
|
|
|
|
2022-01-19 20:03:45 +01:00
|
|
|
station_set_scan_results(station, bss_list, freqs, false);
|
2018-09-05 00:32:18 +02:00
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
station_process_owe_transition_networks(station);
|
|
|
|
|
2022-01-19 20:03:45 +01:00
|
|
|
station->autoconnect_can_start = true;
|
|
|
|
station_autoconnect_start(station);
|
|
|
|
|
2018-09-05 00:32:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void periodic_scan_trigger(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
2019-03-22 22:17:42 +01:00
|
|
|
station_property_set_scanning(station, true);
|
2018-09-05 00:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void periodic_scan_stop(struct station *station)
|
|
|
|
{
|
2019-07-08 16:02:59 +02:00
|
|
|
uint64_t id = netdev_get_wdev_id(station->netdev);
|
2018-09-05 00:32:18 +02:00
|
|
|
|
2020-10-14 14:35:19 +02:00
|
|
|
if (scan_periodic_stop(id))
|
|
|
|
station_property_set_scanning(station, false);
|
2018-09-05 00:32:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-22 22:17:40 +01:00
|
|
|
static bool station_needs_hidden_network_scan(struct station *station)
|
|
|
|
{
|
2021-02-03 16:14:41 +01:00
|
|
|
if (!known_networks_has_hidden())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (station_is_autoconnecting(station))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return !l_queue_isempty(station->hidden_bss_list_sorted);
|
2019-03-22 22:17:40 +01:00
|
|
|
}
|
|
|
|
|
2023-09-28 14:41:27 +02:00
|
|
|
static struct scan_freq_set *station_get_allowed_freqs(struct station *station)
|
|
|
|
{
|
|
|
|
const struct scan_freq_set *supported =
|
|
|
|
wiphy_get_supported_freqs(station->wiphy);
|
|
|
|
struct scan_freq_set *allowed = scan_freq_set_clone(supported,
|
|
|
|
allowed_bands);
|
|
|
|
|
|
|
|
if (scan_freq_set_isempty(allowed)) {
|
|
|
|
scan_freq_set_free(allowed);
|
|
|
|
allowed = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return allowed;
|
|
|
|
}
|
|
|
|
|
2019-03-22 22:17:40 +01:00
|
|
|
static uint32_t station_scan_trigger(struct station *station,
|
|
|
|
struct scan_freq_set *freqs,
|
|
|
|
scan_trigger_func_t triggered,
|
|
|
|
scan_notify_func_t notify,
|
|
|
|
scan_destroy_func_t destroy)
|
|
|
|
{
|
2019-07-08 16:02:59 +02:00
|
|
|
uint64_t id = netdev_get_wdev_id(station->netdev);
|
2021-02-03 16:16:56 +01:00
|
|
|
struct scan_parameters params;
|
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
params.flush = true;
|
|
|
|
params.freqs = freqs;
|
2019-03-22 22:17:40 +01:00
|
|
|
|
|
|
|
if (wiphy_can_randomize_mac_addr(station->wiphy) ||
|
2021-02-03 16:14:41 +01:00
|
|
|
station->connected_bss ||
|
|
|
|
station_needs_hidden_network_scan(station)) {
|
2019-03-22 22:17:40 +01:00
|
|
|
/* If we're connected, HW cannot randomize our MAC */
|
|
|
|
if (!station->connected_bss)
|
|
|
|
params.randomize_mac_addr_hint = true;
|
|
|
|
|
2019-07-08 16:02:59 +02:00
|
|
|
return scan_active_full(id, ¶ms, triggered, notify,
|
|
|
|
station, destroy);
|
2019-03-22 22:17:40 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 16:16:56 +01:00
|
|
|
return scan_passive_full(id, ¶ms, triggered, notify,
|
|
|
|
station, destroy);
|
2019-03-22 22:17:40 +01:00
|
|
|
}
|
|
|
|
|
2019-04-16 23:51:42 +02:00
|
|
|
static bool station_quick_scan_results(int err, struct l_queue *bss_list,
|
2021-02-03 17:02:40 +01:00
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
2019-04-16 23:51:42 +02:00
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
|
|
|
|
station_property_set_scanning(station, false);
|
|
|
|
|
2020-06-09 17:00:02 +02:00
|
|
|
if (err)
|
|
|
|
goto done;
|
2019-04-16 23:51:42 +02:00
|
|
|
|
2022-01-19 20:03:45 +01:00
|
|
|
station_set_scan_results(station, bss_list, freqs, false);
|
2019-04-16 23:51:42 +02:00
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
station_process_owe_transition_networks(station);
|
|
|
|
|
2022-01-19 20:03:45 +01:00
|
|
|
station->autoconnect_can_start = true;
|
|
|
|
station_autoconnect_start(station);
|
|
|
|
|
2020-06-09 17:00:02 +02:00
|
|
|
done:
|
2019-04-16 23:51:42 +02:00
|
|
|
if (station->state == STATION_STATE_AUTOCONNECT_QUICK)
|
|
|
|
/*
|
|
|
|
* If we're still in AUTOCONNECT_QUICK state, then autoconnect
|
|
|
|
* failed to find any candidates. Transition to AUTOCONNECT_FULL
|
|
|
|
*/
|
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_FULL);
|
|
|
|
|
2020-06-09 17:00:02 +02:00
|
|
|
return err == 0;
|
2019-04-16 23:51:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void station_quick_scan_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
l_debug("Quick scan trigger failed: %i", err);
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_FULL);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("Quick scan triggered for %s",
|
|
|
|
netdev_get_name(station->netdev));
|
|
|
|
|
|
|
|
station_property_set_scanning(station, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_quick_scan_destroy(void *userdata)
|
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
|
|
|
|
station->quick_scan_id = 0;
|
|
|
|
}
|
|
|
|
|
2021-02-03 16:14:41 +01:00
|
|
|
static int station_quick_scan_trigger(struct station *station)
|
2019-04-16 23:51:42 +02:00
|
|
|
{
|
2022-08-05 16:29:26 +02:00
|
|
|
_auto_(scan_freq_set_free) struct scan_freq_set *known_freq_set = NULL;
|
2023-09-28 14:41:27 +02:00
|
|
|
_auto_(scan_freq_set_free) struct scan_freq_set *allowed = NULL;
|
2022-08-04 20:51:09 +02:00
|
|
|
bool known_6ghz;
|
|
|
|
|
|
|
|
if (wiphy_regdom_is_updating(station->wiphy)) {
|
|
|
|
l_debug("regdom is updating, delaying quick scan");
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2019-04-16 23:51:42 +02:00
|
|
|
|
|
|
|
known_freq_set = known_networks_get_recent_frequencies(5);
|
|
|
|
if (!known_freq_set)
|
2021-02-03 16:14:41 +01:00
|
|
|
return -ENODATA;
|
2019-04-16 23:51:42 +02:00
|
|
|
|
2022-08-04 20:51:09 +02:00
|
|
|
known_6ghz = scan_freq_set_get_bands(known_freq_set) & BAND_FREQ_6_GHZ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This means IWD has previously connected to a 6GHz AP before, but now
|
|
|
|
* the regulatory domain disallows 6GHz likely caused by a reboot, the
|
|
|
|
* firmware going down, or a regulatory update. The only way to
|
|
|
|
* re-enable 6GHz is to get enough beacons via scanning for the firmware
|
|
|
|
* to set the regulatory domain. A quick scan is very unlikely to do
|
|
|
|
* this since its so limited, so return an error which will fall back to
|
|
|
|
* full autoconnect.
|
|
|
|
*/
|
2023-09-29 18:19:57 +02:00
|
|
|
if (wiphy_band_is_disabled(station->wiphy, BAND_FREQ_6_GHZ) == 1 &&
|
2022-12-16 22:27:39 +01:00
|
|
|
wiphy_country_is_unknown(station->wiphy) &&
|
|
|
|
known_6ghz)
|
2022-08-04 20:51:09 +02:00
|
|
|
return -ENOTSUP;
|
|
|
|
|
2023-09-28 14:41:27 +02:00
|
|
|
allowed = station_get_allowed_freqs(station);
|
|
|
|
if (L_WARN_ON(!allowed))
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
|
|
|
scan_freq_set_constrain(known_freq_set, allowed);
|
|
|
|
|
|
|
|
if (scan_freq_set_isempty(known_freq_set))
|
2021-02-03 16:14:41 +01:00
|
|
|
return -ENOTSUP;
|
2019-04-16 23:51:42 +02:00
|
|
|
|
|
|
|
station->quick_scan_id = station_scan_trigger(station,
|
|
|
|
known_freq_set,
|
|
|
|
station_quick_scan_triggered,
|
|
|
|
station_quick_scan_results,
|
|
|
|
station_quick_scan_destroy);
|
2021-02-03 16:14:41 +01:00
|
|
|
if (!station->quick_scan_id)
|
|
|
|
return -EIO;
|
2019-04-16 23:51:42 +02:00
|
|
|
|
2021-02-03 16:14:41 +01:00
|
|
|
return 0;
|
2019-04-16 23:51:42 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 20:45:49 +02:00
|
|
|
static const char *station_state_to_string(enum station_state state)
|
2018-09-04 17:40:45 +02:00
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case STATION_STATE_DISCONNECTED:
|
|
|
|
return "disconnected";
|
2019-03-22 22:17:45 +01:00
|
|
|
case STATION_STATE_AUTOCONNECT_QUICK:
|
|
|
|
return "autoconnect_quick";
|
|
|
|
case STATION_STATE_AUTOCONNECT_FULL:
|
|
|
|
return "autoconnect_full";
|
2018-09-04 17:40:45 +02:00
|
|
|
case STATION_STATE_CONNECTING:
|
|
|
|
return "connecting";
|
2021-05-24 23:09:28 +02:00
|
|
|
case STATION_STATE_CONNECTING_AUTO:
|
|
|
|
return "connecting (auto)";
|
2018-09-04 17:40:45 +02:00
|
|
|
case STATION_STATE_CONNECTED:
|
|
|
|
return "connected";
|
|
|
|
case STATION_STATE_DISCONNECTING:
|
|
|
|
return "disconnecting";
|
|
|
|
case STATION_STATE_ROAMING:
|
|
|
|
return "roaming";
|
2022-09-28 20:33:50 +02:00
|
|
|
case STATION_STATE_FT_ROAMING:
|
|
|
|
return "ft-roaming";
|
|
|
|
case STATION_STATE_FW_ROAMING:
|
|
|
|
return "fw-roaming";
|
2018-09-04 17:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "invalid";
|
|
|
|
}
|
|
|
|
|
2021-11-03 23:15:01 +01:00
|
|
|
static void station_set_evict_nocarrier(struct station *station, bool value)
|
|
|
|
{
|
|
|
|
char *v = value ? "1" : "0";
|
|
|
|
|
|
|
|
if (supports_arp_evict_nocarrier)
|
|
|
|
sysfs_write_ipv4_setting(netdev_get_name(station->netdev),
|
|
|
|
"arp_evict_nocarrier", v);
|
|
|
|
|
|
|
|
if (supports_ndisc_evict_nocarrier)
|
|
|
|
sysfs_write_ipv6_setting(netdev_get_name(station->netdev),
|
|
|
|
"ndisc_evict_nocarrier", v);
|
|
|
|
}
|
|
|
|
|
2021-11-04 18:57:57 +01:00
|
|
|
/*
|
|
|
|
* Handles dropping ARP (IPv4) and neighbor advertisements (IPv6) settings.
|
|
|
|
*/
|
|
|
|
static void station_set_drop_neighbor_discovery(struct station *station,
|
|
|
|
bool value)
|
|
|
|
{
|
|
|
|
char *v = value ? "1" : "0";
|
|
|
|
|
|
|
|
sysfs_write_ipv4_setting(netdev_get_name(station->netdev),
|
|
|
|
"drop_gratuitous_arp", v);
|
|
|
|
sysfs_write_ipv6_setting(netdev_get_name(station->netdev),
|
|
|
|
"drop_unsolicited_na", v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_set_drop_unicast_l2_multicast(struct station *station,
|
|
|
|
bool value)
|
|
|
|
{
|
|
|
|
char *v = value ? "1" : "0";
|
|
|
|
|
|
|
|
sysfs_write_ipv4_setting(netdev_get_name(station->netdev),
|
|
|
|
"drop_unicast_in_l2_multicast", v);
|
|
|
|
sysfs_write_ipv6_setting(netdev_get_name(station->netdev),
|
|
|
|
"drop_unicast_in_l2_multicast", v);
|
|
|
|
}
|
|
|
|
|
2022-05-23 08:20:52 +02:00
|
|
|
static void station_signal_agent_notify(struct station *station);
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_enter_state(struct station *station,
|
|
|
|
enum station_state state)
|
2018-09-04 17:40:45 +02:00
|
|
|
{
|
2019-07-08 16:02:59 +02:00
|
|
|
uint64_t id = netdev_get_wdev_id(station->netdev);
|
2018-09-05 01:00:48 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
bool disconnected;
|
2022-08-04 20:51:09 +02:00
|
|
|
int ret;
|
2018-09-05 01:00:48 +02:00
|
|
|
|
|
|
|
l_debug("Old State: %s, new state: %s",
|
|
|
|
station_state_to_string(station->state),
|
|
|
|
station_state_to_string(state));
|
|
|
|
|
2019-03-22 22:17:45 +01:00
|
|
|
disconnected = !station_is_busy(station);
|
2018-09-05 01:00:48 +02:00
|
|
|
|
2019-03-22 22:17:45 +01:00
|
|
|
if ((disconnected && state > STATION_STATE_AUTOCONNECT_FULL) ||
|
2018-09-15 04:53:01 +02:00
|
|
|
(!disconnected && state != station->state))
|
2018-09-08 03:05:21 +02:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_INTERFACE, "State");
|
2018-09-05 00:32:18 +02:00
|
|
|
|
2021-02-03 16:14:41 +01:00
|
|
|
station->state = state;
|
|
|
|
|
2018-09-05 00:32:18 +02:00
|
|
|
switch (state) {
|
2019-03-22 22:17:45 +01:00
|
|
|
case STATION_STATE_AUTOCONNECT_QUICK:
|
2022-08-04 20:51:09 +02:00
|
|
|
ret = station_quick_scan_trigger(station);
|
|
|
|
if (ret == 0 || ret == -EAGAIN)
|
2021-02-03 16:14:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
station->state = STATION_STATE_AUTOCONNECT_FULL;
|
|
|
|
/* Fall through */
|
2019-03-22 22:17:45 +01:00
|
|
|
case STATION_STATE_AUTOCONNECT_FULL:
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_periodic_start(id, periodic_scan_trigger,
|
2018-09-05 00:32:18 +02:00
|
|
|
new_scan_results, station);
|
|
|
|
break;
|
2019-01-29 21:36:11 +01:00
|
|
|
case STATION_STATE_CONNECTING:
|
2021-05-24 23:09:28 +02:00
|
|
|
case STATION_STATE_CONNECTING_AUTO:
|
2020-08-14 15:40:32 +02:00
|
|
|
/* Refresh the ordered network list */
|
|
|
|
network_rank_update(station->connected_network, true);
|
2022-02-10 22:06:50 +01:00
|
|
|
l_queue_remove(station->networks_sorted,
|
|
|
|
station->connected_network);
|
|
|
|
l_queue_insert(station->networks_sorted,
|
|
|
|
station->connected_network,
|
2020-08-14 15:40:32 +02:00
|
|
|
network_rank_compare, NULL);
|
|
|
|
|
2019-01-29 21:36:11 +01:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_INTERFACE, "ConnectedNetwork");
|
|
|
|
l_dbus_property_changed(dbus,
|
|
|
|
network_get_path(station->connected_network),
|
|
|
|
IWD_NETWORK_INTERFACE, "Connected");
|
2021-02-03 20:07:04 +01:00
|
|
|
|
2022-05-23 08:20:53 +02:00
|
|
|
if (station->signal_agent)
|
|
|
|
station_signal_agent_notify(station);
|
|
|
|
|
2021-02-03 20:07:04 +01:00
|
|
|
periodic_scan_stop(station);
|
|
|
|
break;
|
2018-09-05 00:32:18 +02:00
|
|
|
case STATION_STATE_CONNECTED:
|
2021-02-03 20:07:04 +01:00
|
|
|
l_dbus_object_add_interface(dbus,
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DIAGNOSTIC_INTERFACE,
|
|
|
|
station);
|
2021-11-04 18:57:57 +01:00
|
|
|
periodic_scan_stop(station);
|
|
|
|
|
|
|
|
station_set_evict_nocarrier(station, true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hotspot Specification 2.0 - Section 6.5
|
|
|
|
*
|
|
|
|
* " - Shall drop all received {gratuitous ARP, unsolicited
|
|
|
|
* Neighbor Advertisement} messages when the Proxy ARP field
|
|
|
|
* is set to 1 in the Extended Capabilities element of the
|
|
|
|
* serving AP.
|
|
|
|
*
|
|
|
|
* - When the serving AP transmits frames containing an HS2.0
|
|
|
|
* Indication element in which the value of the DGAF Disable
|
|
|
|
* bit subfield is set to 0, the mobile device should
|
|
|
|
* discard all received unicast IP packets that were
|
|
|
|
* decrypted using the GTK"
|
|
|
|
*/
|
|
|
|
if (station->connected_bss->proxy_arp)
|
|
|
|
station_set_drop_neighbor_discovery(station, true);
|
|
|
|
if (station->connected_bss->hs20_dgaf_disable)
|
|
|
|
station_set_drop_unicast_l2_multicast(station, true);
|
|
|
|
|
|
|
|
break;
|
2021-11-03 23:15:01 +01:00
|
|
|
case STATION_STATE_DISCONNECTED:
|
2018-09-05 00:32:18 +02:00
|
|
|
periodic_scan_stop(station);
|
2021-11-03 23:15:01 +01:00
|
|
|
|
|
|
|
station_set_evict_nocarrier(station, true);
|
2021-11-04 18:57:57 +01:00
|
|
|
station_set_drop_neighbor_discovery(station, false);
|
|
|
|
station_set_drop_unicast_l2_multicast(station, false);
|
2018-09-05 00:32:18 +02:00
|
|
|
break;
|
|
|
|
case STATION_STATE_DISCONNECTING:
|
2021-04-28 21:27:00 +02:00
|
|
|
break;
|
2018-09-05 00:32:18 +02:00
|
|
|
case STATION_STATE_ROAMING:
|
2022-09-28 20:33:50 +02:00
|
|
|
case STATION_STATE_FT_ROAMING:
|
|
|
|
case STATION_STATE_FW_ROAMING:
|
2021-11-03 23:15:01 +01:00
|
|
|
station_set_evict_nocarrier(station, false);
|
2018-09-05 00:32:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
WATCHLIST_NOTIFY(&station->state_watches,
|
2021-02-03 16:14:41 +01:00
|
|
|
station_state_watch_func_t, station->state);
|
2018-09-04 17:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum station_state station_get_state(struct station *station)
|
|
|
|
{
|
|
|
|
return station->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t station_add_state_watch(struct station *station,
|
|
|
|
station_state_watch_func_t func,
|
|
|
|
void *user_data,
|
|
|
|
station_destroy_func_t destroy)
|
|
|
|
{
|
|
|
|
return watchlist_add(&station->state_watches, func, user_data, destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool station_remove_state_watch(struct station *station, uint32_t id)
|
|
|
|
{
|
|
|
|
return watchlist_remove(&station->state_watches, id);
|
|
|
|
}
|
|
|
|
|
2021-09-15 19:36:18 +02:00
|
|
|
uint32_t station_add_event_watch(station_event_watch_func_t func,
|
2020-06-12 21:14:11 +02:00
|
|
|
void *user_data,
|
|
|
|
station_destroy_func_t destroy)
|
|
|
|
{
|
2021-09-15 19:36:18 +02:00
|
|
|
return watchlist_add(&event_watches, func, user_data, destroy);
|
2020-06-12 21:14:11 +02:00
|
|
|
}
|
|
|
|
|
2021-09-15 19:36:18 +02:00
|
|
|
void station_remove_event_watch(uint32_t id)
|
2020-06-12 21:14:11 +02:00
|
|
|
{
|
2021-09-15 19:36:18 +02:00
|
|
|
watchlist_remove(&event_watches, id);
|
2020-06-12 21:14:11 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 01:00:48 +02:00
|
|
|
bool station_set_autoconnect(struct station *station, bool autoconnect)
|
|
|
|
{
|
|
|
|
if (station->autoconnect == autoconnect)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
station->autoconnect = autoconnect;
|
|
|
|
|
|
|
|
if (station->state == STATION_STATE_DISCONNECTED && autoconnect)
|
2019-03-22 22:17:45 +01:00
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
|
2018-09-05 01:00:48 +02:00
|
|
|
|
2019-03-22 22:17:45 +01:00
|
|
|
if (station_is_autoconnecting(station) && !autoconnect)
|
2018-09-05 01:00:48 +02:00
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTED);
|
|
|
|
|
2021-08-12 22:38:06 +02:00
|
|
|
if (iwd_is_developer_mode())
|
|
|
|
l_dbus_property_changed(dbus_get_bus(),
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DEBUG_INTERFACE, "AutoConnect");
|
|
|
|
|
2018-09-05 01:00:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-05 01:25:31 +02:00
|
|
|
static void station_roam_state_clear(struct station *station)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
2022-01-14 23:30:26 +01:00
|
|
|
l_debug("%u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
l_timeout_remove(station->roam_trigger_timeout);
|
|
|
|
station->roam_trigger_timeout = NULL;
|
|
|
|
station->preparing_roam = false;
|
2020-06-30 19:34:41 +02:00
|
|
|
station->roam_scan_full = false;
|
2018-09-04 20:48:18 +02:00
|
|
|
station->signal_low = false;
|
|
|
|
station->roam_min_time.tv_sec = 0;
|
2023-05-02 20:59:41 +02:00
|
|
|
station->netconfig_after_roam = false;
|
2023-10-30 14:48:37 +01:00
|
|
|
station->last_roam_scan = 0;
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
if (station->roam_scan_id)
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
2018-09-04 20:48:18 +02:00
|
|
|
station->roam_scan_id);
|
2021-02-01 22:12:17 +01:00
|
|
|
|
|
|
|
if (station->roam_freqs) {
|
|
|
|
scan_freq_set_free(station->roam_freqs);
|
|
|
|
station->roam_freqs = NULL;
|
|
|
|
}
|
2022-09-27 21:47:24 +02:00
|
|
|
|
|
|
|
l_queue_clear(station->roam_bss_list, l_free);
|
2022-09-27 21:47:28 +02:00
|
|
|
|
|
|
|
ft_clear_authentications(netdev_get_ifindex(station->netdev));
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 04:28:18 +02:00
|
|
|
static void station_reset_connection_state(struct station *station)
|
|
|
|
{
|
|
|
|
struct network *network = station->connected_network;
|
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
|
2022-01-14 23:30:26 +01:00
|
|
|
l_debug("%u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
2018-09-05 04:28:18 +02:00
|
|
|
if (!network)
|
|
|
|
return;
|
|
|
|
|
|
|
|
station_roam_state_clear(station);
|
|
|
|
|
2022-06-16 02:02:19 +02:00
|
|
|
if (station->netconfig)
|
|
|
|
netconfig_reset(station->netconfig);
|
|
|
|
|
2020-08-14 15:40:32 +02:00
|
|
|
/* Refresh the ordered network list */
|
|
|
|
network_rank_update(station->connected_network, false);
|
|
|
|
l_queue_remove(station->networks_sorted, station->connected_network);
|
|
|
|
l_queue_insert(station->networks_sorted, station->connected_network,
|
|
|
|
network_rank_compare, NULL);
|
|
|
|
|
2020-08-17 12:06:38 +02:00
|
|
|
station->connected_bss = NULL;
|
|
|
|
station->connected_network = NULL;
|
|
|
|
|
2018-09-08 03:05:21 +02:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_INTERFACE, "ConnectedNetwork");
|
2018-09-05 04:28:18 +02:00
|
|
|
l_dbus_property_changed(dbus, network_get_path(network),
|
|
|
|
IWD_NETWORK_INTERFACE, "Connected");
|
2021-06-18 09:33:22 +02:00
|
|
|
l_dbus_object_remove_interface(dbus, netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DIAGNOSTIC_INTERFACE);
|
2022-04-08 20:18:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform this step last since calling network_disconnected() might
|
|
|
|
* result in the removal of the network (for example if provisioning
|
|
|
|
* a new hidden network fails with an incorrect pasword).
|
|
|
|
*/
|
|
|
|
if (station->state == STATION_STATE_CONNECTED ||
|
|
|
|
station->state == STATION_STATE_CONNECTING ||
|
|
|
|
station->state == STATION_STATE_CONNECTING_AUTO ||
|
2022-09-28 20:33:50 +02:00
|
|
|
station_is_roaming(station))
|
2022-04-08 20:18:09 +02:00
|
|
|
network_disconnected(network);
|
2018-09-05 04:28:18 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_disassociated(struct station *station)
|
2018-09-05 04:28:18 +02:00
|
|
|
{
|
|
|
|
l_debug("%u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
|
|
|
station_reset_connection_state(station);
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTED);
|
|
|
|
|
|
|
|
if (station->autoconnect)
|
2019-03-22 22:17:45 +01:00
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
|
2018-09-05 04:28:18 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
static void station_roam_timeout_rearm(struct station *station, int seconds);
|
2020-06-30 19:34:41 +02:00
|
|
|
static int station_roam_scan(struct station *station,
|
|
|
|
struct scan_freq_set *freq_set);
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2021-03-29 21:07:42 +02:00
|
|
|
static uint32_t station_freq_from_neighbor_report(const uint8_t *country,
|
2021-11-30 00:12:59 +01:00
|
|
|
struct ie_neighbor_report_info *info, enum band_freq *out_band)
|
2021-03-29 21:07:42 +02:00
|
|
|
{
|
2021-11-30 00:12:59 +01:00
|
|
|
enum band_freq band;
|
2021-03-29 21:07:42 +02:00
|
|
|
uint32_t freq;
|
|
|
|
|
|
|
|
if (info->oper_class == 0) {
|
|
|
|
/*
|
|
|
|
* Some Cisco APs report all operating class values as 0
|
|
|
|
* in the Neighbor Report Responses. Work around this by
|
|
|
|
* using the most likely operating class for the channel
|
|
|
|
* number as the 2.4GHz and 5GHz bands happen to mostly
|
|
|
|
* use channels in two disjoint ranges.
|
|
|
|
*/
|
|
|
|
if (info->channel_num >= 1 && info->channel_num <= 14)
|
2021-11-30 00:12:59 +01:00
|
|
|
band = BAND_FREQ_2_4_GHZ;
|
2021-03-29 21:07:42 +02:00
|
|
|
else if (info->channel_num >= 36 && info->channel_num <= 169)
|
2021-11-30 00:12:59 +01:00
|
|
|
band = BAND_FREQ_5_GHZ;
|
2021-03-29 21:07:42 +02:00
|
|
|
else {
|
|
|
|
l_debug("Ignored: 0 oper class with an unusual "
|
|
|
|
"channel number");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-30 00:12:59 +01:00
|
|
|
band = band_oper_class_to_band(country, info->oper_class);
|
2021-03-29 21:07:42 +02:00
|
|
|
if (!band) {
|
|
|
|
l_debug("Ignored: unsupported oper class");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 00:12:59 +01:00
|
|
|
freq = band_channel_to_freq(info->channel_num, band);
|
2021-03-29 21:07:42 +02:00
|
|
|
if (!freq) {
|
|
|
|
l_debug("Ignored: unsupported channel");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out_band)
|
|
|
|
*out_band = band;
|
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_neighbor_report(struct station *station,
|
|
|
|
const uint8_t *reports,
|
|
|
|
size_t reports_len,
|
|
|
|
struct scan_freq_set **set)
|
|
|
|
{
|
|
|
|
struct ie_tlv_iter iter;
|
|
|
|
int count_md = 0, count_no_md = 0;
|
|
|
|
struct scan_freq_set *freq_set_md, *freq_set_no_md;
|
|
|
|
uint32_t current_freq = 0;
|
|
|
|
struct handshake_state *hs = netdev_get_handshake(station->netdev);
|
|
|
|
|
|
|
|
freq_set_md = scan_freq_set_new();
|
|
|
|
freq_set_no_md = scan_freq_set_new();
|
|
|
|
|
|
|
|
ie_tlv_iter_init(&iter, reports, reports_len);
|
|
|
|
|
|
|
|
/* First see if any of the reports contain the MD bit set */
|
|
|
|
while (ie_tlv_iter_next(&iter)) {
|
|
|
|
struct ie_neighbor_report_info info;
|
|
|
|
uint32_t freq;
|
2021-11-30 00:12:59 +01:00
|
|
|
enum band_freq band;
|
2021-03-29 21:07:42 +02:00
|
|
|
const uint8_t *cc = NULL;
|
2022-12-16 22:27:39 +01:00
|
|
|
const struct band_freq_attrs *attr;
|
2021-03-29 21:07:42 +02:00
|
|
|
|
|
|
|
if (ie_tlv_iter_get_tag(&iter) != IE_TYPE_NEIGHBOR_REPORT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ie_parse_neighbor_report(&iter, &info) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
l_debug("Neighbor report received for %s: ch %i "
|
|
|
|
"(oper class %i), %s",
|
|
|
|
util_address_to_string(info.addr),
|
|
|
|
(int) info.channel_num, (int) info.oper_class,
|
|
|
|
info.md ? "MD set" : "MD not set");
|
|
|
|
|
|
|
|
if (station->connected_bss->cc_present)
|
|
|
|
cc = station->connected_bss->cc;
|
|
|
|
|
|
|
|
freq = station_freq_from_neighbor_report(cc, &info, &band);
|
|
|
|
if (!freq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Skip if the band is not supported */
|
|
|
|
if (!(band & wiphy_get_supported_bands(station->wiphy)))
|
|
|
|
continue;
|
|
|
|
|
2022-10-10 21:40:10 +02:00
|
|
|
/* Skip if frequency is not supported or disabled */
|
2022-12-16 22:27:39 +01:00
|
|
|
attr = wiphy_get_frequency_info(station->wiphy, freq);
|
|
|
|
if (!attr || attr->disabled)
|
2022-02-25 23:03:37 +01:00
|
|
|
continue;
|
|
|
|
|
2021-03-29 21:07:42 +02:00
|
|
|
if (!memcmp(info.addr,
|
|
|
|
station->connected_bss->addr, ETH_ALEN)) {
|
|
|
|
/*
|
|
|
|
* If this report is for the current AP, don't add
|
|
|
|
* it to any of the lists yet. We will need to scan
|
|
|
|
* its channel because it may still be the best ranked
|
|
|
|
* or the only visible AP.
|
|
|
|
*/
|
|
|
|
current_freq = freq;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the frequency to one of the lists */
|
|
|
|
if (info.md && hs->mde) {
|
|
|
|
scan_freq_set_add(freq_set_md, freq);
|
|
|
|
|
|
|
|
count_md += 1;
|
|
|
|
} else {
|
|
|
|
scan_freq_set_add(freq_set_no_md, freq);
|
|
|
|
|
|
|
|
count_no_md += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!current_freq)
|
|
|
|
current_freq = station->connected_bss->frequency;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are neighbor reports with the MD bit set then the bit
|
|
|
|
* is probably valid so scan only the frequencies of the neighbors
|
|
|
|
* with that bit set, which will allow us to use Fast Transition.
|
|
|
|
* Some APs, such as those based on hostapd do not set the MD bit
|
|
|
|
* even if the neighbor is within the MD.
|
|
|
|
*
|
|
|
|
* In any case we only select the frequencies here and will check
|
|
|
|
* the IEs in the scan results as the authoritative information
|
|
|
|
* on whether we can use Fast Transition, and rank BSSes based on
|
|
|
|
* that.
|
|
|
|
*
|
|
|
|
* TODO: possibly save the neighbors from outside the MD and if
|
|
|
|
* none of the ones in the MD end up working, try a non-FT
|
|
|
|
* transition to those neighbors. We should be using a
|
|
|
|
* blacklisting mechanism (for both initial connection and
|
|
|
|
* transitions) so that cound_md would not count the
|
|
|
|
* BSSes already used and when it goes down to 0 we'd
|
|
|
|
* automatically fall back to the non-FT candidates and then to
|
|
|
|
* full scan.
|
|
|
|
*/
|
|
|
|
if (count_md) {
|
|
|
|
scan_freq_set_add(freq_set_md, current_freq);
|
|
|
|
*set = freq_set_md;
|
|
|
|
scan_freq_set_free(freq_set_no_md);
|
|
|
|
} else if (count_no_md) {
|
|
|
|
scan_freq_set_add(freq_set_no_md, current_freq);
|
|
|
|
*set = freq_set_no_md;
|
|
|
|
scan_freq_set_free(freq_set_md);
|
|
|
|
} else {
|
|
|
|
scan_freq_set_free(freq_set_no_md);
|
|
|
|
scan_freq_set_free(freq_set_md);
|
|
|
|
*set = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_early_neighbor_report_cb(struct netdev *netdev, int err,
|
|
|
|
const uint8_t *reports,
|
|
|
|
size_t reports_len,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
2021-09-24 00:57:26 +02:00
|
|
|
if (err == -ENODEV)
|
|
|
|
return;
|
|
|
|
|
2021-03-29 21:07:42 +02:00
|
|
|
l_debug("ifindex: %u, error: %d(%s)",
|
|
|
|
netdev_get_ifindex(station->netdev),
|
|
|
|
err, err < 0 ? strerror(-err) : "");
|
|
|
|
|
|
|
|
if (!reports || err)
|
|
|
|
return;
|
|
|
|
|
|
|
|
parse_neighbor_report(station, reports, reports_len,
|
|
|
|
&station->roam_freqs);
|
|
|
|
}
|
|
|
|
|
2021-09-28 23:27:37 +02:00
|
|
|
static bool station_can_fast_transition(struct handshake_state *hs,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
uint16_t mdid;
|
|
|
|
|
|
|
|
if (!hs->mde)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (ie_parse_mobility_domain_from_data(hs->mde, hs->mde[1] + 2,
|
|
|
|
&mdid, NULL, NULL) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!(bss->mde_present && l_get_le16(bss->mde) == mdid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (hs->supplicant_ie != NULL) {
|
|
|
|
struct ie_rsn_info rsn_info;
|
|
|
|
|
|
|
|
if (!IE_AKM_IS_FT(hs->akm_suite))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (scan_bss_get_rsn_info(bss, &rsn_info) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!IE_AKM_IS_FT(rsn_info.akm_suites))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-05-02 20:59:41 +02:00
|
|
|
static void station_disconnect_on_error_cb(struct netdev *netdev, bool success,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
bool continue_autoconnect;
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTED);
|
|
|
|
|
|
|
|
continue_autoconnect = station->state == STATION_STATE_CONNECTING_AUTO;
|
|
|
|
|
|
|
|
if (continue_autoconnect) {
|
|
|
|
if (station_autoconnect_next(station) < 0) {
|
|
|
|
l_debug("Nothing left on autoconnect list");
|
|
|
|
station_enter_state(station,
|
|
|
|
STATION_STATE_AUTOCONNECT_FULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (station->autoconnect)
|
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_netconfig_event_handler(enum netconfig_event event,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case NETCONFIG_EVENT_CONNECTED:
|
|
|
|
station_enter_state(station, STATION_STATE_CONNECTED);
|
|
|
|
break;
|
|
|
|
case NETCONFIG_EVENT_FAILED:
|
|
|
|
if (station->connect_pending) {
|
|
|
|
struct l_dbus_message *reply = dbus_error_failed(
|
|
|
|
station->connect_pending);
|
|
|
|
|
|
|
|
dbus_pending_reply(&station->connect_pending, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (L_IN_SET(station->state, STATION_STATE_CONNECTING,
|
|
|
|
STATION_STATE_CONNECTING_AUTO))
|
|
|
|
network_connect_failed(station->connected_network,
|
|
|
|
false);
|
|
|
|
|
|
|
|
netdev_disconnect(station->netdev,
|
|
|
|
station_disconnect_on_error_cb,
|
|
|
|
station);
|
|
|
|
station_reset_connection_state(station);
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTING);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
l_error("station: Unsupported netconfig event: %d.", event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-20 15:55:55 +02:00
|
|
|
static bool netconfig_after_roam(struct station *station)
|
|
|
|
{
|
|
|
|
const struct network *network = station_get_connected_network(station);
|
|
|
|
|
|
|
|
/* Netconfig was reset which frees all settings, reload now */
|
|
|
|
if (!netconfig_load_settings(station->netconfig,
|
|
|
|
network_get_settings(network)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return netconfig_configure(station->netconfig,
|
|
|
|
station_netconfig_event_handler,
|
|
|
|
station);
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_roamed(struct station *station)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
2021-01-22 14:37:00 +01:00
|
|
|
station->roam_scan_full = false;
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
/*
|
2021-01-22 14:37:00 +01:00
|
|
|
* Schedule another roaming attempt in case the signal continues to
|
|
|
|
* remain low. A subsequent high signal notification will cancel it.
|
2018-09-04 20:48:18 +02:00
|
|
|
*/
|
2021-01-22 14:37:00 +01:00
|
|
|
if (station->signal_low)
|
2021-01-22 14:37:01 +01:00
|
|
|
station_roam_timeout_rearm(station, roam_retry_interval);
|
2019-10-09 23:53:31 +02:00
|
|
|
|
|
|
|
if (station->netconfig)
|
2021-11-03 23:15:02 +01:00
|
|
|
netconfig_reconfigure(station->netconfig,
|
|
|
|
!supports_arp_evict_nocarrier);
|
2019-10-09 23:53:31 +02:00
|
|
|
|
2021-03-29 21:07:40 +02:00
|
|
|
if (station->roam_freqs) {
|
|
|
|
scan_freq_set_free(station->roam_freqs);
|
|
|
|
station->roam_freqs = NULL;
|
|
|
|
}
|
|
|
|
|
2021-03-29 21:07:42 +02:00
|
|
|
if (station->connected_bss->cap_rm_neighbor_report) {
|
|
|
|
if (netdev_neighbor_report_req(station->netdev,
|
|
|
|
station_early_neighbor_report_cb) < 0)
|
|
|
|
l_warn("Could not request neighbor report");
|
|
|
|
}
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
l_queue_clear(station->roam_bss_list, l_free);
|
|
|
|
|
2023-05-02 20:59:41 +02:00
|
|
|
/* Re-enable netconfig if it never finished on the last BSS */
|
|
|
|
if (station->netconfig_after_roam) {
|
|
|
|
station->netconfig_after_roam = false;
|
2023-10-20 15:55:55 +02:00
|
|
|
L_WARN_ON(!netconfig_after_roam(station));
|
2023-05-02 20:59:41 +02:00
|
|
|
} else
|
|
|
|
station_enter_state(station, STATION_STATE_CONNECTED);
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2021-04-30 19:47:03 +02:00
|
|
|
static void station_roam_retry(struct station *station)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If we're still connected to the old BSS, only clear preparing_roam
|
|
|
|
* and reattempt in 60 seconds if signal level is still low at that
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
station->preparing_roam = false;
|
|
|
|
station->roam_scan_full = false;
|
|
|
|
station->ap_directed_roaming = false;
|
|
|
|
|
|
|
|
if (station->signal_low)
|
|
|
|
station_roam_timeout_rearm(station, roam_retry_interval);
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_roam_failed(struct station *station)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
2020-06-30 17:35:47 +02:00
|
|
|
l_debug("%u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
l_queue_clear(station->roam_bss_list, l_free);
|
|
|
|
|
2020-06-30 17:35:47 +02:00
|
|
|
/*
|
|
|
|
* If we attempted a reassociation or a fast transition, and ended up
|
|
|
|
* here then we are now disconnected.
|
|
|
|
*/
|
2022-09-28 20:33:50 +02:00
|
|
|
if (station_is_roaming(station)) {
|
2020-06-30 17:35:47 +02:00
|
|
|
station_disassociated(station);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-02 20:59:41 +02:00
|
|
|
/* Re-enable netconfig if needed, even on a failed roam */
|
|
|
|
if (station->netconfig_after_roam) {
|
|
|
|
station->netconfig_after_roam = false;
|
2023-10-20 15:55:55 +02:00
|
|
|
L_WARN_ON(!netconfig_after_roam(station));
|
2023-05-02 20:59:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 19:34:41 +02:00
|
|
|
/*
|
|
|
|
* We were told by the AP to roam, but failed. Try ourselves or
|
|
|
|
* wait for the AP to tell us to roam again
|
|
|
|
*/
|
|
|
|
if (station->ap_directed_roaming)
|
|
|
|
goto delayed_retry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we tried a limited scan, failed and the signal is still low,
|
|
|
|
* repeat with a full scan right away
|
|
|
|
*/
|
2021-04-28 19:55:56 +02:00
|
|
|
if (station->signal_low && !station->roam_scan_full) {
|
|
|
|
/*
|
|
|
|
* Since we're re-using roam_scan_id, explicitly cancel
|
|
|
|
* the scan here, so that the destroy callback is not called
|
|
|
|
* after the return of this function
|
|
|
|
*/
|
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
|
|
|
station->roam_scan_id);
|
|
|
|
|
|
|
|
if (!station_roam_scan(station, NULL))
|
|
|
|
return;
|
|
|
|
}
|
2020-06-30 19:34:41 +02:00
|
|
|
|
|
|
|
delayed_retry:
|
2021-04-30 19:47:03 +02:00
|
|
|
station_roam_retry(station);
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_reassociate_cb(struct netdev *netdev,
|
|
|
|
enum netdev_result result,
|
2019-02-28 18:32:40 +01:00
|
|
|
void *event_data,
|
2018-09-05 06:26:54 +02:00
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result);
|
|
|
|
|
|
|
|
if (station->state != STATION_STATE_ROAMING)
|
|
|
|
return;
|
|
|
|
|
2019-10-09 23:53:31 +02:00
|
|
|
if (result == NETDEV_RESULT_OK)
|
2018-09-05 06:26:54 +02:00
|
|
|
station_roamed(station);
|
2019-10-09 23:53:31 +02:00
|
|
|
else
|
2018-09-05 06:26:54 +02:00
|
|
|
station_roam_failed(station);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
|
2019-03-01 00:41:51 +01:00
|
|
|
void *event_data, void *user_data);
|
2018-09-05 06:26:54 +02:00
|
|
|
|
2022-09-27 21:47:28 +02:00
|
|
|
static int station_transition_reassociate(struct station *station,
|
2018-09-05 06:26:54 +02:00
|
|
|
struct scan_bss *bss,
|
|
|
|
struct handshake_state *new_hs)
|
|
|
|
{
|
2022-09-27 21:47:28 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = netdev_reassociate(station->netdev, bss, station->connected_bss,
|
2018-09-05 06:26:54 +02:00
|
|
|
new_hs, station_netdev_event,
|
2022-09-27 21:47:28 +02:00
|
|
|
station_reassociate_cb, station);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2018-09-05 06:26:54 +02:00
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
l_debug("");
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
station->connected_bss = bss;
|
|
|
|
station->preparing_roam = false;
|
|
|
|
station_enter_state(station, STATION_STATE_ROAMING);
|
2022-09-27 21:47:28 +02:00
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
station_debug_event(station, "reassoc-roam");
|
|
|
|
|
2022-09-27 21:47:28 +02:00
|
|
|
return 0;
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool bss_match_bssid(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct scan_bss *bss = a;
|
|
|
|
const uint8_t *bssid = b;
|
|
|
|
|
|
|
|
return !memcmp(bss->addr, bssid, sizeof(bss->addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_preauthenticate_cb(struct netdev *netdev,
|
|
|
|
enum netdev_result result,
|
|
|
|
const uint8_t *pmk, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct network *connected = station->connected_network;
|
|
|
|
struct scan_bss *bss;
|
|
|
|
struct handshake_state *new_hs;
|
|
|
|
|
|
|
|
l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result);
|
|
|
|
|
|
|
|
if (!station->preparing_roam || result == NETDEV_RESULT_ABORTED)
|
|
|
|
return;
|
|
|
|
|
2022-09-27 17:31:53 +02:00
|
|
|
bss = network_bss_find_by_addr(station->connected_network,
|
|
|
|
station->preauth_bssid);
|
2018-09-05 06:26:54 +02:00
|
|
|
if (!bss) {
|
|
|
|
l_error("Roam target BSS not found");
|
|
|
|
station_roam_failed(station);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_hs = station_handshake_setup(station, connected, bss);
|
|
|
|
if (!new_hs) {
|
|
|
|
l_error("station_handshake_setup failed");
|
|
|
|
|
|
|
|
station_roam_failed(station);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == NETDEV_RESULT_OK) {
|
|
|
|
uint8_t pmkid[16];
|
|
|
|
uint8_t rsne_buf[300];
|
|
|
|
struct ie_rsn_info rsn_info;
|
|
|
|
|
|
|
|
handshake_state_set_pmk(new_hs, pmk, 32);
|
|
|
|
handshake_state_set_authenticator_address(new_hs,
|
|
|
|
station->preauth_bssid);
|
|
|
|
handshake_state_set_supplicant_address(new_hs,
|
|
|
|
netdev_get_address(station->netdev));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rebuild the RSNE to include the negotiated PMKID. Note
|
|
|
|
* supplicant_ie can't be a WPA IE here, including because
|
|
|
|
* the WPA IE doesn't have a capabilities field and
|
|
|
|
* target_rsne->preauthentication would have been false in
|
|
|
|
* station_transition_start.
|
|
|
|
*/
|
|
|
|
ie_parse_rsne_from_data(new_hs->supplicant_ie,
|
|
|
|
new_hs->supplicant_ie[1] + 2,
|
|
|
|
&rsn_info);
|
|
|
|
|
2023-06-20 19:25:32 +02:00
|
|
|
/*
|
|
|
|
* IEEE 802.11 Section 12.7.1.3:
|
|
|
|
*
|
|
|
|
* "When the PMKID is calculated for the PMKSA as part of
|
|
|
|
* preauthentication, the AKM has not yet been negotiated.
|
|
|
|
* In this case, the HMAC-SHA-1 based derivation is used for
|
|
|
|
* the PMKID calculation."
|
|
|
|
*/
|
|
|
|
handshake_state_get_pmkid(new_hs, pmkid, L_CHECKSUM_SHA1);
|
2018-09-05 06:26:54 +02:00
|
|
|
|
|
|
|
rsn_info.num_pmkids = 1;
|
|
|
|
rsn_info.pmkids = pmkid;
|
|
|
|
|
|
|
|
ie_build_rsne(&rsn_info, rsne_buf);
|
2019-06-07 21:17:00 +02:00
|
|
|
handshake_state_set_supplicant_ie(new_hs, rsne_buf);
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2022-09-27 21:47:28 +02:00
|
|
|
if (station_transition_reassociate(station, bss, new_hs) < 0) {
|
|
|
|
handshake_state_free(new_hs);
|
|
|
|
station_roam_failed(station);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_transition_start(struct station *station);
|
|
|
|
|
|
|
|
static bool station_ft_work_ready(struct wiphy_radio_work_item *item)
|
|
|
|
{
|
|
|
|
struct station *station = l_container_of(item, struct station, ft_work);
|
2023-08-31 14:39:23 +02:00
|
|
|
_auto_(l_free) struct roam_bss *rbss = l_queue_pop_head(
|
|
|
|
station->roam_bss_list);
|
|
|
|
struct scan_bss *bss;
|
2022-09-27 21:47:28 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Very unlikely, but the BSS could have gone away */
|
2023-08-31 14:39:23 +02:00
|
|
|
bss = network_bss_find_by_addr(station->connected_network, rbss->addr);
|
2022-09-27 21:47:28 +02:00
|
|
|
if (!bss)
|
|
|
|
goto try_next;
|
|
|
|
|
|
|
|
ret = ft_associate(netdev_get_ifindex(station->netdev), bss->addr);
|
2023-08-31 14:39:23 +02:00
|
|
|
switch (ret) {
|
|
|
|
case MMPDU_STATUS_CODE_INVALID_PMKID:
|
|
|
|
/*
|
|
|
|
* Re-insert removing FT from the ranking (scan_bss does not
|
|
|
|
* take into account FT, so we can use that rank directly).
|
|
|
|
* If the BSS is still the best reassociation will be used,
|
|
|
|
* otherwise we'll try more FT candidates that are better ranked
|
|
|
|
*/
|
|
|
|
rbss->rank = bss->rank;
|
|
|
|
rbss->ft_failed = true;
|
|
|
|
|
|
|
|
l_debug("Re-inserting BSS "MAC" using reassociation, rank: %u",
|
|
|
|
MAC_STR(rbss->addr), rbss->rank);
|
|
|
|
|
|
|
|
l_queue_insert(station->roam_bss_list, rbss,
|
|
|
|
roam_bss_rank_compare, NULL);
|
|
|
|
|
|
|
|
station_debug_event(station, "ft-fallback-to-reassoc");
|
|
|
|
|
|
|
|
station_transition_start(station);
|
|
|
|
l_steal_ptr(rbss);
|
|
|
|
break;
|
|
|
|
case -ENOENT:
|
2022-12-14 22:26:57 +01:00
|
|
|
station_debug_event(station, "ft-roam-failed");
|
2022-09-27 21:47:28 +02:00
|
|
|
try_next:
|
|
|
|
station_transition_start(station);
|
2023-08-31 14:39:23 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
station->connected_bss = bss;
|
|
|
|
station->preparing_roam = false;
|
|
|
|
station_enter_state(station, STATION_STATE_FT_ROAMING);
|
2022-09-27 21:47:28 +02:00
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
station_debug_event(station, "ft-roam");
|
2022-09-27 21:47:28 +02:00
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (ret > 0)
|
|
|
|
goto try_next;
|
|
|
|
|
|
|
|
station_roam_failed(station);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-27 21:47:28 +02:00
|
|
|
|
|
|
|
return true;
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2022-09-27 21:47:28 +02:00
|
|
|
static const struct wiphy_radio_work_item_ops ft_work_ops = {
|
|
|
|
.do_work = station_ft_work_ready,
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool station_fast_transition(struct station *station,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
struct handshake_state *hs = netdev_get_handshake(station->netdev);
|
|
|
|
struct network *connected = station->connected_network;
|
|
|
|
const struct network_info *info = network_get_info(connected);
|
|
|
|
const struct iovec *vendor_ies;
|
|
|
|
size_t iov_elems = 0;
|
|
|
|
|
|
|
|
/* Rebuild handshake RSN for target AP */
|
|
|
|
if (station_build_handshake_rsn(hs, station->wiphy,
|
|
|
|
station->connected_network, bss) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Reset the vendor_ies in case they're different */
|
|
|
|
vendor_ies = network_info_get_extra_ies(info, bss, &iov_elems);
|
|
|
|
handshake_state_set_vendor_ies(hs, vendor_ies, iov_elems);
|
|
|
|
|
2023-01-13 22:24:36 +01:00
|
|
|
if (station->roam_trigger_timeout) {
|
|
|
|
l_timeout_remove(station->roam_trigger_timeout);
|
|
|
|
station->roam_trigger_timeout = NULL;
|
|
|
|
}
|
|
|
|
|
2022-12-14 22:26:57 +01:00
|
|
|
/* Both ft_action/ft_authenticate will gate the associate work item */
|
2023-03-01 16:35:48 +01:00
|
|
|
if ((hs->mde[4] & 1)) {
|
2022-12-14 22:26:57 +01:00
|
|
|
ft_action(netdev_get_ifindex(station->netdev),
|
|
|
|
station->connected_bss->frequency, bss);
|
2023-03-01 16:35:48 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (station->connected_bss->frequency == bss->frequency) {
|
|
|
|
ft_authenticate_onchannel(netdev_get_ifindex(station->netdev),
|
|
|
|
bss);
|
|
|
|
goto done;
|
|
|
|
}
|
2022-09-27 21:47:28 +02:00
|
|
|
|
2023-03-01 16:35:48 +01:00
|
|
|
ft_authenticate(netdev_get_ifindex(station->netdev), bss);
|
|
|
|
|
|
|
|
done:
|
2023-05-18 18:50:00 +02:00
|
|
|
if (station->ft_work.id)
|
|
|
|
wiphy_radio_work_reschedule(station->wiphy, &station->ft_work);
|
|
|
|
else
|
|
|
|
wiphy_radio_work_insert(station->wiphy, &station->ft_work,
|
|
|
|
WIPHY_WORK_PRIORITY_CONNECT,
|
|
|
|
&ft_work_ops);
|
2022-09-27 21:47:28 +02:00
|
|
|
|
2022-12-14 22:26:57 +01:00
|
|
|
return true;
|
2022-09-27 21:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_try_next_transition(struct station *station,
|
2023-08-31 14:39:23 +02:00
|
|
|
struct scan_bss *bss,
|
|
|
|
bool no_ft)
|
2018-09-05 06:26:54 +02:00
|
|
|
{
|
|
|
|
struct handshake_state *hs = netdev_get_handshake(station->netdev);
|
|
|
|
struct network *connected = station->connected_network;
|
|
|
|
enum security security = network_get_security(connected);
|
|
|
|
struct handshake_state *new_hs;
|
|
|
|
struct ie_rsn_info cur_rsne, target_rsne;
|
|
|
|
|
|
|
|
l_debug("%u, target %s", netdev_get_ifindex(station->netdev),
|
|
|
|
util_address_to_string(bss->addr));
|
|
|
|
|
|
|
|
/* Reset AP roam flag, at this point the roaming behaves the same */
|
|
|
|
station->ap_directed_roaming = false;
|
|
|
|
|
|
|
|
/* Can we use Fast Transition? */
|
2023-08-31 14:39:23 +02:00
|
|
|
if (station_can_fast_transition(hs, bss) && !no_ft)
|
2022-09-27 21:47:28 +02:00
|
|
|
return station_fast_transition(station, bss);
|
2018-09-05 06:26:54 +02:00
|
|
|
|
|
|
|
/* Non-FT transition */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FT not available, we can try preauthentication if available.
|
|
|
|
* 802.11-2012 section 11.5.9.2:
|
|
|
|
* "A STA shall not use preauthentication within the same mobility
|
|
|
|
* domain if AKM suite type 00-0F-AC:3 or 00-0F-AC:4 is used in
|
|
|
|
* the current association."
|
|
|
|
*/
|
|
|
|
if (security == SECURITY_8021X &&
|
|
|
|
scan_bss_get_rsn_info(station->connected_bss,
|
|
|
|
&cur_rsne) >= 0 &&
|
|
|
|
scan_bss_get_rsn_info(bss, &target_rsne) >= 0 &&
|
|
|
|
cur_rsne.preauthentication &&
|
|
|
|
target_rsne.preauthentication) {
|
|
|
|
/*
|
|
|
|
* Both the current and the target AP support
|
|
|
|
* pre-authentication and we're using 8021x authentication so
|
|
|
|
* attempt to pre-authenticate and reassociate afterwards.
|
|
|
|
* If the pre-authentication fails or times out we simply
|
|
|
|
* won't supply any PMKID when reassociating.
|
|
|
|
* Remain in the preparing_roam state.
|
|
|
|
*/
|
|
|
|
memcpy(station->preauth_bssid, bss->addr, ETH_ALEN);
|
|
|
|
|
|
|
|
if (netdev_preauthenticate(station->netdev, bss,
|
|
|
|
station_preauthenticate_cb,
|
|
|
|
station) >= 0)
|
2022-09-27 21:47:28 +02:00
|
|
|
return true;
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
new_hs = station_handshake_setup(station, connected, bss);
|
|
|
|
if (!new_hs) {
|
|
|
|
l_error("station_handshake_setup failed in reassociation");
|
2022-09-27 21:47:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (station_transition_reassociate(station, bss, new_hs) < 0) {
|
|
|
|
handshake_state_free(new_hs);
|
|
|
|
return false;
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2022-09-27 21:47:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_transition_start(struct station *station)
|
|
|
|
{
|
|
|
|
struct roam_bss *rbss;
|
|
|
|
bool roaming = false;
|
2023-10-20 14:50:21 +02:00
|
|
|
bool connected = (station->state == STATION_STATE_CONNECTED);
|
2022-09-27 21:47:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For each failed attempt pop the BSS leaving the head of the queue
|
|
|
|
* with the current roam candidate.
|
|
|
|
*/
|
|
|
|
while ((rbss = l_queue_peek_head(station->roam_bss_list))) {
|
|
|
|
struct scan_bss *bss = network_bss_find_by_addr(
|
|
|
|
station->connected_network, rbss->addr);
|
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
roaming = station_try_next_transition(station, bss,
|
|
|
|
rbss->ft_failed);
|
2022-09-27 21:47:28 +02:00
|
|
|
if (roaming)
|
|
|
|
break;
|
|
|
|
|
|
|
|
l_queue_pop_head(station->roam_bss_list);
|
|
|
|
l_free(rbss);
|
|
|
|
}
|
|
|
|
|
2023-05-02 20:59:41 +02:00
|
|
|
if (!roaming) {
|
2022-09-27 21:47:28 +02:00
|
|
|
station_roam_failed(station);
|
2023-05-02 20:59:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Netconfig could potentially be running and not completed yet. We
|
|
|
|
* still should roam in this case but need to restart netconfig once the
|
|
|
|
* roam is finished.
|
|
|
|
*/
|
2023-10-20 14:50:21 +02:00
|
|
|
if (station->netconfig && !connected) {
|
2023-05-02 20:59:41 +02:00
|
|
|
netconfig_reset(station->netconfig);
|
|
|
|
station->netconfig_after_roam = true;
|
|
|
|
}
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
static void station_roam_scan_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
station_roam_failed(station);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-19 23:26:50 +01:00
|
|
|
station_debug_event(station, "roam-scan-triggered");
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
/*
|
|
|
|
* Do not update the Scanning property as we won't be updating the
|
|
|
|
* list of networks.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2022-09-14 17:54:13 +02:00
|
|
|
static void station_update_roam_bss(struct station *station,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
struct network *network = station->connected_network;
|
2022-09-27 18:04:54 +02:00
|
|
|
struct scan_bss *old =
|
|
|
|
l_queue_remove_if(station->bss_list, bss_match, bss);
|
2022-09-14 17:54:13 +02:00
|
|
|
|
|
|
|
network_bss_update(network, bss);
|
|
|
|
l_queue_push_tail(station->bss_list, bss);
|
|
|
|
|
|
|
|
if (old)
|
|
|
|
scan_bss_free(old);
|
|
|
|
}
|
|
|
|
|
2019-03-14 21:42:11 +01:00
|
|
|
static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
|
2021-02-03 17:02:40 +01:00
|
|
|
const struct scan_freq_set *freqs,
|
2018-09-04 20:48:18 +02:00
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
struct network *network = station->connected_network;
|
|
|
|
struct handshake_state *hs = netdev_get_handshake(station->netdev);
|
2022-08-01 12:06:31 +02:00
|
|
|
struct scan_bss *current_bss = station->connected_bss;
|
2018-09-04 20:48:18 +02:00
|
|
|
struct scan_bss *bss;
|
2022-09-27 21:47:24 +02:00
|
|
|
double cur_bss_rank = 0.0;
|
2018-09-04 20:48:18 +02:00
|
|
|
static const double RANK_FT_FACTOR = 1.3;
|
|
|
|
uint16_t mdid;
|
|
|
|
enum security orig_security, security;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
station_roam_failed(station);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not call station_set_scan_results because this may have been
|
|
|
|
* a partial scan. We could at most update the current networks' BSS
|
|
|
|
* list in its station->networks entry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
orig_security = network_get_security(network);
|
|
|
|
|
|
|
|
if (hs->mde)
|
|
|
|
ie_parse_mobility_domain_from_data(hs->mde, hs->mde[1] + 2,
|
|
|
|
&mdid, NULL, NULL);
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
/*
|
|
|
|
* Find the current BSS rank, use the updated result if it exists. If
|
|
|
|
* this is an AP roam keep the current rank as zero to force the roam
|
|
|
|
* to occur.
|
|
|
|
*/
|
|
|
|
bss = l_queue_find(bss_list, bss_match_bssid, current_bss->addr);
|
|
|
|
if (bss && !station->ap_directed_roaming) {
|
|
|
|
cur_bss_rank = bss->rank;
|
|
|
|
|
|
|
|
if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid)
|
|
|
|
cur_bss_rank *= RANK_FT_FACTOR;
|
|
|
|
}
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
/*
|
|
|
|
* BSSes in the bss_list come already ranked with their initial
|
|
|
|
* association preference rank value. We only need to add preference
|
|
|
|
* for BSSes that are within the FT Mobility Domain so as to favor
|
|
|
|
* Fast Roaming, if it is supported.
|
|
|
|
*/
|
2022-08-01 12:06:31 +02:00
|
|
|
l_debug("Current BSS '%s' with SSID: %s",
|
|
|
|
util_address_to_string(current_bss->addr),
|
|
|
|
util_ssid_to_utf8(current_bss->ssid_len, current_bss->ssid));
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
while ((bss = l_queue_pop_head(bss_list))) {
|
|
|
|
double rank;
|
2022-08-01 12:06:31 +02:00
|
|
|
uint32_t kbps100 = DIV_ROUND_CLOSEST(bss->data_rate, 100000);
|
2022-09-27 21:47:24 +02:00
|
|
|
struct roam_bss *rbss;
|
2022-08-01 12:06:31 +02:00
|
|
|
|
|
|
|
l_debug("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u,"
|
|
|
|
" strength: %i, data_rate: %u.%u",
|
|
|
|
util_address_to_string(bss->addr),
|
|
|
|
util_ssid_to_utf8(bss->ssid_len, bss->ssid),
|
|
|
|
bss->frequency, bss->rank, bss->signal_strength,
|
|
|
|
kbps100 / 10, kbps100 % 10);
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
/* Skip the BSS we are connected to */
|
|
|
|
if (!memcmp(bss->addr, station->connected_bss->addr, 6))
|
2018-09-04 20:48:18 +02:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
/* Skip result if it is not part of the ESS */
|
|
|
|
if (bss->ssid_len != hs->ssid_len ||
|
|
|
|
memcmp(bss->ssid, hs->ssid, hs->ssid_len))
|
|
|
|
goto next;
|
|
|
|
|
2022-02-24 18:04:55 +01:00
|
|
|
if (scan_bss_get_security(bss, &security) < 0)
|
2021-08-12 21:07:21 +02:00
|
|
|
goto next;
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
if (security != orig_security)
|
|
|
|
goto next;
|
|
|
|
|
2021-07-27 20:59:52 +02:00
|
|
|
if (network_can_connect_bss(network, bss) < 0)
|
2018-09-04 20:48:18 +02:00
|
|
|
goto next;
|
|
|
|
|
2019-01-29 21:36:12 +01:00
|
|
|
if (blacklist_contains_bss(bss->addr))
|
|
|
|
goto next;
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
rank = bss->rank;
|
|
|
|
|
|
|
|
if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid)
|
|
|
|
rank *= RANK_FT_FACTOR;
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
if (rank <= cur_bss_rank)
|
|
|
|
goto next;
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
/*
|
|
|
|
* We need to update/add any potential roam candidate so
|
|
|
|
* station/network know it exists.
|
|
|
|
*/
|
|
|
|
station_update_roam_bss(station, bss);
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2023-08-31 14:39:23 +02:00
|
|
|
rbss = roam_bss_from_scan_bss(bss, rank);
|
2022-09-27 21:47:24 +02:00
|
|
|
|
|
|
|
l_queue_insert(station->roam_bss_list, rbss,
|
|
|
|
roam_bss_rank_compare, NULL);
|
|
|
|
|
|
|
|
continue;
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
next:
|
|
|
|
scan_bss_free(bss);
|
|
|
|
}
|
|
|
|
|
|
|
|
l_queue_destroy(bss_list, NULL);
|
|
|
|
|
|
|
|
/* See if we have anywhere to roam to */
|
2022-09-27 21:47:24 +02:00
|
|
|
if (l_queue_isempty(station->roam_bss_list)) {
|
2021-08-13 21:47:08 +02:00
|
|
|
station_debug_event(station, "no-roam-candidates");
|
2022-09-27 21:47:24 +02:00
|
|
|
goto fail;
|
2021-08-13 21:47:08 +02:00
|
|
|
}
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
station_transition_start(station);
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
fail:
|
2018-09-04 20:48:18 +02:00
|
|
|
station_roam_failed(station);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_roam_scan_destroy(void *userdata)
|
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
|
|
|
|
station->roam_scan_id = 0;
|
|
|
|
}
|
|
|
|
|
2020-06-30 19:27:56 +02:00
|
|
|
static int station_roam_scan(struct station *station,
|
2018-09-04 20:48:18 +02:00
|
|
|
struct scan_freq_set *freq_set)
|
|
|
|
{
|
|
|
|
struct scan_parameters params = { .freqs = freq_set, .flush = true };
|
2023-09-28 14:41:27 +02:00
|
|
|
_auto_(scan_freq_set_free) struct scan_freq_set *allowed =
|
|
|
|
station_get_allowed_freqs(station);
|
|
|
|
|
|
|
|
if (L_WARN_ON(!allowed))
|
|
|
|
return -ENOTSUP;
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2019-08-04 08:34:16 +02:00
|
|
|
l_debug("ifindex: %u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
2021-09-16 18:30:41 +02:00
|
|
|
if (station->connected_network) {
|
|
|
|
const char *ssid = network_get_ssid(station->connected_network);
|
2018-09-04 20:48:18 +02:00
|
|
|
/* Use direct probe request */
|
2021-09-16 18:30:41 +02:00
|
|
|
params.ssid = (const uint8_t *)ssid;
|
|
|
|
params.ssid_len = strlen(ssid);
|
|
|
|
}
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2023-09-28 14:41:27 +02:00
|
|
|
if (!freq_set) {
|
2020-06-30 19:34:41 +02:00
|
|
|
station->roam_scan_full = true;
|
2023-09-28 14:41:27 +02:00
|
|
|
params.freqs = allowed;
|
|
|
|
} else
|
|
|
|
scan_freq_set_constrain(freq_set, allowed);
|
|
|
|
|
|
|
|
if (L_WARN_ON(scan_freq_set_isempty(params.freqs)))
|
|
|
|
return -ENOTSUP;
|
2020-06-30 19:34:41 +02:00
|
|
|
|
2023-10-30 14:48:37 +01:00
|
|
|
station->last_roam_scan = l_time_now();
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
station->roam_scan_id =
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_active_full(netdev_get_wdev_id(station->netdev), ¶ms,
|
2018-09-04 20:48:18 +02:00
|
|
|
station_roam_scan_triggered,
|
|
|
|
station_roam_scan_notify, station,
|
|
|
|
station_roam_scan_destroy);
|
|
|
|
|
|
|
|
if (!station->roam_scan_id)
|
2020-06-30 19:27:56 +02:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 19:02:09 +02:00
|
|
|
static int station_roam_scan_known_freqs(struct station *station)
|
2019-09-17 18:49:53 +02:00
|
|
|
{
|
|
|
|
const struct network_info *info = network_get_info(
|
|
|
|
station->connected_network);
|
|
|
|
struct scan_freq_set *freqs = network_info_get_roam_frequencies(info,
|
|
|
|
station->connected_bss->frequency, 5);
|
2022-10-10 21:40:11 +02:00
|
|
|
int r = -ENODATA;
|
2019-09-17 18:49:53 +02:00
|
|
|
|
2020-06-30 19:02:09 +02:00
|
|
|
if (!freqs)
|
2022-10-10 21:40:11 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!wiphy_constrain_freq_set(station->wiphy, freqs))
|
|
|
|
goto free_set;
|
2019-09-17 18:49:53 +02:00
|
|
|
|
2020-06-30 19:27:56 +02:00
|
|
|
r = station_roam_scan(station, freqs);
|
2022-10-10 21:40:11 +02:00
|
|
|
|
|
|
|
free_set:
|
2019-09-17 18:49:53 +02:00
|
|
|
scan_freq_set_free(freqs);
|
2020-06-30 19:27:56 +02:00
|
|
|
return r;
|
2019-09-17 18:49:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 00:54:00 +01:00
|
|
|
static void station_neighbor_report_cb(struct netdev *netdev, int err,
|
|
|
|
const uint8_t *reports,
|
|
|
|
size_t reports_len, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct scan_freq_set *freq_set;
|
|
|
|
int r;
|
|
|
|
|
2021-09-24 00:57:26 +02:00
|
|
|
if (err == -ENODEV)
|
|
|
|
return;
|
|
|
|
|
2020-11-17 00:54:00 +01:00
|
|
|
l_debug("ifindex: %u, error: %d(%s)",
|
|
|
|
netdev_get_ifindex(station->netdev),
|
|
|
|
err, err < 0 ? strerror(-err) : "");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we're still attempting to roam -- if dbus Disconnect
|
|
|
|
* had been called in the meantime we just abort the attempt.
|
|
|
|
*/
|
|
|
|
if (!station->preparing_roam || err == -ENODEV)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!reports || err) {
|
|
|
|
r = station_roam_scan_known_freqs(station);
|
|
|
|
|
|
|
|
if (r == -ENODATA)
|
|
|
|
l_debug("no neighbor report results or known freqs");
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
station_roam_failed(station);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2020-11-17 00:54:00 +01:00
|
|
|
parse_neighbor_report(station, reports, reports_len, &freq_set);
|
|
|
|
|
|
|
|
r = station_roam_scan(station, freq_set);
|
|
|
|
|
|
|
|
if (freq_set)
|
|
|
|
scan_freq_set_free(freq_set);
|
2020-06-30 19:27:56 +02:00
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
station_roam_failed(station);
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-10 01:04:25 +02:00
|
|
|
static void station_start_roam(struct station *station)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
2020-06-30 19:02:09 +02:00
|
|
|
int r;
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
station->preparing_roam = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If current BSS supports Neighbor Reports, narrow the scan down
|
2020-11-17 00:54:00 +01:00
|
|
|
* to channels occupied by known neighbors in the ESS. If no neighbor
|
|
|
|
* report was obtained upon connection, request one now. This isn't
|
2018-09-04 20:48:18 +02:00
|
|
|
* 100% reliable as the neighbor lists are not required to be
|
|
|
|
* complete or current. It is likely still better than doing a
|
|
|
|
* full scan. 10.11.10.1: "A neighbor report may not be exhaustive
|
|
|
|
* either by choice, or due to the fact that there may be neighbor
|
|
|
|
* APs not known to the AP."
|
|
|
|
*/
|
2020-11-17 00:54:00 +01:00
|
|
|
if (station->roam_freqs) {
|
|
|
|
if (station_roam_scan(station, station->roam_freqs) == 0) {
|
|
|
|
l_debug("Using cached neighbor report for roam");
|
|
|
|
return;
|
|
|
|
}
|
2021-01-20 17:06:59 +01:00
|
|
|
} else if (station->connected_bss->cap_rm_neighbor_report) {
|
2020-11-17 00:54:00 +01:00
|
|
|
if (netdev_neighbor_report_req(station->netdev,
|
|
|
|
station_neighbor_report_cb) == 0) {
|
|
|
|
l_debug("Requesting neighbor report for roam");
|
2018-09-04 20:48:18 +02:00
|
|
|
return;
|
2020-11-17 00:54:00 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2020-06-30 19:02:09 +02:00
|
|
|
r = station_roam_scan_known_freqs(station);
|
|
|
|
if (r == -ENODATA)
|
2019-09-17 18:49:53 +02:00
|
|
|
l_debug("No neighbor report or known frequencies, roam failed");
|
2020-06-30 19:02:09 +02:00
|
|
|
|
|
|
|
if (r < 0)
|
2019-09-17 18:49:53 +02:00
|
|
|
station_roam_failed(station);
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2023-01-13 22:24:34 +01:00
|
|
|
static bool station_cannot_roam(struct station *station)
|
|
|
|
{
|
|
|
|
const struct l_settings *config = iwd_get_config();
|
|
|
|
bool disabled;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable roaming with hardware that can roam automatically. Note this
|
|
|
|
* is now required for recent kernels which have CQM event support on
|
|
|
|
* this type of hardware (e.g. brcmfmac).
|
|
|
|
*/
|
|
|
|
if (wiphy_supports_firmware_roam(station->wiphy))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!l_settings_get_bool(config, "Scan", "DisableRoamingScan",
|
|
|
|
&disabled))
|
|
|
|
disabled = false;
|
|
|
|
|
|
|
|
return disabled || station->preparing_roam ||
|
|
|
|
station->state == STATION_STATE_ROAMING ||
|
2023-01-13 22:24:35 +01:00
|
|
|
station->state == STATION_STATE_FT_ROAMING ||
|
|
|
|
station->ft_work.id;
|
2023-01-13 22:24:34 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 01:04:25 +02:00
|
|
|
static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_debug("%u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
|
|
|
l_timeout_remove(station->roam_trigger_timeout);
|
|
|
|
station->roam_trigger_timeout = NULL;
|
|
|
|
|
2023-01-13 22:24:34 +01:00
|
|
|
if (station_cannot_roam(station))
|
|
|
|
return;
|
|
|
|
|
2022-08-10 01:04:25 +02:00
|
|
|
station_start_roam(station);
|
|
|
|
}
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
static void station_roam_timeout_rearm(struct station *station, int seconds)
|
|
|
|
{
|
|
|
|
struct timespec now, min_timeout;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
|
|
|
|
min_timeout = now;
|
|
|
|
min_timeout.tv_sec += seconds;
|
|
|
|
|
|
|
|
if (station->roam_min_time.tv_sec < min_timeout.tv_sec ||
|
|
|
|
(station->roam_min_time.tv_sec == min_timeout.tv_sec &&
|
|
|
|
station->roam_min_time.tv_nsec < min_timeout.tv_nsec))
|
|
|
|
station->roam_min_time = min_timeout;
|
|
|
|
|
|
|
|
seconds = station->roam_min_time.tv_sec - now.tv_sec +
|
|
|
|
(station->roam_min_time.tv_nsec > now.tv_nsec ? 1 : 0);
|
|
|
|
|
|
|
|
station->roam_trigger_timeout =
|
|
|
|
l_timeout_create(seconds, station_roam_trigger_cb,
|
|
|
|
station, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define WNM_REQUEST_MODE_PREFERRED_CANDIDATE_LIST (1 << 0)
|
2022-09-28 18:36:34 +02:00
|
|
|
#define WNM_REQUEST_MODE_DISASSOCIATION_IMMINENT (1 << 2)
|
2018-09-04 20:48:18 +02:00
|
|
|
#define WNM_REQUEST_MODE_TERMINATION_IMMINENT (1 << 3)
|
|
|
|
#define WNM_REQUEST_MODE_ESS_DISASSOCIATION_IMMINENT (1 << 4)
|
|
|
|
|
2021-04-19 23:58:53 +02:00
|
|
|
static void station_ap_directed_roam(struct station *station,
|
|
|
|
const struct mmpdu_header *hdr,
|
|
|
|
const void *body, size_t body_len)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
|
|
|
uint32_t pos = 0;
|
|
|
|
uint8_t req_mode;
|
|
|
|
uint16_t dtimer;
|
|
|
|
uint8_t valid_interval;
|
|
|
|
|
2019-08-04 08:34:16 +02:00
|
|
|
l_debug("ifindex: %u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
2019-04-02 01:23:02 +02:00
|
|
|
if (station_cannot_roam(station))
|
2018-09-04 20:48:18 +02:00
|
|
|
return;
|
|
|
|
|
2022-09-28 18:36:32 +02:00
|
|
|
if (station->state != STATION_STATE_CONNECTED) {
|
|
|
|
l_debug("roam: unexpected AP directed roam -- ignore");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanitize the frame to check that it is from our current AP.
|
|
|
|
*
|
|
|
|
* 802.11-2020 Section 9.3.3.1 about Address2:
|
|
|
|
* "If the STA is an AP with dot11MultiBSSDImplemented set to false,
|
|
|
|
* then this address is the BSSID."
|
|
|
|
*
|
|
|
|
* Address3:
|
|
|
|
* "If the STA is an AP or PCP, the Address 3 field is the same as the
|
|
|
|
* Address 2 field."
|
|
|
|
*
|
|
|
|
* For now check that Address2 & Address3 is the same as the connected
|
|
|
|
* BSS address.
|
|
|
|
*/
|
|
|
|
if (memcmp(hdr->address_2, station->connected_bss, ETH_ALEN) ||
|
|
|
|
memcmp(hdr->address_2, hdr->address_3, ETH_ALEN)) {
|
|
|
|
l_debug("roam: AP directed roam not from our AP -- ignore");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
if (body_len < 7)
|
|
|
|
goto format_error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First two bytes are checked by the frame watch (WNM category and
|
|
|
|
* WNM action). The third is the dialog token which is not relevant
|
|
|
|
* because we did not send a BSS transition query -- so skip these
|
|
|
|
* first three bytes.
|
|
|
|
*/
|
|
|
|
pos += 3;
|
|
|
|
|
|
|
|
req_mode = l_get_u8(body + pos);
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: Disassociation timer and validity interval are currently not
|
|
|
|
* used since the BSS transition request is being handled immediately.
|
|
|
|
*/
|
|
|
|
dtimer = l_get_le16(body + pos);
|
|
|
|
pos += 2;
|
|
|
|
valid_interval = l_get_u8(body + pos);
|
|
|
|
pos++;
|
|
|
|
|
2022-04-05 18:36:39 +02:00
|
|
|
l_debug("roam: BSS transition received from AP: " MAC", "
|
2019-08-04 08:34:16 +02:00
|
|
|
"Disassociation Time: %u, "
|
2022-04-05 18:36:39 +02:00
|
|
|
"Validity interval: %u, Address3: " MAC,
|
|
|
|
MAC_STR(hdr->address_2),
|
|
|
|
dtimer, valid_interval,
|
|
|
|
MAC_STR(hdr->address_3));
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2022-09-28 18:36:34 +02:00
|
|
|
/*
|
|
|
|
* The ap_directed_roaming flag forces IWD to roam if there are any
|
|
|
|
* candidates, even if they are worse than the current BSS. This isn't
|
|
|
|
* always a good idea since we may be associated to the best BSS. Where
|
|
|
|
* this does matter is if the AP indicates its going down or will be
|
|
|
|
* disassociating us. If either of these bits are set, set the
|
|
|
|
* ap_directed_roaming flag. Otherwise still try roaming but don't
|
|
|
|
* treat it any different than a normal roam.
|
|
|
|
*/
|
|
|
|
if (req_mode & (WNM_REQUEST_MODE_DISASSOCIATION_IMMINENT |
|
|
|
|
WNM_REQUEST_MODE_TERMINATION_IMMINENT |
|
|
|
|
WNM_REQUEST_MODE_ESS_DISASSOCIATION_IMMINENT))
|
|
|
|
station->ap_directed_roaming = true;
|
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
if (req_mode & WNM_REQUEST_MODE_TERMINATION_IMMINENT) {
|
|
|
|
if (pos + 12 > body_len)
|
|
|
|
goto format_error;
|
|
|
|
|
|
|
|
pos += 12;
|
|
|
|
}
|
|
|
|
|
2022-01-11 17:51:11 +01:00
|
|
|
if (req_mode & WNM_REQUEST_MODE_ESS_DISASSOCIATION_IMMINENT) {
|
2018-09-04 20:48:18 +02:00
|
|
|
uint8_t url_len;
|
|
|
|
|
|
|
|
if (pos + 1 > body_len)
|
|
|
|
goto format_error;
|
|
|
|
|
|
|
|
url_len = l_get_u8(body + pos);
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
if (pos + url_len > body_len)
|
|
|
|
goto format_error;
|
|
|
|
|
|
|
|
pos += url_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
station->preparing_roam = true;
|
|
|
|
|
|
|
|
l_timeout_remove(station->roam_trigger_timeout);
|
|
|
|
station->roam_trigger_timeout = NULL;
|
|
|
|
|
2019-08-04 08:34:16 +02:00
|
|
|
if (req_mode & WNM_REQUEST_MODE_PREFERRED_CANDIDATE_LIST) {
|
2020-01-21 07:21:38 +01:00
|
|
|
l_debug("roam: AP sent a preferred candidate list");
|
2018-09-04 20:48:18 +02:00
|
|
|
station_neighbor_report_cb(station->netdev, 0, body + pos,
|
2022-01-11 17:51:11 +01:00
|
|
|
body_len - pos, station);
|
2019-08-04 08:34:16 +02:00
|
|
|
} else {
|
|
|
|
l_debug("roam: AP did not include a preferred candidate list");
|
2020-06-30 19:27:56 +02:00
|
|
|
if (station_roam_scan(station, NULL) < 0)
|
|
|
|
station_roam_failed(station);
|
2019-08-04 08:34:16 +02:00
|
|
|
}
|
2018-09-04 20:48:18 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
format_error:
|
|
|
|
l_debug("bad AP roam frame formatting");
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_low_rssi(struct station *station)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
|
|
|
if (station->signal_low)
|
|
|
|
return;
|
|
|
|
|
|
|
|
station->signal_low = true;
|
|
|
|
|
2019-04-02 01:23:02 +02:00
|
|
|
if (station_cannot_roam(station))
|
2018-09-04 20:48:18 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Set a 5-second initial timeout */
|
|
|
|
station_roam_timeout_rearm(station, 5);
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
static void station_ok_rssi(struct station *station)
|
2018-09-04 20:48:18 +02:00
|
|
|
{
|
|
|
|
l_timeout_remove(station->roam_trigger_timeout);
|
|
|
|
station->roam_trigger_timeout = NULL;
|
|
|
|
|
|
|
|
station->signal_low = false;
|
2021-01-22 14:37:00 +01:00
|
|
|
station->roam_min_time.tv_sec = 0;
|
2018-09-04 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 18:29:29 +01:00
|
|
|
static void station_event_roamed(struct station *station, struct scan_bss *new)
|
|
|
|
{
|
|
|
|
struct scan_bss *stale;
|
|
|
|
|
2021-03-15 20:15:29 +01:00
|
|
|
network_bss_update(station->connected_network, new);
|
|
|
|
|
2021-03-15 18:29:29 +01:00
|
|
|
/* Remove new BSS if it exists in past scan results */
|
2022-09-27 17:59:11 +02:00
|
|
|
stale = l_queue_remove_if(station->bss_list, bss_match, new);
|
2021-03-15 18:29:29 +01:00
|
|
|
if (stale)
|
|
|
|
scan_bss_free(stale);
|
|
|
|
|
|
|
|
station->connected_bss = new;
|
|
|
|
|
|
|
|
l_queue_insert(station->bss_list, new, scan_bss_rank_compare, NULL);
|
|
|
|
|
2021-03-29 21:07:41 +02:00
|
|
|
station_roamed(station);
|
2021-03-15 18:29:29 +01:00
|
|
|
}
|
|
|
|
|
2021-05-27 16:22:29 +02:00
|
|
|
static void station_event_channel_switched(struct station *station,
|
|
|
|
const uint32_t freq)
|
|
|
|
{
|
|
|
|
struct network *network = station->connected_network;
|
|
|
|
|
|
|
|
station->connected_bss->frequency = freq;
|
|
|
|
|
|
|
|
network_bss_update(network, station->connected_bss);
|
|
|
|
}
|
|
|
|
|
2019-01-29 21:36:12 +01:00
|
|
|
static bool station_try_next_bss(struct station *station)
|
|
|
|
{
|
|
|
|
struct scan_bss *next;
|
|
|
|
int ret;
|
|
|
|
|
2019-01-31 00:13:57 +01:00
|
|
|
next = network_bss_select(station->connected_network, false);
|
2019-01-29 21:36:12 +01:00
|
|
|
|
|
|
|
if (!next)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ret = __station_connect_network(station, station->connected_network,
|
2023-10-31 19:47:46 +01:00
|
|
|
next, station->state);
|
2019-01-29 21:36:12 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_debug("Attempting to connect to next BSS "MAC, MAC_STR(next->addr));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-08 20:22:59 +02:00
|
|
|
static bool station_retry_owe_default_group(struct station *station)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Shouldn't ever get here with classic open networks so its safe to
|
|
|
|
* assume if the security is none this is an OWE network.
|
|
|
|
*/
|
|
|
|
if (network_get_security(station->connected_network) != SECURITY_NONE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If we already forced group 19, allow the BSS to be blacklisted */
|
|
|
|
if (network_get_force_default_owe_group(station->connected_network))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_warn("Failed to connect to OWE BSS "MAC" possibly because the AP is "
|
|
|
|
"incorrectly deriving the PTK, this AP should be fixed. "
|
|
|
|
"Retrying with group 19 as a workaround",
|
|
|
|
MAC_STR(station->connected_bss->addr));
|
|
|
|
|
|
|
|
network_set_force_default_owe_group(station->connected_network);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-01 19:55:04 +01:00
|
|
|
static bool station_retry_with_reason(struct station *station,
|
|
|
|
uint16_t reason_code)
|
2019-01-29 21:36:12 +01:00
|
|
|
{
|
|
|
|
/*
|
2020-01-21 07:21:38 +01:00
|
|
|
* We don't want to cause a retry and blacklist if the password was
|
2019-01-29 21:36:12 +01:00
|
|
|
* incorrect. Otherwise we would just continue to fail.
|
|
|
|
*
|
2019-03-01 19:55:04 +01:00
|
|
|
* Other reason codes can be added here if its decided we want to
|
2019-01-29 21:36:12 +01:00
|
|
|
* fail in those cases.
|
|
|
|
*/
|
2022-08-08 20:22:59 +02:00
|
|
|
switch (reason_code) {
|
|
|
|
case MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID:
|
|
|
|
if (station_retry_owe_default_group(station))
|
|
|
|
goto try_next;
|
|
|
|
/* fall through */
|
|
|
|
case MMPDU_REASON_CODE_IEEE8021X_FAILED:
|
2019-03-01 19:55:04 +01:00
|
|
|
return false;
|
2022-08-08 20:22:59 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-01-29 21:36:12 +01:00
|
|
|
|
2019-03-01 19:55:04 +01:00
|
|
|
blacklist_add_bss(station->connected_bss->addr);
|
|
|
|
|
2022-08-08 20:22:59 +02:00
|
|
|
try_next:
|
2019-03-01 19:55:04 +01:00
|
|
|
return station_try_next_bss(station);
|
|
|
|
}
|
|
|
|
|
2020-07-31 03:31:27 +02:00
|
|
|
/* A bit more concise for trying to fit these into 80 characters */
|
2019-03-01 19:55:04 +01:00
|
|
|
#define IS_TEMPORARY_STATUS(code) \
|
|
|
|
((code) == MMPDU_STATUS_CODE_DENIED_UNSUFFICIENT_BANDWIDTH || \
|
|
|
|
(code) == MMPDU_STATUS_CODE_DENIED_POOR_CHAN_CONDITIONS || \
|
|
|
|
(code) == MMPDU_STATUS_CODE_REJECTED_WITH_SUGG_BSS_TRANS || \
|
|
|
|
(code) == MMPDU_STATUS_CODE_DENIED_NO_MORE_STAS)
|
|
|
|
|
|
|
|
static bool station_retry_with_status(struct station *station,
|
|
|
|
uint16_t status_code)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Certain Auth/Assoc failures should not cause a timeout blacklist.
|
|
|
|
* In these cases we want to only temporarily blacklist the BSS until
|
|
|
|
* the connection is complete.
|
|
|
|
*
|
|
|
|
* TODO: The WITH_SUGG_BSS_TRANS case should also include a neighbor
|
|
|
|
* report IE in the frame. This would allow us to target a
|
|
|
|
* specific BSS on our next attempt. There is currently no way to
|
|
|
|
* obtain that IE, but this should be done in the future.
|
|
|
|
*/
|
|
|
|
if (IS_TEMPORARY_STATUS(status_code))
|
|
|
|
network_blacklist_add(station->connected_network,
|
|
|
|
station->connected_bss);
|
|
|
|
else
|
|
|
|
blacklist_add_bss(station->connected_bss->addr);
|
|
|
|
|
|
|
|
return station_try_next_bss(station);
|
2019-01-29 21:36:12 +01:00
|
|
|
}
|
|
|
|
|
2021-05-24 23:02:58 +02:00
|
|
|
static void station_connect_ok(struct station *station)
|
2018-09-05 06:26:54 +02:00
|
|
|
{
|
2021-05-24 23:02:58 +02:00
|
|
|
struct handshake_state *hs = netdev_get_handshake(station->netdev);
|
2020-06-12 22:21:39 +02:00
|
|
|
|
2021-05-24 23:02:58 +02:00
|
|
|
l_debug("");
|
2018-09-05 06:26:54 +02:00
|
|
|
|
2021-05-24 23:02:58 +02:00
|
|
|
if (station->connect_pending) {
|
|
|
|
struct l_dbus_message *reply =
|
|
|
|
l_dbus_message_new_method_return(
|
|
|
|
station->connect_pending);
|
|
|
|
dbus_pending_reply(&station->connect_pending, reply);
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 00:54:00 +01:00
|
|
|
/*
|
|
|
|
* Get a neighbor report now so future roams can avoid waiting for
|
|
|
|
* a report at that time
|
|
|
|
*/
|
|
|
|
if (station->connected_bss->cap_rm_neighbor_report) {
|
|
|
|
if (netdev_neighbor_report_req(station->netdev,
|
|
|
|
station_early_neighbor_report_cb) < 0)
|
|
|
|
l_warn("Could not request neighbor report");
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
network_connected(station->connected_network);
|
2019-10-09 23:53:31 +02:00
|
|
|
|
2021-08-27 05:02:03 +02:00
|
|
|
if (station->netconfig) {
|
2021-08-27 05:02:05 +02:00
|
|
|
if (hs->fils_ip_req_ie && hs->fils_ip_resp_ie) {
|
|
|
|
struct ie_fils_ip_addr_response_info info;
|
|
|
|
struct ie_tlv_iter iter;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
ie_tlv_iter_init(&iter, hs->fils_ip_resp_ie,
|
|
|
|
hs->fils_ip_resp_ie[1] + 2);
|
2021-09-03 22:06:40 +02:00
|
|
|
if (!L_WARN_ON(unlikely(!ie_tlv_iter_next(&iter))))
|
|
|
|
r = ie_parse_fils_ip_addr_response(&iter,
|
|
|
|
&info);
|
|
|
|
else
|
|
|
|
r = -ENOMSG;
|
2021-08-27 05:02:05 +02:00
|
|
|
|
|
|
|
if (r != 0)
|
|
|
|
l_debug("Error parsing the FILS IP Address "
|
|
|
|
"Assignment response: %s (%i)",
|
|
|
|
strerror(-r), -r);
|
|
|
|
else if (info.response_pending &&
|
|
|
|
info.response_timeout)
|
|
|
|
l_debug("FILS IP Address Assignment response "
|
|
|
|
"is pending (unsupported)");
|
|
|
|
else if (info.response_pending)
|
|
|
|
l_debug("FILS IP Address Assignment failed");
|
|
|
|
else {
|
|
|
|
l_debug("FILS IP Address Assignment response "
|
|
|
|
"OK");
|
|
|
|
netconfig_handle_fils_ip_resp(
|
|
|
|
station->netconfig,
|
|
|
|
&info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 05:02:03 +02:00
|
|
|
if (L_WARN_ON(!netconfig_configure(station->netconfig,
|
|
|
|
station_netconfig_event_handler,
|
|
|
|
station)))
|
|
|
|
return;
|
|
|
|
} else
|
2019-10-09 23:53:31 +02:00
|
|
|
station_enter_state(station, STATION_STATE_CONNECTED);
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2021-05-24 23:02:58 +02:00
|
|
|
static void station_connect_cb(struct netdev *netdev, enum netdev_result result,
|
|
|
|
void *event_data, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
2021-05-25 01:04:05 +02:00
|
|
|
bool continue_autoconnect;
|
2021-05-24 23:02:58 +02:00
|
|
|
|
|
|
|
l_debug("%u, result: %d", netdev_get_ifindex(station->netdev), result);
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case NETDEV_RESULT_OK:
|
|
|
|
blacklist_remove_bss(station->connected_bss->addr);
|
|
|
|
station_connect_ok(station);
|
|
|
|
return;
|
|
|
|
case NETDEV_RESULT_HANDSHAKE_FAILED:
|
|
|
|
/* reason code in this case */
|
|
|
|
if (station_retry_with_reason(station, l_get_u16(event_data)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case NETDEV_RESULT_AUTHENTICATION_FAILED:
|
|
|
|
case NETDEV_RESULT_ASSOCIATION_FAILED:
|
|
|
|
/* status code in this case */
|
|
|
|
if (station_retry_with_status(station, l_get_u16(event_data)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (station->connect_pending) {
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
if (result == NETDEV_RESULT_ABORTED)
|
|
|
|
reply = dbus_error_aborted(station->connect_pending);
|
|
|
|
else
|
|
|
|
reply = dbus_error_failed(station->connect_pending);
|
|
|
|
|
|
|
|
dbus_pending_reply(&station->connect_pending, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == NETDEV_RESULT_ABORTED)
|
|
|
|
return;
|
|
|
|
|
2021-05-25 01:04:05 +02:00
|
|
|
continue_autoconnect = station->state == STATION_STATE_CONNECTING_AUTO;
|
|
|
|
|
|
|
|
if (station->state == STATION_STATE_CONNECTING) {
|
|
|
|
bool during_eapol = result == NETDEV_RESULT_HANDSHAKE_FAILED;
|
|
|
|
network_connect_failed(station->connected_network,
|
|
|
|
during_eapol);
|
|
|
|
}
|
|
|
|
|
|
|
|
station_reset_connection_state(station);
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTED);
|
|
|
|
|
|
|
|
if (continue_autoconnect) {
|
|
|
|
if (station_autoconnect_next(station) < 0) {
|
|
|
|
l_debug("Nothing left on autoconnect list");
|
|
|
|
station_enter_state(station,
|
|
|
|
STATION_STATE_AUTOCONNECT_FULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (station->autoconnect)
|
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_disconnect_event(struct station *station, void *event_data)
|
|
|
|
{
|
|
|
|
l_debug("%u", netdev_get_ifindex(station->netdev));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're connecting, AP deauthenticated us, most likely because
|
|
|
|
* we provided the wrong password or otherwise failed authentication
|
|
|
|
* during the handshaking phase. Treat this as a connection failure
|
|
|
|
*/
|
|
|
|
switch (station->state) {
|
|
|
|
case STATION_STATE_CONNECTING:
|
|
|
|
case STATION_STATE_CONNECTING_AUTO:
|
|
|
|
station_connect_cb(station->netdev,
|
|
|
|
NETDEV_RESULT_HANDSHAKE_FAILED,
|
|
|
|
event_data, station);
|
|
|
|
return;
|
|
|
|
case STATION_STATE_CONNECTED:
|
2022-09-28 20:33:50 +02:00
|
|
|
case STATION_STATE_FT_ROAMING:
|
|
|
|
case STATION_STATE_FW_ROAMING:
|
2021-05-25 01:04:05 +02:00
|
|
|
station_disassociated(station);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_warn("Unexpected disconnect event");
|
|
|
|
}
|
|
|
|
|
2023-10-30 14:48:37 +01:00
|
|
|
#define STATION_PKT_LOSS_THRESHOLD 10
|
|
|
|
#define LOSS_ROAM_RATE_LIMIT 2
|
2022-08-10 01:04:25 +02:00
|
|
|
|
|
|
|
static void station_packets_lost(struct station *station, uint32_t num_pkts)
|
|
|
|
{
|
2023-10-30 14:48:37 +01:00
|
|
|
uint64_t elapsed;
|
|
|
|
|
2022-08-10 01:04:25 +02:00
|
|
|
l_debug("Packets lost event: %u", num_pkts);
|
|
|
|
|
|
|
|
if (num_pkts < STATION_PKT_LOSS_THRESHOLD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (station_cannot_roam(station))
|
|
|
|
return;
|
|
|
|
|
|
|
|
station_debug_event(station, "packet-loss-roam");
|
|
|
|
|
2023-10-30 14:48:37 +01:00
|
|
|
elapsed = l_time_diff(station->last_roam_scan, l_time_now());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we just issued a roam scan, delay the roam to avoid constant
|
|
|
|
* scanning.
|
|
|
|
*/
|
|
|
|
if (LOSS_ROAM_RATE_LIMIT > l_time_to_secs(elapsed)) {
|
|
|
|
l_debug("Too many roam attempts in %u second timeframe, "
|
|
|
|
"delaying roam", LOSS_ROAM_RATE_LIMIT);
|
|
|
|
|
|
|
|
if (station->roam_trigger_timeout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
station_roam_timeout_rearm(station, LOSS_ROAM_RATE_LIMIT);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 01:04:25 +02:00
|
|
|
station_start_roam(station);
|
|
|
|
}
|
|
|
|
|
2021-05-25 01:04:05 +02:00
|
|
|
static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
|
|
|
|
void *event_data, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case NETDEV_EVENT_AUTHENTICATING:
|
|
|
|
l_debug("Authenticating");
|
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_ASSOCIATING:
|
|
|
|
l_debug("Associating");
|
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_DISCONNECT_BY_AP:
|
|
|
|
case NETDEV_EVENT_DISCONNECT_BY_SME:
|
|
|
|
station_disconnect_event(station, event_data);
|
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_RSSI_THRESHOLD_LOW:
|
|
|
|
station_low_rssi(station);
|
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_RSSI_THRESHOLD_HIGH:
|
|
|
|
station_ok_rssi(station);
|
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_RSSI_LEVEL_NOTIFY:
|
2022-05-23 08:20:52 +02:00
|
|
|
if (station->signal_agent)
|
|
|
|
station_signal_agent_notify(station);
|
2021-05-25 01:04:05 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_ROAMING:
|
2022-09-28 20:33:50 +02:00
|
|
|
station_enter_state(station, STATION_STATE_FW_ROAMING);
|
2021-05-25 01:04:05 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_ROAMED:
|
|
|
|
station_event_roamed(station, (struct scan_bss *) event_data);
|
|
|
|
break;
|
2021-05-27 16:22:29 +02:00
|
|
|
case NETDEV_EVENT_CHANNEL_SWITCHED:
|
|
|
|
station_event_channel_switched(station, l_get_u32(event_data));
|
|
|
|
break;
|
2022-08-10 01:04:25 +02:00
|
|
|
case NETDEV_EVENT_PACKET_LOSS_NOTIFY:
|
|
|
|
station_packets_lost(station, l_get_u32(event_data));
|
|
|
|
break;
|
2022-09-22 00:31:44 +02:00
|
|
|
case NETDEV_EVENT_FT_ROAMED:
|
2022-09-28 20:33:50 +02:00
|
|
|
if (L_WARN_ON(station->state != STATION_STATE_FT_ROAMING))
|
2022-09-27 21:47:27 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
station_roamed(station);
|
2022-09-22 00:31:44 +02:00
|
|
|
break;
|
2021-05-25 01:04:05 +02:00
|
|
|
}
|
2021-05-24 23:02:58 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
int __station_connect_network(struct station *station, struct network *network,
|
2023-10-31 19:47:46 +01:00
|
|
|
struct scan_bss *bss, enum station_state state)
|
2018-09-05 06:26:54 +02:00
|
|
|
{
|
|
|
|
struct handshake_state *hs;
|
|
|
|
int r;
|
|
|
|
|
2021-08-27 05:02:03 +02:00
|
|
|
if (station->netconfig && !netconfig_load_settings(
|
|
|
|
station->netconfig,
|
2021-09-27 18:21:40 +02:00
|
|
|
network_get_settings(network)))
|
2021-08-27 05:02:03 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
hs = station_handshake_setup(station, network, bss);
|
|
|
|
if (!hs)
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
2021-08-04 22:53:43 +02:00
|
|
|
r = netdev_connect(station->netdev, bss, hs, NULL, 0,
|
|
|
|
station_netdev_event,
|
2019-07-12 23:00:02 +02:00
|
|
|
station_connect_cb, station);
|
2018-09-05 06:26:54 +02:00
|
|
|
if (r < 0) {
|
|
|
|
handshake_state_free(hs);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-09-14 23:02:30 +02:00
|
|
|
l_debug("connecting to BSS "MAC, MAC_STR(bss->addr));
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
station->connected_bss = bss;
|
|
|
|
station->connected_network = network;
|
|
|
|
|
2023-10-31 19:47:46 +01:00
|
|
|
if (station->state != state)
|
|
|
|
station_enter_state(station, state);
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-24 03:12:57 +02:00
|
|
|
static void station_disconnect_onconnect_cb(struct netdev *netdev, bool success,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTED);
|
|
|
|
|
|
|
|
err = __station_connect_network(station,
|
|
|
|
station->connect_pending_network,
|
2023-10-31 19:47:46 +01:00
|
|
|
station->connect_pending_bss,
|
|
|
|
STATION_STATE_CONNECTING);
|
2019-07-24 03:12:57 +02:00
|
|
|
|
|
|
|
station->connect_pending_network = NULL;
|
|
|
|
station->connect_pending_bss = NULL;
|
|
|
|
|
|
|
|
if (err < 0) {
|
2021-02-01 18:42:27 +01:00
|
|
|
dbus_pending_reply(&station->connect_pending,
|
|
|
|
dbus_error_from_errno(err,
|
2019-07-24 03:12:57 +02:00
|
|
|
station->connect_pending));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_disconnect_onconnect(struct station *station,
|
|
|
|
struct network *network,
|
|
|
|
struct scan_bss *bss,
|
|
|
|
struct l_dbus_message *message)
|
|
|
|
{
|
|
|
|
if (netdev_disconnect(station->netdev, station_disconnect_onconnect_cb,
|
|
|
|
station) < 0) {
|
|
|
|
l_dbus_send(dbus_get_bus(),
|
|
|
|
dbus_error_from_errno(-EIO, message));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
station_reset_connection_state(station);
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTING);
|
|
|
|
|
|
|
|
station->connect_pending_network = network;
|
|
|
|
station->connect_pending_bss = bss;
|
|
|
|
|
|
|
|
station->connect_pending = l_dbus_message_ref(message);
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
void station_connect_network(struct station *station, struct network *network,
|
|
|
|
struct scan_bss *bss,
|
|
|
|
struct l_dbus_message *message)
|
|
|
|
{
|
2019-01-29 21:36:11 +01:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
int err;
|
2018-09-05 06:26:54 +02:00
|
|
|
|
2020-07-09 02:04:36 +02:00
|
|
|
/*
|
|
|
|
* If a hidden scan is not completed, station_is_busy would not
|
|
|
|
* indicate anything is going on so we need to cancel the scan and
|
|
|
|
* fail the connection now.
|
|
|
|
*/
|
|
|
|
if (station->hidden_network_scan_id) {
|
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
|
|
|
station->hidden_network_scan_id);
|
|
|
|
|
|
|
|
dbus_pending_reply(&station->hidden_pending,
|
|
|
|
dbus_error_failed(station->hidden_pending));
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:57:35 +01:00
|
|
|
if (station->quick_scan_id) {
|
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
|
|
|
station->quick_scan_id);
|
|
|
|
station->quick_scan_id = 0;
|
2021-03-29 17:35:31 +02:00
|
|
|
station_property_set_scanning(station, false);
|
2021-01-26 20:57:35 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 21:36:11 +01:00
|
|
|
if (station_is_busy(station)) {
|
2019-07-24 03:12:57 +02:00
|
|
|
station_disconnect_onconnect(station, network, bss, message);
|
|
|
|
|
|
|
|
return;
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2023-10-31 19:47:46 +01:00
|
|
|
err = __station_connect_network(station, network, bss,
|
|
|
|
STATION_STATE_CONNECTING);
|
2019-01-29 21:36:11 +01:00
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2018-09-05 06:26:54 +02:00
|
|
|
station->connect_pending = l_dbus_message_ref(message);
|
2021-08-13 00:24:58 +02:00
|
|
|
|
|
|
|
station_set_autoconnect(station, true);
|
2019-01-29 21:36:11 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
l_dbus_send(dbus, dbus_error_from_errno(err, message));
|
2018-09-05 06:26:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 02:05:20 +02:00
|
|
|
static void station_hidden_network_scan_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
return;
|
|
|
|
|
2020-06-10 03:22:19 +02:00
|
|
|
dbus_pending_reply(&station->hidden_pending,
|
|
|
|
dbus_error_failed(station->hidden_pending));
|
2018-09-05 02:05:20 +02:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:42:11 +01:00
|
|
|
static bool station_hidden_network_scan_results(int err,
|
2021-02-03 17:02:40 +01:00
|
|
|
struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
2018-09-05 02:05:20 +02:00
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
struct network *network_psk;
|
|
|
|
struct network *network_open;
|
|
|
|
const char *ssid;
|
|
|
|
uint8_t ssid_len;
|
|
|
|
struct l_dbus_message *msg;
|
2021-02-01 18:22:42 +01:00
|
|
|
struct l_dbus_message *error;
|
2018-09-05 02:05:20 +02:00
|
|
|
struct scan_bss *bss;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2020-06-10 03:22:19 +02:00
|
|
|
msg = station->hidden_pending;
|
|
|
|
station->hidden_pending = NULL;
|
2020-07-09 02:04:36 +02:00
|
|
|
/* Zero this now so station_connect_network knows the scan is done */
|
|
|
|
station->hidden_network_scan_id = 0;
|
2018-09-05 02:05:20 +02:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
dbus_pending_reply(&msg, dbus_error_failed(msg));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(msg, "s", &ssid)) {
|
|
|
|
dbus_pending_reply(&msg, dbus_error_invalid_args(msg));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssid_len = strlen(ssid);
|
|
|
|
|
|
|
|
while ((bss = l_queue_pop_head(bss_list))) {
|
|
|
|
if (bss->ssid_len != ssid_len ||
|
|
|
|
memcmp(bss->ssid, ssid, ssid_len))
|
|
|
|
goto next;
|
|
|
|
|
2021-09-22 20:26:51 +02:00
|
|
|
if (bss->owe_trans)
|
2021-09-16 22:49:25 +02:00
|
|
|
goto next;
|
|
|
|
|
2021-02-01 22:30:15 +01:00
|
|
|
/*
|
|
|
|
* Override time_stamp so that this entry is removed on
|
|
|
|
* the next scan
|
|
|
|
*/
|
|
|
|
bss->time_stamp = 0;
|
|
|
|
|
2018-09-05 02:05:20 +02:00
|
|
|
if (station_add_seen_bss(station, bss)) {
|
|
|
|
l_queue_push_tail(station->bss_list, bss);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
scan_bss_free(bss);
|
|
|
|
}
|
|
|
|
|
|
|
|
l_queue_destroy(bss_list, NULL);
|
|
|
|
|
|
|
|
network_psk = station_network_find(station, ssid, SECURITY_PSK);
|
|
|
|
network_open = station_network_find(station, ssid, SECURITY_NONE);
|
|
|
|
|
|
|
|
if (!network_psk && !network_open) {
|
|
|
|
dbus_pending_reply(&msg, dbus_error_not_found(msg));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (network_psk && network_open) {
|
2022-04-05 10:21:33 +02:00
|
|
|
station_hide_network(station, network_psk);
|
|
|
|
station_hide_network(station, network_open);
|
2018-09-05 02:05:20 +02:00
|
|
|
dbus_pending_reply(&msg, dbus_error_service_set_overlap(msg));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-01 18:22:42 +01:00
|
|
|
error = network_connect_new_hidden_network(network_psk ?: network_open,
|
|
|
|
msg);
|
2018-09-05 02:05:20 +02:00
|
|
|
|
2021-02-01 18:22:42 +01:00
|
|
|
if (error)
|
|
|
|
dbus_pending_reply(&msg, error);
|
|
|
|
else
|
|
|
|
l_dbus_message_unref(msg);
|
2018-09-05 02:05:20 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-06 02:55:55 +02:00
|
|
|
static void station_hidden_network_scan_destroy(void *userdata)
|
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
|
|
|
|
station->hidden_network_scan_id = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:37:14 +02:00
|
|
|
static struct l_dbus_message *station_dbus_connect_hidden_network(
|
2018-09-05 02:05:20 +02:00
|
|
|
struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
2019-07-08 16:02:59 +02:00
|
|
|
uint64_t id = netdev_get_wdev_id(station->netdev);
|
2018-09-05 02:05:20 +02:00
|
|
|
struct scan_parameters params = {
|
|
|
|
.flush = true,
|
2021-02-02 16:54:34 +01:00
|
|
|
.randomize_mac_addr_hint = false,
|
2018-09-05 02:05:20 +02:00
|
|
|
};
|
|
|
|
const char *ssid;
|
2021-02-01 18:33:12 +01:00
|
|
|
struct network *network;
|
2023-09-28 14:41:27 +02:00
|
|
|
_auto_(scan_freq_set_free) struct scan_freq_set *allowed = NULL;
|
2018-09-05 02:05:20 +02:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2021-02-01 17:17:12 +01:00
|
|
|
if (station->hidden_pending)
|
2018-09-05 02:05:20 +02:00
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "s", &ssid))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (strlen(ssid) > 32)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (known_networks_find(ssid, SECURITY_PSK) ||
|
|
|
|
known_networks_find(ssid, SECURITY_NONE))
|
|
|
|
return dbus_error_already_provisioned(message);
|
|
|
|
|
2021-02-01 18:33:12 +01:00
|
|
|
network = station_network_find(station, ssid, SECURITY_PSK);
|
|
|
|
if (!network)
|
|
|
|
network = station_network_find(station, ssid, SECURITY_NONE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This checks for a corner case where the hidden network was already
|
|
|
|
* found and is in our scan results, but the initial connection failed.
|
|
|
|
* For example, the password was given incorrectly. In this case the
|
|
|
|
* entry will also be found on the hidden bss list.
|
|
|
|
*/
|
|
|
|
if (network) {
|
|
|
|
const struct l_queue_entry *entry =
|
|
|
|
l_queue_get_entries(station->hidden_bss_list_sorted);
|
|
|
|
struct scan_bss *target = network_bss_select(network, true);
|
|
|
|
|
2021-09-16 22:49:25 +02:00
|
|
|
/* Treat OWE transition networks special */
|
2021-09-22 20:26:51 +02:00
|
|
|
if (target->owe_trans)
|
2021-09-16 22:49:25 +02:00
|
|
|
goto not_hidden;
|
|
|
|
|
2021-02-01 18:33:12 +01:00
|
|
|
for (; entry; entry = entry->next) {
|
|
|
|
struct scan_bss *bss = entry->data;
|
|
|
|
|
|
|
|
if (!scan_bss_addr_eq(target, bss))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We can skip the scan and try to connect right away */
|
|
|
|
return network_connect_new_hidden_network(network,
|
|
|
|
message);
|
|
|
|
}
|
2021-02-03 16:12:08 +01:00
|
|
|
|
2021-09-16 22:49:25 +02:00
|
|
|
not_hidden:
|
2021-02-03 16:12:08 +01:00
|
|
|
return dbus_error_not_hidden(message);
|
2021-02-01 18:33:12 +01:00
|
|
|
}
|
2018-09-05 02:05:20 +02:00
|
|
|
|
2023-09-28 14:41:27 +02:00
|
|
|
allowed = station_get_allowed_freqs(station);
|
|
|
|
if (L_WARN_ON(!allowed))
|
|
|
|
return dbus_error_not_supported(message);
|
|
|
|
|
|
|
|
params.freqs = allowed;
|
2021-09-16 18:30:41 +02:00
|
|
|
params.ssid = (const uint8_t *)ssid;
|
|
|
|
params.ssid_len = strlen(ssid);
|
2018-09-05 02:05:20 +02:00
|
|
|
|
2021-02-02 16:54:34 +01:00
|
|
|
/* HW cannot randomize our MAC if connected */
|
|
|
|
if (!station->connected_bss)
|
|
|
|
params.randomize_mac_addr_hint = true;
|
|
|
|
|
2019-07-08 16:02:59 +02:00
|
|
|
station->hidden_network_scan_id = scan_active_full(id, ¶ms,
|
2018-09-05 02:05:20 +02:00
|
|
|
station_hidden_network_scan_triggered,
|
|
|
|
station_hidden_network_scan_results,
|
2018-10-06 02:55:55 +02:00
|
|
|
station, station_hidden_network_scan_destroy);
|
|
|
|
if (!station->hidden_network_scan_id)
|
2018-09-05 02:05:20 +02:00
|
|
|
return dbus_error_failed(message);
|
|
|
|
|
2020-06-10 03:22:19 +02:00
|
|
|
station->hidden_pending = l_dbus_message_ref(message);
|
2018-09-05 02:05:20 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-25 20:23:12 +01:00
|
|
|
static void station_disconnect_reconnect_cb(struct netdev *netdev, bool success,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
2019-01-29 21:36:11 +01:00
|
|
|
if (__station_connect_network(station, station->connected_network,
|
2023-10-31 19:47:46 +01:00
|
|
|
station->connected_bss,
|
|
|
|
STATION_STATE_ROAMING) < 0)
|
2019-01-29 21:36:11 +01:00
|
|
|
station_disassociated(station);
|
2019-01-25 20:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void station_reconnect(struct station *station)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Rather than doing 4 or so state changes, lets just go into
|
|
|
|
* roaming for the duration of this reconnect.
|
|
|
|
*/
|
|
|
|
station_enter_state(station, STATION_STATE_ROAMING);
|
|
|
|
|
|
|
|
netdev_disconnect(station->netdev, station_disconnect_reconnect_cb,
|
|
|
|
station);
|
|
|
|
}
|
|
|
|
|
2018-09-05 02:54:48 +02:00
|
|
|
static void station_disconnect_cb(struct netdev *netdev, bool success,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_debug("%u, success: %d",
|
|
|
|
netdev_get_ifindex(station->netdev), success);
|
|
|
|
|
|
|
|
if (station->disconnect_pending) {
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
reply = l_dbus_message_new_method_return(
|
|
|
|
station->disconnect_pending);
|
|
|
|
l_dbus_message_set_arguments(reply, "");
|
|
|
|
} else
|
|
|
|
reply = dbus_error_failed(station->disconnect_pending);
|
|
|
|
|
|
|
|
dbus_pending_reply(&station->disconnect_pending, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTED);
|
|
|
|
|
|
|
|
if (station->autoconnect)
|
2019-03-22 22:17:45 +01:00
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
|
2018-09-05 02:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int station_disconnect(struct station *station)
|
|
|
|
{
|
|
|
|
if (station->state == STATION_STATE_DISCONNECTING)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (!station->connected_bss)
|
|
|
|
return -ENOTCONN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the disconnect somehow fails we won't know if we're still
|
|
|
|
* connected so we may as well indicate now that we're no longer
|
|
|
|
* connected.
|
|
|
|
*/
|
|
|
|
station_reset_connection_state(station);
|
|
|
|
|
|
|
|
station_enter_state(station, STATION_STATE_DISCONNECTING);
|
|
|
|
|
2020-07-15 23:29:17 +02:00
|
|
|
if (netdev_disconnect(station->netdev,
|
|
|
|
station_disconnect_cb, station) < 0)
|
|
|
|
return -EIO;
|
|
|
|
|
2018-09-05 02:54:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-15 04:17:57 +02:00
|
|
|
static struct l_dbus_message *station_dbus_disconnect(struct l_dbus *dbus,
|
2018-09-05 02:58:37 +02:00
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disconnect was triggered by the user, don't autoconnect. Wait for
|
|
|
|
* the user's explicit instructions to scan and connect to the network
|
|
|
|
*/
|
|
|
|
station_set_autoconnect(station, false);
|
|
|
|
|
2020-10-08 10:49:07 +02:00
|
|
|
if (station->hidden_network_scan_id) {
|
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
|
|
|
station->hidden_network_scan_id);
|
|
|
|
dbus_pending_reply(&station->hidden_pending,
|
|
|
|
dbus_error_aborted(station->hidden_pending));
|
|
|
|
|
|
|
|
return l_dbus_message_new_method_return(message);
|
|
|
|
}
|
|
|
|
|
2019-03-22 22:17:45 +01:00
|
|
|
if (!station_is_busy(station))
|
2018-09-05 02:58:37 +02:00
|
|
|
return l_dbus_message_new_method_return(message);
|
|
|
|
|
|
|
|
result = station_disconnect(station);
|
|
|
|
if (result < 0)
|
|
|
|
return dbus_error_from_errno(result, message);
|
|
|
|
|
|
|
|
station->disconnect_pending = l_dbus_message_ref(message);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-15 04:49:13 +02:00
|
|
|
static struct l_dbus_message *station_dbus_get_networks(struct l_dbus *dbus,
|
2018-09-05 04:07:26 +02:00
|
|
|
struct l_dbus_message *message,
|
2018-09-15 04:49:13 +02:00
|
|
|
void *user_data)
|
2018-09-05 04:07:26 +02:00
|
|
|
{
|
2018-09-15 04:49:13 +02:00
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply =
|
|
|
|
l_dbus_message_new_method_return(message);
|
|
|
|
struct l_dbus_message_builder *builder =
|
|
|
|
l_dbus_message_builder_new(reply);
|
2018-09-05 04:07:26 +02:00
|
|
|
struct l_queue *sorted = station->networks_sorted;
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
|
2018-09-15 04:49:13 +02:00
|
|
|
l_dbus_message_builder_enter_array(builder, "(on)");
|
2018-09-05 04:07:26 +02:00
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(sorted); entry; entry = entry->next) {
|
|
|
|
const struct network *network = entry->data;
|
|
|
|
int16_t signal_strength = network_get_signal_strength(network);
|
|
|
|
|
2018-09-15 04:49:13 +02:00
|
|
|
l_dbus_message_builder_enter_struct(builder, "on");
|
2018-09-05 04:07:26 +02:00
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
|
|
|
network_get_path(network));
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'n',
|
|
|
|
&signal_strength);
|
|
|
|
l_dbus_message_builder_leave_struct(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
|
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2018-11-09 20:57:08 +01:00
|
|
|
static struct l_dbus_message *station_dbus_get_hidden_access_points(
|
2018-11-09 01:25:22 +01:00
|
|
|
struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply =
|
|
|
|
l_dbus_message_new_method_return(message);
|
|
|
|
struct l_dbus_message_builder *builder =
|
|
|
|
l_dbus_message_builder_new(reply);
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_array(builder, "(sns)");
|
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(station->hidden_bss_list_sorted);
|
|
|
|
entry; entry = entry->next) {
|
|
|
|
struct scan_bss *bss = entry->data;
|
|
|
|
int16_t signal_strength = bss->signal_strength;
|
|
|
|
enum security security;
|
|
|
|
|
2022-02-24 18:04:55 +01:00
|
|
|
if (scan_bss_get_security(bss, &security) < 0)
|
2021-08-12 21:07:21 +02:00
|
|
|
continue;
|
2018-11-09 01:25:22 +01:00
|
|
|
|
|
|
|
l_dbus_message_builder_enter_struct(builder, "sns");
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's',
|
|
|
|
util_address_to_string(bss->addr));
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'n',
|
|
|
|
&signal_strength);
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's',
|
|
|
|
security_to_str(security));
|
|
|
|
l_dbus_message_builder_leave_struct(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
|
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:00:01 +02:00
|
|
|
static void station_dbus_scan_done(struct station *station,
|
|
|
|
bool try_autoconnect)
|
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 02:28:58 +01:00
|
|
|
{
|
|
|
|
station->dbus_scan_id = 0;
|
|
|
|
station_property_set_scanning(station, false);
|
2021-09-16 21:00:01 +02:00
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
station_process_owe_transition_networks(station);
|
|
|
|
|
2021-09-16 21:00:01 +02:00
|
|
|
if (try_autoconnect) {
|
|
|
|
station->autoconnect_can_start = true;
|
|
|
|
station_autoconnect_start(station);
|
|
|
|
}
|
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 02:28:58 +01:00
|
|
|
}
|
|
|
|
|
2018-09-05 00:32:18 +02:00
|
|
|
static void station_dbus_scan_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
l_debug("station_scan_triggered: %i", err);
|
|
|
|
|
|
|
|
if (err < 0) {
|
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 02:28:58 +01:00
|
|
|
if (station->scan_pending) {
|
|
|
|
reply = dbus_error_from_errno(err,
|
|
|
|
station->scan_pending);
|
|
|
|
dbus_pending_reply(&station->scan_pending, reply);
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:00:01 +02:00
|
|
|
station_dbus_scan_done(station, true);
|
2018-09-05 00:32:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 02:28:58 +01:00
|
|
|
l_debug("Scan triggered for %s subset %i",
|
|
|
|
netdev_get_name(station->netdev),
|
|
|
|
station->dbus_scan_subset_idx);
|
2018-09-05 00:32:18 +02:00
|
|
|
|
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 02:28:58 +01:00
|
|
|
if (station->scan_pending) {
|
|
|
|
reply = l_dbus_message_new_method_return(station->scan_pending);
|
|
|
|
l_dbus_message_set_arguments(reply, "");
|
|
|
|
dbus_pending_reply(&station->scan_pending, reply);
|
|
|
|
}
|
2018-09-05 00:32:18 +02:00
|
|
|
|
2019-03-22 22:17:42 +01:00
|
|
|
station_property_set_scanning(station, true);
|
2018-09-05 00:32:18 +02:00
|
|
|
}
|
|
|
|
|
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 02:28:58 +01:00
|
|
|
static bool station_dbus_scan_subset(struct station *station);
|
|
|
|
|
2021-02-03 17:02:40 +01:00
|
|
|
static bool station_dbus_scan_results(int err, struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
2019-03-22 22:17:41 +01:00
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
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 02:28:58 +01:00
|
|
|
unsigned int next_idx = station->dbus_scan_subset_idx + 1;
|
|
|
|
bool last_subset;
|
2019-03-22 22:17:41 +01:00
|
|
|
|
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 02:28:58 +01:00
|
|
|
if (err) {
|
2021-09-16 21:00:01 +02:00
|
|
|
station_dbus_scan_done(station, true);
|
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 02:28:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_subset = next_idx >= L_ARRAY_SIZE(station->scan_freqs_order) ||
|
|
|
|
station->scan_freqs_order[next_idx] == NULL;
|
|
|
|
station->dbus_scan_subset_idx = next_idx;
|
|
|
|
|
2021-09-16 21:00:01 +02:00
|
|
|
station_set_scan_results(station, bss_list, freqs, false);
|
|
|
|
|
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 02:28:58 +01:00
|
|
|
if (last_subset || !station_dbus_scan_subset(station))
|
2021-09-16 21:00:01 +02:00
|
|
|
station_dbus_scan_done(station, true);
|
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 02:28:58 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_dbus_scan_subset(struct station *station)
|
|
|
|
{
|
|
|
|
unsigned int idx = station->dbus_scan_subset_idx;
|
|
|
|
|
|
|
|
station->dbus_scan_id = station_scan_trigger(station,
|
|
|
|
station->scan_freqs_order[idx],
|
|
|
|
station_dbus_scan_triggered,
|
|
|
|
station_dbus_scan_results,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return station->dbus_scan_id != 0;
|
2019-03-22 22:17:41 +01:00
|
|
|
}
|
|
|
|
|
2018-09-15 04:21:47 +02:00
|
|
|
static struct l_dbus_message *station_dbus_scan(struct l_dbus *dbus,
|
2018-09-05 00:32:18 +02:00
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_debug("Scan called from DBus");
|
|
|
|
|
2019-03-22 22:17:43 +01:00
|
|
|
if (station->dbus_scan_id)
|
2018-09-05 00:32:18 +02:00
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
2021-05-24 23:09:28 +02:00
|
|
|
if (station->state == STATION_STATE_CONNECTING ||
|
|
|
|
station->state == STATION_STATE_CONNECTING_AUTO)
|
2019-11-14 19:59:59 +01:00
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
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 02:28:58 +01:00
|
|
|
station->dbus_scan_subset_idx = 0;
|
2018-09-05 00:32:18 +02:00
|
|
|
|
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 02:28:58 +01:00
|
|
|
if (!station_dbus_scan_subset(station))
|
2018-10-06 02:55:55 +02:00
|
|
|
return dbus_error_failed(message);
|
|
|
|
|
2018-09-18 20:56:15 +02:00
|
|
|
station->scan_pending = l_dbus_message_ref(message);
|
|
|
|
|
2018-09-05 00:32:18 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-05 05:46:12 +02:00
|
|
|
struct signal_agent {
|
|
|
|
char *owner;
|
|
|
|
char *path;
|
|
|
|
unsigned int disconnect_watch;
|
|
|
|
};
|
|
|
|
|
2022-05-23 08:20:52 +02:00
|
|
|
static void station_signal_agent_notify(struct station *station)
|
2018-09-05 05:46:12 +02:00
|
|
|
{
|
2022-05-23 08:20:52 +02:00
|
|
|
struct signal_agent *agent = station->signal_agent;
|
|
|
|
struct netdev *netdev = station->netdev;
|
|
|
|
const char *device_path = netdev_get_path(netdev);
|
|
|
|
uint8_t level = netdev_get_rssi_level_idx(netdev);
|
|
|
|
|
2018-09-05 05:46:12 +02:00
|
|
|
struct l_dbus_message *msg;
|
|
|
|
|
|
|
|
msg = l_dbus_message_new_method_call(dbus_get_bus(),
|
|
|
|
agent->owner, agent->path,
|
|
|
|
IWD_SIGNAL_AGENT_INTERFACE,
|
|
|
|
"Changed");
|
2019-03-01 00:41:51 +01:00
|
|
|
l_dbus_message_set_arguments(msg, "oy", device_path, level);
|
2018-09-05 05:46:12 +02:00
|
|
|
l_dbus_message_set_no_reply(msg, true);
|
|
|
|
|
|
|
|
l_dbus_send(dbus_get_bus(), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_signal_agent_release(struct signal_agent *agent,
|
|
|
|
const char *device_path)
|
|
|
|
{
|
|
|
|
struct l_dbus_message *msg;
|
|
|
|
|
|
|
|
msg = l_dbus_message_new_method_call(dbus_get_bus(),
|
|
|
|
agent->owner, agent->path,
|
|
|
|
IWD_SIGNAL_AGENT_INTERFACE,
|
|
|
|
"Release");
|
|
|
|
l_dbus_message_set_arguments(msg, "o", device_path);
|
|
|
|
l_dbus_message_set_no_reply(msg, true);
|
|
|
|
|
|
|
|
l_dbus_send(dbus_get_bus(), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void signal_agent_free(void *data)
|
|
|
|
{
|
|
|
|
struct signal_agent *agent = data;
|
|
|
|
|
|
|
|
l_free(agent->owner);
|
|
|
|
l_free(agent->path);
|
|
|
|
l_dbus_remove_watch(dbus_get_bus(), agent->disconnect_watch);
|
|
|
|
l_free(agent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void signal_agent_disconnect(struct l_dbus *dbus, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
l_debug("signal_agent %s disconnected", station->signal_agent->owner);
|
|
|
|
|
|
|
|
l_idle_oneshot(signal_agent_free, station->signal_agent, NULL);
|
|
|
|
station->signal_agent = NULL;
|
|
|
|
|
|
|
|
netdev_set_rssi_report_levels(station->netdev, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *station_dbus_signal_agent_register(
|
|
|
|
struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
const char *path, *sender;
|
2022-05-20 23:53:23 +02:00
|
|
|
struct l_dbus_message *reply;
|
2018-09-05 05:46:12 +02:00
|
|
|
struct l_dbus_message_iter level_iter;
|
|
|
|
int8_t levels[16];
|
|
|
|
int err;
|
|
|
|
int16_t val;
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
if (station->signal_agent)
|
|
|
|
return dbus_error_already_exists(message);
|
|
|
|
|
|
|
|
l_debug("signal agent register called");
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "oan", &path, &level_iter))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
while (l_dbus_message_iter_next_entry(&level_iter, &val)) {
|
|
|
|
if (count >= L_ARRAY_SIZE(levels) || val > 127 || val < -127)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
levels[count++] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count < 1)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
err = netdev_set_rssi_report_levels(station->netdev, levels, count);
|
|
|
|
if (err == -ENOTSUP)
|
|
|
|
return dbus_error_not_supported(message);
|
|
|
|
else if (err < 0)
|
|
|
|
return dbus_error_failed(message);
|
|
|
|
|
|
|
|
sender = l_dbus_message_get_sender(message);
|
|
|
|
|
|
|
|
station->signal_agent = l_new(struct signal_agent, 1);
|
|
|
|
station->signal_agent->owner = l_strdup(sender);
|
|
|
|
station->signal_agent->path = l_strdup(path);
|
|
|
|
station->signal_agent->disconnect_watch =
|
|
|
|
l_dbus_add_disconnect_watch(dbus, sender,
|
|
|
|
signal_agent_disconnect,
|
|
|
|
station, NULL);
|
|
|
|
|
|
|
|
l_debug("agent %s path %s", sender, path);
|
|
|
|
|
2022-05-20 23:53:23 +02:00
|
|
|
reply = l_dbus_message_new_method_return(message);
|
|
|
|
l_dbus_send(dbus, reply);
|
|
|
|
|
2022-05-23 08:20:52 +02:00
|
|
|
if (station->connected_network)
|
|
|
|
station_signal_agent_notify(station);
|
2018-09-05 05:46:12 +02:00
|
|
|
|
2022-05-20 23:53:23 +02:00
|
|
|
return NULL;
|
2018-09-05 05:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *station_dbus_signal_agent_unregister(
|
|
|
|
struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
const char *path, *sender;
|
|
|
|
|
|
|
|
if (!station->signal_agent)
|
|
|
|
return dbus_error_failed(message);
|
|
|
|
|
|
|
|
l_debug("signal agent unregister");
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "o", &path))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (strcmp(station->signal_agent->path, path))
|
|
|
|
return dbus_error_not_found(message);
|
|
|
|
|
|
|
|
sender = l_dbus_message_get_sender(message);
|
|
|
|
|
|
|
|
if (strcmp(station->signal_agent->owner, sender))
|
|
|
|
return dbus_error_not_found(message);
|
|
|
|
|
|
|
|
signal_agent_free(station->signal_agent);
|
|
|
|
station->signal_agent = NULL;
|
|
|
|
|
|
|
|
netdev_set_rssi_report_levels(station->netdev, NULL, 0);
|
|
|
|
|
|
|
|
return l_dbus_message_new_method_return(message);
|
|
|
|
}
|
|
|
|
|
2018-09-05 18:02:33 +02:00
|
|
|
static bool station_property_get_connected_network(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
if (!station->connected_network)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
|
|
|
network_get_path(station->connected_network));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_property_get_scanning(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
bool scanning = station->scanning;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'b', &scanning);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_property_get_state(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
2021-05-24 23:09:28 +02:00
|
|
|
const char *statestr = "invalid";
|
2018-09-05 18:02:33 +02:00
|
|
|
|
2021-05-24 23:09:28 +02:00
|
|
|
switch (station->state) {
|
|
|
|
case STATION_STATE_AUTOCONNECT_QUICK:
|
|
|
|
case STATION_STATE_AUTOCONNECT_FULL:
|
|
|
|
case STATION_STATE_DISCONNECTED:
|
2018-09-05 18:02:33 +02:00
|
|
|
statestr = "disconnected";
|
2021-05-24 23:09:28 +02:00
|
|
|
break;
|
|
|
|
case STATION_STATE_CONNECTING:
|
|
|
|
case STATION_STATE_CONNECTING_AUTO:
|
|
|
|
statestr = "connecting";
|
|
|
|
break;
|
|
|
|
case STATION_STATE_CONNECTED:
|
|
|
|
statestr = "connected";
|
|
|
|
break;
|
|
|
|
case STATION_STATE_DISCONNECTING:
|
|
|
|
statestr = "disconnecting";
|
|
|
|
break;
|
|
|
|
case STATION_STATE_ROAMING:
|
2022-09-28 20:33:50 +02:00
|
|
|
case STATION_STATE_FT_ROAMING:
|
|
|
|
case STATION_STATE_FW_ROAMING:
|
2021-05-24 23:09:28 +02:00
|
|
|
statestr = "roaming";
|
|
|
|
break;
|
|
|
|
}
|
2018-09-05 18:02:33 +02:00
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's', statestr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:07:03 +02:00
|
|
|
void station_foreach(station_foreach_func_t func, void *user_data)
|
|
|
|
{
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(station_list); entry;
|
|
|
|
entry = entry->next) {
|
|
|
|
struct station *station = entry->data;
|
|
|
|
|
|
|
|
func(station, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-03 05:15:41 +02:00
|
|
|
struct station *station_find(uint32_t ifindex)
|
|
|
|
{
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(station_list); entry;
|
|
|
|
entry = entry->next) {
|
|
|
|
struct station *station = entry->data;
|
|
|
|
|
|
|
|
if (netdev_get_ifindex(station->netdev) == ifindex)
|
|
|
|
return station;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-15 22:15:20 +02:00
|
|
|
struct network_foreach_data {
|
|
|
|
station_network_foreach_func_t func;
|
|
|
|
void *user_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void network_foreach(const void *key, void *value, void *user_data)
|
|
|
|
{
|
|
|
|
struct network_foreach_data *data = user_data;
|
|
|
|
struct network *network = value;
|
|
|
|
|
|
|
|
data->func(network, data->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void station_network_foreach(struct station *station,
|
|
|
|
station_network_foreach_func_t func,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct network_foreach_data data = {
|
|
|
|
.func = func,
|
|
|
|
.user_data = user_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
l_hashmap_foreach(station->networks, network_foreach, &data);
|
|
|
|
}
|
|
|
|
|
2019-10-29 18:50:41 +01:00
|
|
|
struct l_queue *station_get_bss_list(struct station *station)
|
|
|
|
{
|
|
|
|
return station->bss_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct scan_bss *station_get_connected_bss(struct station *station)
|
|
|
|
{
|
|
|
|
return station->connected_bss;
|
|
|
|
}
|
|
|
|
|
2021-02-02 05:43:34 +01:00
|
|
|
int station_hide_network(struct station *station, struct network *network)
|
|
|
|
{
|
|
|
|
const char *path = network_get_path(network);
|
|
|
|
struct scan_bss *bss;
|
|
|
|
|
|
|
|
l_debug("%s", path);
|
|
|
|
|
|
|
|
if (station->connected_network == network)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (!l_hashmap_lookup(station->networks, path))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
l_queue_remove(station->networks_sorted, network);
|
|
|
|
l_hashmap_remove(station->networks, path);
|
|
|
|
|
|
|
|
while ((bss = network_bss_list_pop(network))) {
|
2021-02-03 18:14:30 +01:00
|
|
|
memset(bss->ssid, 0, bss->ssid_len);
|
2021-02-02 05:43:34 +01:00
|
|
|
l_queue_remove_if(station->hidden_bss_list_sorted,
|
|
|
|
bss_match_bssid, bss->addr);
|
|
|
|
l_queue_insert(station->hidden_bss_list_sorted, bss,
|
|
|
|
bss_signal_strength_compare, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
network_remove(network, -ESRCH);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-09-28 14:41:27 +02:00
|
|
|
static void station_add_2_4ghz_freq(uint32_t freq, void *user_data)
|
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 02:28:58 +01:00
|
|
|
{
|
2023-09-28 14:41:27 +02:00
|
|
|
struct scan_freq_set *set = user_data;
|
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 02:28:58 +01:00
|
|
|
|
2023-09-28 14:41:27 +02:00
|
|
|
/* exclude social channels added in initial scan request */
|
|
|
|
if (freq < 3000 && freq != 2412 && freq != 2437 && freq != 2462)
|
|
|
|
scan_freq_set_add(set, freq);
|
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 02:28:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void station_fill_scan_freq_subsets(struct station *station)
|
|
|
|
{
|
|
|
|
const struct scan_freq_set *supported =
|
2023-09-28 14:41:27 +02:00
|
|
|
wiphy_get_supported_freqs(station->wiphy);
|
|
|
|
unsigned int subset_idx = 0;
|
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 02:28:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the 2.4GHz "social channels" first, 5GHz second, if supported,
|
|
|
|
* all other 2.4GHz channels last. To be refined as needed.
|
|
|
|
*/
|
2023-09-28 14:41:27 +02:00
|
|
|
if (allowed_bands & BAND_FREQ_2_4_GHZ) {
|
|
|
|
station->scan_freqs_order[subset_idx] = scan_freq_set_new();
|
|
|
|
scan_freq_set_add(station->scan_freqs_order[subset_idx], 2412);
|
|
|
|
scan_freq_set_add(station->scan_freqs_order[subset_idx], 2437);
|
|
|
|
scan_freq_set_add(station->scan_freqs_order[subset_idx], 2462);
|
|
|
|
subset_idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: It may might sense to split up 5 and 6ghz into separate subsets
|
|
|
|
* since the channel set is so large.
|
|
|
|
*/
|
|
|
|
if (allowed_bands & (BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ)) {
|
|
|
|
uint32_t mask = allowed_bands &
|
|
|
|
(BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ);
|
|
|
|
struct scan_freq_set *set = scan_freq_set_clone(supported,
|
|
|
|
mask);
|
|
|
|
|
|
|
|
/* 5/6ghz didn't add any frequencies */
|
|
|
|
if (scan_freq_set_isempty(set)) {
|
|
|
|
scan_freq_set_free(set);
|
|
|
|
} else
|
|
|
|
station->scan_freqs_order[subset_idx++] = set;
|
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 02:28:58 +01:00
|
|
|
}
|
2023-09-28 14:41:27 +02:00
|
|
|
|
|
|
|
/* Add remaining 2.4ghz channels to subset */
|
|
|
|
if (allowed_bands & BAND_FREQ_2_4_GHZ) {
|
|
|
|
station->scan_freqs_order[subset_idx] = scan_freq_set_new();
|
|
|
|
scan_freq_set_foreach(supported, station_add_2_4ghz_freq,
|
|
|
|
station->scan_freqs_order[subset_idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This has the unintended consequence of allowing DBus scans to
|
|
|
|
* scan the entire spectrum rather than cause IWD to be completely
|
|
|
|
* non-functional. Rather than prevent DBus scans from working at all
|
|
|
|
* print a warning here.
|
|
|
|
*/
|
|
|
|
if (station->scan_freqs_order[0] == NULL)
|
|
|
|
l_warn("All supported bands were disabled by user! IWD will not"
|
|
|
|
" function as expected");
|
|
|
|
|
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 02:28:58 +01:00
|
|
|
}
|
|
|
|
|
2022-08-04 20:51:09 +02:00
|
|
|
static void station_wiphy_watch(struct wiphy *wiphy,
|
|
|
|
enum wiphy_state_watch_event event,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The only state that requires special handling is for
|
|
|
|
* quick scans since the previous quick scan was delayed until
|
|
|
|
* the regulatory domain updated. Try again in case 6Ghz is now
|
|
|
|
* unlocked (unlikely), or advance to full autoconnect. Just in
|
|
|
|
* case this update came during a quick scan, ignore it.
|
|
|
|
*/
|
|
|
|
if (station->state != STATION_STATE_AUTOCONNECT_QUICK ||
|
|
|
|
station->quick_scan_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = station_quick_scan_trigger(station);
|
|
|
|
if (!ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
L_WARN_ON(ret == -EAGAIN);
|
|
|
|
station_enter_state(station, STATION_STATE_AUTOCONNECT_FULL);
|
|
|
|
}
|
|
|
|
|
2018-09-22 18:48:26 +02:00
|
|
|
static struct station *station_create(struct netdev *netdev)
|
2018-08-31 20:24:26 +02:00
|
|
|
{
|
|
|
|
struct station *station;
|
2018-09-05 04:50:18 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
2021-08-12 22:38:07 +02:00
|
|
|
bool autoconnect = true;
|
2018-08-31 20:24:26 +02:00
|
|
|
|
|
|
|
station = l_new(struct station, 1);
|
2018-09-04 17:40:45 +02:00
|
|
|
watchlist_init(&station->state_watches, NULL);
|
2018-08-31 20:24:26 +02:00
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
station->bss_list = l_queue_new();
|
2018-11-09 01:25:21 +01:00
|
|
|
station->hidden_bss_list_sorted = l_queue_new();
|
2018-09-01 23:21:28 +02:00
|
|
|
station->networks = l_hashmap_new();
|
|
|
|
l_hashmap_set_hash_function(station->networks, l_str_hash);
|
|
|
|
l_hashmap_set_compare_function(station->networks,
|
|
|
|
(l_hashmap_compare_func_t) strcmp);
|
|
|
|
station->networks_sorted = l_queue_new();
|
|
|
|
|
2018-09-22 18:48:26 +02:00
|
|
|
station->wiphy = netdev_get_wiphy(netdev);
|
2018-08-31 20:24:26 +02:00
|
|
|
station->netdev = netdev;
|
|
|
|
|
2022-08-04 20:51:09 +02:00
|
|
|
station->wiphy_watch = wiphy_state_watch_add(station->wiphy,
|
|
|
|
station_wiphy_watch,
|
|
|
|
station, NULL);
|
|
|
|
|
2018-08-31 20:24:26 +02:00
|
|
|
l_queue_push_head(station_list, station);
|
|
|
|
|
2018-09-05 04:50:18 +02:00
|
|
|
l_dbus_object_add_interface(dbus, netdev_get_path(netdev),
|
|
|
|
IWD_STATION_INTERFACE, station);
|
|
|
|
|
2021-10-21 10:50:30 +02:00
|
|
|
if (netconfig_enabled())
|
2020-04-30 15:48:42 +02:00
|
|
|
station->netconfig = netconfig_new(netdev_get_ifindex(netdev));
|
2019-06-26 00:21:01 +02:00
|
|
|
|
2019-06-27 00:15:57 +02:00
|
|
|
station->anqp_pending = l_queue_new();
|
|
|
|
|
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 02:28:58 +01:00
|
|
|
station_fill_scan_freq_subsets(station);
|
|
|
|
|
2021-08-12 22:38:07 +02:00
|
|
|
if (iwd_is_developer_mode()) {
|
2021-08-12 21:07:21 +02:00
|
|
|
l_dbus_object_add_interface(dbus,
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DEBUG_INTERFACE,
|
|
|
|
station);
|
2021-08-12 22:38:07 +02:00
|
|
|
autoconnect = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
station_set_autoconnect(station, autoconnect);
|
2021-08-12 21:07:21 +02:00
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
station->roam_bss_list = l_queue_new();
|
|
|
|
|
2018-08-31 20:24:26 +02:00
|
|
|
return station;
|
|
|
|
}
|
|
|
|
|
2018-09-22 18:48:26 +02:00
|
|
|
static void station_free(struct station *station)
|
2018-08-31 20:24:26 +02:00
|
|
|
{
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
if (!l_queue_remove(station_list, station))
|
|
|
|
return;
|
|
|
|
|
2021-04-28 21:40:12 +02:00
|
|
|
l_dbus_object_remove_interface(dbus_get_bus(),
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DIAGNOSTIC_INTERFACE);
|
2021-08-12 21:07:21 +02:00
|
|
|
if (iwd_is_developer_mode())
|
|
|
|
l_dbus_object_remove_interface(dbus_get_bus(),
|
|
|
|
netdev_get_path(station->netdev),
|
|
|
|
IWD_STATION_DEBUG_INTERFACE);
|
2021-04-28 21:40:12 +02:00
|
|
|
|
2019-10-08 22:18:17 +02:00
|
|
|
if (station->netconfig) {
|
2019-10-03 19:24:09 +02:00
|
|
|
netconfig_destroy(station->netconfig);
|
2019-10-08 22:18:17 +02:00
|
|
|
station->netconfig = NULL;
|
|
|
|
}
|
2019-06-26 00:21:01 +02:00
|
|
|
|
2018-09-05 00:32:18 +02:00
|
|
|
periodic_scan_stop(station);
|
|
|
|
|
2018-09-05 05:46:12 +02:00
|
|
|
if (station->signal_agent) {
|
|
|
|
station_signal_agent_release(station->signal_agent,
|
|
|
|
netdev_get_path(station->netdev));
|
|
|
|
signal_agent_free(station->signal_agent);
|
|
|
|
}
|
|
|
|
|
2018-09-05 02:05:20 +02:00
|
|
|
if (station->connect_pending)
|
|
|
|
dbus_pending_reply(&station->connect_pending,
|
|
|
|
dbus_error_aborted(station->connect_pending));
|
|
|
|
|
2020-06-10 03:22:19 +02:00
|
|
|
if (station->hidden_pending)
|
|
|
|
dbus_pending_reply(&station->hidden_pending,
|
|
|
|
dbus_error_aborted(station->hidden_pending));
|
|
|
|
|
2018-09-05 02:54:48 +02:00
|
|
|
if (station->disconnect_pending)
|
|
|
|
dbus_pending_reply(&station->disconnect_pending,
|
|
|
|
dbus_error_aborted(station->disconnect_pending));
|
|
|
|
|
2018-09-05 00:32:18 +02:00
|
|
|
if (station->scan_pending)
|
|
|
|
dbus_pending_reply(&station->scan_pending,
|
|
|
|
dbus_error_aborted(station->scan_pending));
|
|
|
|
|
2019-03-22 22:17:43 +01:00
|
|
|
if (station->dbus_scan_id)
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
2019-03-22 22:17:43 +01:00
|
|
|
station->dbus_scan_id);
|
2018-10-06 02:55:55 +02:00
|
|
|
|
2019-04-16 23:51:42 +02:00
|
|
|
if (station->quick_scan_id)
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
2019-04-16 23:51:42 +02:00
|
|
|
station->quick_scan_id);
|
|
|
|
|
2018-10-06 02:55:55 +02:00
|
|
|
if (station->hidden_network_scan_id)
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
2018-10-06 02:55:55 +02:00
|
|
|
station->hidden_network_scan_id);
|
|
|
|
|
2021-09-18 00:58:38 +02:00
|
|
|
if (station->owe_hidden_scan_ids) {
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
while ((ptr = l_queue_pop_head(station->owe_hidden_scan_ids)))
|
|
|
|
scan_cancel(netdev_get_wdev_id(station->netdev),
|
|
|
|
L_PTR_TO_UINT(ptr));
|
|
|
|
|
|
|
|
l_queue_destroy(station->owe_hidden_scan_ids, NULL);
|
|
|
|
}
|
|
|
|
|
2019-05-11 01:18:57 +02:00
|
|
|
station_roam_state_clear(station);
|
2018-09-04 20:48:18 +02:00
|
|
|
|
2018-09-01 23:21:28 +02:00
|
|
|
l_queue_destroy(station->networks_sorted, NULL);
|
|
|
|
l_hashmap_destroy(station->networks, network_free);
|
|
|
|
l_queue_destroy(station->bss_list, bss_free);
|
2018-11-09 01:25:21 +01:00
|
|
|
l_queue_destroy(station->hidden_bss_list_sorted, NULL);
|
2021-05-07 22:26:17 +02:00
|
|
|
l_queue_destroy(station->autoconnect_list, NULL);
|
2018-09-01 22:15:47 +02:00
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
watchlist_destroy(&station->state_watches);
|
|
|
|
|
2020-07-09 02:04:34 +02:00
|
|
|
l_queue_destroy(station->anqp_pending, remove_anqp);
|
2019-06-27 00:15:57 +02:00
|
|
|
|
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 02:28:58 +01:00
|
|
|
scan_freq_set_free(station->scan_freqs_order[0]);
|
|
|
|
scan_freq_set_free(station->scan_freqs_order[1]);
|
|
|
|
|
|
|
|
if (station->scan_freqs_order[2])
|
|
|
|
scan_freq_set_free(station->scan_freqs_order[2]);
|
|
|
|
|
2022-08-04 20:51:09 +02:00
|
|
|
wiphy_state_watch_remove(station->wiphy, station->wiphy_watch);
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
l_queue_destroy(station->roam_bss_list, l_free);
|
|
|
|
|
2018-08-31 20:24:26 +02:00
|
|
|
l_free(station);
|
|
|
|
}
|
|
|
|
|
2018-09-05 04:50:18 +02:00
|
|
|
static void station_setup_interface(struct l_dbus_interface *interface)
|
|
|
|
{
|
2018-09-05 17:37:14 +02:00
|
|
|
l_dbus_interface_method(interface, "ConnectHiddenNetwork", 0,
|
|
|
|
station_dbus_connect_hidden_network,
|
|
|
|
"", "s", "name");
|
2018-09-05 17:45:34 +02:00
|
|
|
l_dbus_interface_method(interface, "Disconnect", 0,
|
|
|
|
station_dbus_disconnect, "", "");
|
|
|
|
l_dbus_interface_method(interface, "GetOrderedNetworks", 0,
|
2018-09-08 17:34:52 +02:00
|
|
|
station_dbus_get_networks, "a(on)", "",
|
2018-09-05 17:45:34 +02:00
|
|
|
"networks");
|
2018-11-09 20:57:08 +01:00
|
|
|
l_dbus_interface_method(interface, "GetHiddenAccessPoints", 0,
|
|
|
|
station_dbus_get_hidden_access_points,
|
|
|
|
"a(sns)", "",
|
|
|
|
"accesspoints");
|
2018-09-05 17:45:34 +02:00
|
|
|
l_dbus_interface_method(interface, "Scan", 0,
|
|
|
|
station_dbus_scan, "", "");
|
2018-09-05 05:46:12 +02:00
|
|
|
l_dbus_interface_method(interface, "RegisterSignalLevelAgent", 0,
|
|
|
|
station_dbus_signal_agent_register,
|
|
|
|
"", "oan", "path", "levels");
|
|
|
|
l_dbus_interface_method(interface, "UnregisterSignalLevelAgent", 0,
|
|
|
|
station_dbus_signal_agent_unregister,
|
|
|
|
"", "o", "path");
|
2018-09-05 18:02:33 +02:00
|
|
|
|
|
|
|
l_dbus_interface_property(interface, "ConnectedNetwork", 0, "o",
|
|
|
|
station_property_get_connected_network,
|
|
|
|
NULL);
|
|
|
|
l_dbus_interface_property(interface, "Scanning", 0, "b",
|
|
|
|
station_property_get_scanning, NULL);
|
|
|
|
l_dbus_interface_property(interface, "State", 0, "s",
|
|
|
|
station_property_get_state, NULL);
|
2018-09-05 04:50:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void station_destroy_interface(void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
|
|
|
|
station_free(station);
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:38:42 +01:00
|
|
|
static void station_get_diagnostic_cb(
|
|
|
|
const struct diagnostic_station_info *info,
|
|
|
|
void *user_data)
|
2021-01-14 21:54:40 +01:00
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
struct l_dbus_message_builder *builder;
|
2021-03-29 19:33:09 +02:00
|
|
|
struct handshake_state *hs = netdev_get_handshake(station->netdev);
|
2021-01-14 21:54:40 +01:00
|
|
|
|
|
|
|
if (!info) {
|
|
|
|
reply = dbus_error_aborted(station->get_station_pending);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
reply = l_dbus_message_new_method_return(station->get_station_pending);
|
|
|
|
|
|
|
|
builder = l_dbus_message_builder_new(reply);
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_array(builder, "{sv}");
|
|
|
|
|
|
|
|
dbus_append_dict_basic(builder, "ConnectedBss", 's',
|
|
|
|
util_address_to_string(info->addr));
|
2021-02-03 18:20:44 +01:00
|
|
|
dbus_append_dict_basic(builder, "Frequency", 'u',
|
|
|
|
&station->connected_bss->frequency);
|
2021-03-29 19:33:09 +02:00
|
|
|
dbus_append_dict_basic(builder, "Security", 's',
|
|
|
|
diagnostic_akm_suite_to_security(hs->akm_suite,
|
|
|
|
hs->wpa_ie));
|
2021-01-14 21:54:40 +01:00
|
|
|
|
2022-10-20 21:17:48 +02:00
|
|
|
if (hs->pairwise_cipher) {
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (hs->pairwise_cipher ==
|
|
|
|
IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER)
|
|
|
|
str = ie_rsn_cipher_suite_to_string(hs->group_cipher);
|
|
|
|
else
|
|
|
|
str = ie_rsn_cipher_suite_to_string(
|
|
|
|
hs->pairwise_cipher);
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
dbus_append_dict_basic(builder, "PairwiseCipher",
|
|
|
|
's', str);
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:38:44 +01:00
|
|
|
diagnostic_info_to_dict(info, builder);
|
2021-01-14 21:54:40 +01:00
|
|
|
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
|
|
|
|
done:
|
|
|
|
dbus_pending_reply(&station->get_station_pending, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_get_diagnostic_destroy(void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
if (station->get_station_pending) {
|
|
|
|
reply = dbus_error_aborted(station->get_station_pending);
|
|
|
|
dbus_pending_reply(&station->get_station_pending, reply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *station_get_diagnostics(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
int ret;
|
|
|
|
|
2021-06-18 09:33:23 +02:00
|
|
|
if (station->get_station_pending)
|
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
2021-01-14 21:54:40 +01:00
|
|
|
ret = netdev_get_current_station(station->netdev,
|
|
|
|
station_get_diagnostic_cb, station,
|
|
|
|
station_get_diagnostic_destroy);
|
|
|
|
if (ret < 0)
|
|
|
|
return dbus_error_from_errno(ret, message);
|
|
|
|
|
|
|
|
station->get_station_pending = l_dbus_message_ref(message);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-09-14 17:54:13 +02:00
|
|
|
struct station_roam_data {
|
|
|
|
struct station *station;
|
|
|
|
struct l_dbus_message *pending;
|
|
|
|
uint8_t bssid[6];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void station_force_roam_scan_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station_roam_data *data = user_data;
|
|
|
|
struct station *station = data->station;
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
station_roam_failed(station);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_force_roam_scan_notify(int err, struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station_roam_data *data = user_data;
|
|
|
|
struct station *station = data->station;
|
|
|
|
struct scan_bss *target;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
reply = dbus_error_from_errno(err, data->pending);
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = l_queue_remove_if(bss_list, bss_match_bssid, data->bssid);
|
|
|
|
if (!target) {
|
|
|
|
reply = dbus_error_not_found(data->pending);
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("Attempting forced roam to BSS "MAC, MAC_STR(target->addr));
|
|
|
|
|
|
|
|
/* The various roam routines expect this to be set from scanning */
|
|
|
|
station->preparing_roam = true;
|
2022-09-27 21:47:24 +02:00
|
|
|
l_queue_push_tail(station->roam_bss_list,
|
2023-08-31 14:39:23 +02:00
|
|
|
roam_bss_from_scan_bss(target, target->rank));
|
2022-09-14 17:54:13 +02:00
|
|
|
|
|
|
|
station_update_roam_bss(station, target);
|
|
|
|
|
2022-09-27 21:47:24 +02:00
|
|
|
station_transition_start(station);
|
2022-09-14 17:54:13 +02:00
|
|
|
|
|
|
|
reply = l_dbus_message_new_method_return(data->pending);
|
|
|
|
|
|
|
|
reply:
|
|
|
|
dbus_pending_reply(&data->pending, reply);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_force_roam_scan_destroy(void *user_data)
|
|
|
|
{
|
|
|
|
struct station_roam_data *data = user_data;
|
|
|
|
|
|
|
|
data->station->roam_scan_id = 0;
|
|
|
|
|
|
|
|
if (data->pending)
|
|
|
|
l_dbus_message_unref(data->pending);
|
|
|
|
|
|
|
|
l_free(data);
|
|
|
|
}
|
|
|
|
|
2021-05-05 20:23:54 +02:00
|
|
|
static struct l_dbus_message *station_force_roam(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct scan_bss *target;
|
|
|
|
struct l_dbus_message_iter iter;
|
|
|
|
uint8_t *mac;
|
|
|
|
uint32_t mac_len;
|
2022-09-14 17:54:13 +02:00
|
|
|
struct scan_parameters params = { 0 };
|
|
|
|
struct scan_freq_set *freqs = NULL;
|
|
|
|
struct station_roam_data *data;
|
2021-05-05 20:23:54 +02:00
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "ay", &iter))
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_fixed_array(&iter, &mac, &mac_len))
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
if (mac_len != 6)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
2021-09-24 00:57:27 +02:00
|
|
|
if (!station->connected_network)
|
|
|
|
return dbus_error_not_connected(message);
|
|
|
|
|
2021-05-05 20:23:54 +02:00
|
|
|
target = network_bss_find_by_addr(station->connected_network, mac);
|
2022-09-14 17:54:13 +02:00
|
|
|
if (!target)
|
|
|
|
goto full_scan;
|
|
|
|
|
|
|
|
if (target && target == station->connected_bss)
|
|
|
|
return dbus_error_already_exists(message);
|
2021-05-05 20:23:54 +02:00
|
|
|
|
2022-08-11 01:16:15 +02:00
|
|
|
if (station->connected_bss->ssid_len != target->ssid_len)
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
if (memcmp(station->connected_bss->ssid, target->ssid,
|
|
|
|
target->ssid_len))
|
|
|
|
goto invalid_args;
|
|
|
|
|
2022-09-14 17:54:13 +02:00
|
|
|
/*
|
|
|
|
* Always scan before a roam to ensure the kernel has the BSS in its
|
|
|
|
* cache. If we already see the BSS only scan that frequency
|
|
|
|
*/
|
|
|
|
freqs = scan_freq_set_new();
|
|
|
|
scan_freq_set_add(freqs, target->frequency);
|
2021-05-05 20:23:54 +02:00
|
|
|
|
2022-09-14 17:54:13 +02:00
|
|
|
params.freqs = freqs;
|
2021-08-07 01:02:11 +02:00
|
|
|
|
2022-09-14 17:54:13 +02:00
|
|
|
full_scan:
|
|
|
|
params.flush = true;
|
2021-05-05 20:23:54 +02:00
|
|
|
|
2022-09-14 17:54:13 +02:00
|
|
|
data = l_new(struct station_roam_data, 1);
|
|
|
|
data->station = station;
|
|
|
|
data->pending = l_dbus_message_ref(message);
|
|
|
|
memcpy(data->bssid, mac, 6);
|
|
|
|
|
|
|
|
station->roam_scan_id = scan_active_full(
|
|
|
|
netdev_get_wdev_id(station->netdev),
|
|
|
|
¶ms,
|
|
|
|
station_force_roam_scan_triggered,
|
|
|
|
station_force_roam_scan_notify, data,
|
|
|
|
station_force_roam_scan_destroy);
|
|
|
|
|
|
|
|
if (freqs)
|
|
|
|
scan_freq_set_free(freqs);
|
|
|
|
|
|
|
|
if (!station->roam_scan_id) {
|
|
|
|
l_free(data);
|
|
|
|
return dbus_error_failed(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freqs)
|
|
|
|
l_debug("Scanning on %u for BSS "MAC, target->frequency,
|
|
|
|
MAC_STR(mac));
|
|
|
|
else
|
|
|
|
l_debug("Full scan for BSS "MAC, MAC_STR(mac));
|
|
|
|
|
|
|
|
return NULL;
|
2021-05-05 20:23:54 +02:00
|
|
|
|
|
|
|
invalid_args:
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
}
|
|
|
|
|
2021-08-12 21:07:21 +02:00
|
|
|
static struct network *station_find_network_from_bss(struct station *station,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
enum security security;
|
|
|
|
char ssid[33];
|
|
|
|
|
|
|
|
memcpy(ssid, bss->ssid, bss->ssid_len);
|
|
|
|
ssid[bss->ssid_len] = '\0';
|
|
|
|
|
2022-02-24 18:04:55 +01:00
|
|
|
if (scan_bss_get_security(bss, &security) < 0)
|
2021-08-12 21:07:21 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return station_network_find(station, ssid, security);
|
|
|
|
}
|
|
|
|
|
2021-01-14 21:54:40 +01:00
|
|
|
static void station_setup_diagnostic_interface(
|
|
|
|
struct l_dbus_interface *interface)
|
|
|
|
{
|
|
|
|
l_dbus_interface_method(interface, "GetDiagnostics", 0,
|
|
|
|
station_get_diagnostics, "a{sv}", "",
|
|
|
|
"diagnostics");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_destroy_diagnostic_interface(void *user_data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-12 21:07:21 +02:00
|
|
|
static struct l_dbus_message *station_force_connect_bssid(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_queue *bss_list;
|
|
|
|
struct scan_bss *target;
|
|
|
|
struct network *network;
|
|
|
|
struct l_dbus_message_iter iter;
|
|
|
|
uint8_t *mac;
|
|
|
|
uint32_t mac_len;
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "ay", &iter))
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_fixed_array(&iter, &mac, &mac_len))
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
if (mac_len != 6)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
bss_list = station_get_bss_list(station);
|
|
|
|
|
|
|
|
target = l_queue_find(bss_list, bss_match_bssid, mac);
|
|
|
|
if (!target)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (util_ssid_is_hidden(target->ssid_len, target->ssid))
|
|
|
|
return dbus_error_not_found(message);
|
|
|
|
|
|
|
|
network = station_find_network_from_bss(station, target);
|
|
|
|
if (!network)
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
l_debug("Attempting forced connection to BSS "MAC, MAC_STR(mac));
|
|
|
|
|
|
|
|
return __network_connect(network, target, message);
|
|
|
|
|
|
|
|
invalid_args:
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
}
|
|
|
|
|
2021-08-13 01:12:28 +02:00
|
|
|
static void station_debug_scan_triggered(int err, void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
if (station->scan_pending) {
|
|
|
|
reply = dbus_error_from_errno(err,
|
|
|
|
station->scan_pending);
|
|
|
|
dbus_pending_reply(&station->scan_pending, reply);
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:00:01 +02:00
|
|
|
station_dbus_scan_done(station, false);
|
2021-08-13 01:12:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("debug scan triggered for %s",
|
|
|
|
netdev_get_name(station->netdev));
|
|
|
|
|
|
|
|
if (station->scan_pending) {
|
|
|
|
reply = l_dbus_message_new_method_return(station->scan_pending);
|
|
|
|
l_dbus_message_set_arguments(reply, "");
|
|
|
|
dbus_pending_reply(&station->scan_pending, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
station_property_set_scanning(station, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool station_debug_scan_results(int err, struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
struct station *station = userdata;
|
|
|
|
|
|
|
|
if (err) {
|
2021-09-16 21:00:01 +02:00
|
|
|
station_dbus_scan_done(station, false);
|
2021-08-13 01:12:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 20:47:01 +02:00
|
|
|
station_set_scan_results(station, bss_list, freqs, false);
|
2021-09-16 21:00:01 +02:00
|
|
|
station_dbus_scan_done(station, false);
|
2021-08-13 01:12:28 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *station_debug_scan(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message_iter iter;
|
|
|
|
uint16_t *freqs;
|
|
|
|
uint32_t freqs_len;
|
|
|
|
struct scan_freq_set *freq_set;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (station->dbus_scan_id)
|
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
|
|
|
if (station->state == STATION_STATE_CONNECTING ||
|
|
|
|
station->state == STATION_STATE_CONNECTING_AUTO)
|
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "aq", &iter))
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_fixed_array(&iter, &freqs, &freqs_len))
|
|
|
|
goto invalid_args;
|
|
|
|
|
|
|
|
freq_set = scan_freq_set_new();
|
|
|
|
|
|
|
|
for (i = 0; i < freqs_len; i++) {
|
2021-09-02 01:38:52 +02:00
|
|
|
if (scan_freq_set_contains(freq_set, (uint32_t)freqs[i]))
|
|
|
|
continue;
|
|
|
|
|
2021-08-13 01:12:28 +02:00
|
|
|
if (!scan_freq_set_add(freq_set, (uint32_t)freqs[i])) {
|
|
|
|
scan_freq_set_free(freq_set);
|
|
|
|
goto invalid_args;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("added frequency %u", freqs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
station->dbus_scan_id = station_scan_trigger(station, freq_set,
|
|
|
|
station_debug_scan_triggered,
|
|
|
|
station_debug_scan_results,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
scan_freq_set_free(freq_set);
|
|
|
|
|
|
|
|
if (!station->dbus_scan_id)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
station->scan_pending = l_dbus_message_ref(message);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
return dbus_error_failed(message);
|
|
|
|
invalid_args:
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
}
|
|
|
|
|
2021-08-12 22:38:06 +02:00
|
|
|
static bool station_property_get_autoconnect(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
bool autoconnect;
|
|
|
|
|
|
|
|
autoconnect = station->autoconnect;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'b', &autoconnect);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *station_property_set_autoconnect(
|
|
|
|
struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_iter *new_value,
|
|
|
|
l_dbus_property_complete_cb_t complete,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
bool autoconnect;
|
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_variant(new_value, "b", &autoconnect))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
l_debug("Setting autoconnect %s", autoconnect ? "true" : "false");
|
|
|
|
|
|
|
|
station_set_autoconnect(station, autoconnect);
|
|
|
|
|
|
|
|
return l_dbus_message_new_method_return(message);
|
|
|
|
}
|
|
|
|
|
2022-08-11 20:47:31 +02:00
|
|
|
static void station_append_byte_array(struct l_dbus_message_builder *builder,
|
|
|
|
const char *name,
|
|
|
|
const uint8_t *bytes, size_t len)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_dict(builder, "sv");
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's', name);
|
|
|
|
l_dbus_message_builder_enter_variant(builder, "ay");
|
|
|
|
l_dbus_message_builder_enter_array(builder, "y");
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'y', &bytes[i]);
|
|
|
|
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
l_dbus_message_builder_leave_variant(builder);
|
|
|
|
l_dbus_message_builder_leave_dict(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void station_append_bss_list(struct l_dbus_message_builder *builder,
|
|
|
|
const struct l_queue_entry *entry)
|
|
|
|
{
|
|
|
|
for (; entry; entry = entry->next) {
|
|
|
|
struct scan_bss *bss = entry->data;
|
|
|
|
int32_t rssi = bss->signal_strength / 100;
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_array(builder, "{sv}");
|
|
|
|
|
|
|
|
dbus_append_dict_basic(builder, "Frequency", 'u',
|
|
|
|
&bss->frequency);
|
|
|
|
dbus_append_dict_basic(builder, "RSSI", 'i',
|
|
|
|
&rssi);
|
|
|
|
dbus_append_dict_basic(builder, "Rank", 'q', &bss->rank);
|
|
|
|
|
|
|
|
dbus_append_dict_basic(builder, "Address", 's',
|
|
|
|
util_address_to_string(bss->addr));
|
|
|
|
|
|
|
|
station_append_byte_array(builder, "MDE", bss->mde, 3);
|
|
|
|
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *station_debug_get_networks(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct station *station = user_data;
|
|
|
|
struct l_dbus_message *reply =
|
|
|
|
l_dbus_message_new_method_return(message);
|
|
|
|
struct l_dbus_message_builder *builder =
|
|
|
|
l_dbus_message_builder_new(reply);
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_array(builder, "{oaa{sv}}");
|
|
|
|
|
|
|
|
if (l_queue_isempty(station->networks_sorted))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(station->networks_sorted); entry;
|
|
|
|
entry = entry->next) {
|
|
|
|
const struct network *network = entry->data;
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_dict(builder, "oaa{sv}");
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
|
|
|
network_get_path(network));
|
|
|
|
l_dbus_message_builder_enter_array(builder, "a{sv}");
|
|
|
|
|
|
|
|
station_append_bss_list(builder,
|
|
|
|
network_bss_list_get_entries(network));
|
|
|
|
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
l_dbus_message_builder_leave_dict(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
|
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2021-08-12 21:07:21 +02:00
|
|
|
static void station_setup_debug_interface(
|
|
|
|
struct l_dbus_interface *interface)
|
|
|
|
{
|
|
|
|
l_dbus_interface_method(interface, "ConnectBssid", 0,
|
|
|
|
station_force_connect_bssid, "", "ay",
|
|
|
|
"mac");
|
2021-08-12 21:07:22 +02:00
|
|
|
l_dbus_interface_method(interface, "Roam", 0,
|
|
|
|
station_force_roam, "", "ay", "mac");
|
2021-08-12 22:38:06 +02:00
|
|
|
|
2021-08-13 01:12:28 +02:00
|
|
|
l_dbus_interface_method(interface, "Scan", 0,
|
|
|
|
station_debug_scan, "", "aq",
|
|
|
|
"frequencies");
|
2022-08-11 20:47:31 +02:00
|
|
|
l_dbus_interface_method(interface, "GetNetworks", 0,
|
|
|
|
station_debug_get_networks, "a{oaa{sv}}", "",
|
|
|
|
"networks");
|
2021-08-13 01:12:28 +02:00
|
|
|
|
2021-08-13 21:47:08 +02:00
|
|
|
l_dbus_interface_signal(interface, "Event", 0, "sav", "name", "data");
|
|
|
|
|
2021-08-12 22:38:06 +02:00
|
|
|
l_dbus_interface_property(interface, "AutoConnect", 0, "b",
|
|
|
|
station_property_get_autoconnect,
|
|
|
|
station_property_set_autoconnect);
|
2021-08-12 21:07:21 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 23:58:53 +02:00
|
|
|
static void ap_roam_frame_event(const struct mmpdu_header *hdr,
|
|
|
|
const void *body, size_t body_len,
|
|
|
|
int rssi, void *user_data)
|
|
|
|
{
|
|
|
|
uint32_t ifindex = L_PTR_TO_UINT(user_data);
|
|
|
|
struct station *station = station_find(ifindex);
|
|
|
|
|
|
|
|
if (!station)
|
|
|
|
return;
|
|
|
|
|
|
|
|
station_ap_directed_roam(station, hdr, body, body_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_frame_watches(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
static const uint8_t action_ap_roam_prefix[2] = { 0x0a, 0x07 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register for AP roam transition watch
|
|
|
|
*/
|
|
|
|
frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0,
|
|
|
|
action_ap_roam_prefix, sizeof(action_ap_roam_prefix),
|
|
|
|
ap_roam_frame_event,
|
|
|
|
L_UINT_TO_PTR(netdev_get_ifindex(netdev)), NULL);
|
|
|
|
}
|
|
|
|
|
2018-09-05 04:50:18 +02:00
|
|
|
static void station_netdev_watch(struct netdev *netdev,
|
|
|
|
enum netdev_watch_event event, void *userdata)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case NETDEV_WATCH_EVENT_NEW:
|
2021-04-19 23:58:53 +02:00
|
|
|
if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION) {
|
|
|
|
add_frame_watches(netdev);
|
|
|
|
|
|
|
|
if (netdev_get_is_up(netdev))
|
|
|
|
station_create(netdev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NETDEV_WATCH_EVENT_UP:
|
|
|
|
if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
|
2018-09-22 18:48:26 +02:00
|
|
|
station_create(netdev);
|
2021-04-19 23:58:53 +02:00
|
|
|
|
2018-09-05 04:50:18 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_WATCH_EVENT_DOWN:
|
|
|
|
case NETDEV_WATCH_EVENT_DEL:
|
|
|
|
l_dbus_object_remove_interface(dbus_get_bus(),
|
|
|
|
netdev_get_path(netdev),
|
|
|
|
IWD_STATION_INTERFACE);
|
2021-04-19 23:58:53 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_WATCH_EVENT_IFTYPE_CHANGE:
|
|
|
|
if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
|
|
|
|
add_frame_watches(netdev);
|
|
|
|
|
2018-09-05 04:50:18 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 14:56:10 +01:00
|
|
|
static void station_known_networks_changed(enum known_networks_event event,
|
|
|
|
const struct network_info *info,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
_auto_(l_free) char *network_id = NULL;
|
|
|
|
|
|
|
|
if (event != KNOWN_NETWORKS_EVENT_REMOVED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info->type != SECURITY_8021X)
|
|
|
|
return;
|
|
|
|
|
|
|
|
network_id = l_util_hexstring(info->ssid, strlen(info->ssid));
|
|
|
|
eap_tls_forget_peer(network_id);
|
|
|
|
}
|
|
|
|
|
2019-05-22 17:05:45 +02:00
|
|
|
static int station_init(void)
|
2018-08-31 20:24:26 +02:00
|
|
|
{
|
2023-10-02 13:32:13 +02:00
|
|
|
if (scan_get_band_rank_modifier(BAND_FREQ_2_4_GHZ))
|
|
|
|
allowed_bands |= BAND_FREQ_2_4_GHZ;
|
|
|
|
if (scan_get_band_rank_modifier(BAND_FREQ_5_GHZ))
|
|
|
|
allowed_bands |= BAND_FREQ_5_GHZ;
|
|
|
|
if (scan_get_band_rank_modifier(BAND_FREQ_6_GHZ))
|
|
|
|
allowed_bands |= BAND_FREQ_6_GHZ;
|
|
|
|
|
|
|
|
if (!(allowed_bands & (BAND_FREQ_2_4_GHZ | BAND_FREQ_5_GHZ))) {
|
|
|
|
l_error("At least 2.4GHz and 5GHz bands must be enabled for "
|
|
|
|
"IWD to start, check [Rank].BandModifier* setting");
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2018-08-31 20:24:26 +02:00
|
|
|
station_list = l_queue_new();
|
2018-09-05 04:50:18 +02:00
|
|
|
netdev_watch = netdev_watch_add(station_netdev_watch, NULL, NULL);
|
|
|
|
l_dbus_register_interface(dbus_get_bus(), IWD_STATION_INTERFACE,
|
|
|
|
station_setup_interface,
|
|
|
|
station_destroy_interface, false);
|
2021-01-14 21:54:40 +01:00
|
|
|
l_dbus_register_interface(dbus_get_bus(),
|
|
|
|
IWD_STATION_DIAGNOSTIC_INTERFACE,
|
|
|
|
station_setup_diagnostic_interface,
|
|
|
|
station_destroy_diagnostic_interface,
|
|
|
|
false);
|
2021-08-12 21:07:21 +02:00
|
|
|
if (iwd_is_developer_mode())
|
|
|
|
l_dbus_register_interface(dbus_get_bus(),
|
|
|
|
IWD_STATION_DEBUG_INTERFACE,
|
|
|
|
station_setup_debug_interface,
|
|
|
|
NULL,
|
|
|
|
false);
|
2019-10-25 04:15:17 +02:00
|
|
|
|
|
|
|
if (!l_settings_get_uint(iwd_get_config(), "General",
|
|
|
|
"ManagementFrameProtection",
|
|
|
|
&mfp_setting))
|
|
|
|
mfp_setting = 1;
|
|
|
|
|
|
|
|
if (mfp_setting > 2) {
|
|
|
|
l_error("Invalid [General].ManagementFrameProtection value: %d,"
|
|
|
|
" using default of 1", mfp_setting);
|
|
|
|
mfp_setting = 1;
|
|
|
|
}
|
|
|
|
|
2021-01-22 14:37:01 +01:00
|
|
|
if (!l_settings_get_uint(iwd_get_config(), "General",
|
|
|
|
"RoamRetryInterval",
|
|
|
|
&roam_retry_interval))
|
|
|
|
roam_retry_interval = 60;
|
|
|
|
|
|
|
|
if (roam_retry_interval > INT_MAX)
|
|
|
|
roam_retry_interval = INT_MAX;
|
|
|
|
|
2019-10-25 06:18:23 +02:00
|
|
|
if (!l_settings_get_bool(iwd_get_config(), "General", "DisableANQP",
|
|
|
|
&anqp_disabled))
|
|
|
|
anqp_disabled = true;
|
|
|
|
|
2021-10-21 10:50:30 +02:00
|
|
|
if (!netconfig_enabled())
|
2020-04-30 15:48:42 +02:00
|
|
|
l_info("station: Network configuration is disabled.");
|
|
|
|
|
2021-11-03 23:15:01 +01:00
|
|
|
supports_arp_evict_nocarrier = sysfs_supports_ipv4_setting("all",
|
|
|
|
"arp_evict_nocarrier");
|
|
|
|
supports_ndisc_evict_nocarrier = sysfs_supports_ipv6_setting("all",
|
|
|
|
"ndisc_evict_nocarrier");
|
|
|
|
|
2021-09-15 19:36:18 +02:00
|
|
|
watchlist_init(&event_watches, NULL);
|
2020-06-12 21:14:11 +02:00
|
|
|
|
2022-11-17 14:56:10 +01:00
|
|
|
eap_tls_set_session_cache_ops(storage_eap_tls_cache_load,
|
|
|
|
storage_eap_tls_cache_sync);
|
|
|
|
known_networks_watch = known_networks_watch_add(
|
|
|
|
station_known_networks_changed,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2020-04-17 19:20:53 +02:00
|
|
|
return 0;
|
2018-08-31 20:24:26 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 17:05:45 +02:00
|
|
|
static void station_exit(void)
|
2018-08-31 20:24:26 +02:00
|
|
|
{
|
2021-01-14 21:54:40 +01:00
|
|
|
l_dbus_unregister_interface(dbus_get_bus(),
|
|
|
|
IWD_STATION_DIAGNOSTIC_INTERFACE);
|
2021-08-12 21:07:21 +02:00
|
|
|
if (iwd_is_developer_mode())
|
|
|
|
l_dbus_unregister_interface(dbus_get_bus(),
|
|
|
|
IWD_STATION_DEBUG_INTERFACE);
|
2018-09-05 04:50:18 +02:00
|
|
|
l_dbus_unregister_interface(dbus_get_bus(), IWD_STATION_INTERFACE);
|
|
|
|
netdev_watch_remove(netdev_watch);
|
2018-08-31 20:24:26 +02:00
|
|
|
l_queue_destroy(station_list, NULL);
|
|
|
|
station_list = NULL;
|
2021-09-15 19:36:18 +02:00
|
|
|
watchlist_destroy(&event_watches);
|
2022-11-17 14:56:10 +01:00
|
|
|
known_networks_watch_remove(known_networks_watch);
|
|
|
|
known_networks_watch = 0;
|
2018-08-31 20:24:26 +02:00
|
|
|
}
|
2019-05-22 17:05:45 +02:00
|
|
|
|
|
|
|
IWD_MODULE(station, station_init, station_exit)
|
2022-11-17 17:16:32 +01:00
|
|
|
IWD_MODULE_DEPENDS(station, known_networks)
|
2020-08-20 18:07:51 +02:00
|
|
|
IWD_MODULE_DEPENDS(station, netdev);
|
2022-07-15 06:38:18 +02:00
|
|
|
IWD_MODULE_DEPENDS(station, netconfig);
|
|
|
|
IWD_MODULE_DEPENDS(station, frame_xchg);
|
|
|
|
IWD_MODULE_DEPENDS(station, wiphy);
|