mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-03 15:58:02 +02:00
wifi: add initial support for iwd Wi-Fi damon
https://mail.gnome.org/archives/networkmanager-list/2017-November/msg00037.html https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00004.html https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00028.html
This commit is contained in:
commit
24bc95316d
13 changed files with 2703 additions and 133 deletions
|
|
@ -2703,6 +2703,14 @@ src_devices_wifi_libnm_device_plugin_wifi_la_SOURCES = \
|
|||
src/devices/wifi/nm-device-olpc-mesh.c \
|
||||
src/devices/wifi/nm-device-olpc-mesh.h
|
||||
|
||||
if WITH_IWD
|
||||
src_devices_wifi_libnm_device_plugin_wifi_la_SOURCES += \
|
||||
src/devices/wifi/nm-device-iwd.c \
|
||||
src/devices/wifi/nm-device-iwd.h \
|
||||
src/devices/wifi/nm-iwd-manager.c \
|
||||
src/devices/wifi/nm-iwd-manager.h
|
||||
endif
|
||||
|
||||
src_devices_wifi_libnm_device_plugin_wifi_la_CPPFLAGS = \
|
||||
-I$(srcdir)/src \
|
||||
-I$(builddir)/src \
|
||||
|
|
|
|||
21
configure.ac
21
configure.ac
|
|
@ -279,6 +279,26 @@ else
|
|||
AC_DEFINE(HAVE_NL80211_CRITICAL_PROTOCOL_CMDS, 0, [Define if nl80211 has critical protocol support])
|
||||
fi
|
||||
|
||||
dnl
|
||||
dnl Default to using wpa_supplicant but allow IWD as wifi backend
|
||||
dnl
|
||||
AC_ARG_WITH(iwd,
|
||||
AS_HELP_STRING([--with-iwd=yes],
|
||||
[Support IWD as wifi-backend in addition to wpa_supplicant (experimental)]),
|
||||
ac_with_iwd=$withval, ac_with_iwd="no")
|
||||
if test "$ac_with_iwd" != 'no'; then
|
||||
ac_with_iwd='yes'
|
||||
fi
|
||||
if test x"$ac_with_iwd" = x"yes"; then
|
||||
if test "$enable_wifi" != "yes"; then
|
||||
AC_MSG_ERROR(Enabling IWD support and disabling Wi-Fi makes no sense)
|
||||
fi
|
||||
AC_DEFINE(WITH_IWD, 1, [Define to compile with the IWD wifi-backend])
|
||||
else
|
||||
AC_DEFINE(WITH_IWD, 0, [Define to compile without the IWD wifi-backend])
|
||||
fi
|
||||
AM_CONDITIONAL(WITH_IWD, test x"${ac_with_iwd}" = x"yes")
|
||||
|
||||
dnl
|
||||
dnl Check for newer VLAN flags
|
||||
dnl
|
||||
|
|
@ -1417,6 +1437,7 @@ echo " ovs: $enable_ovs"
|
|||
echo " libnm-glib: $with_libnm_glib"
|
||||
echo " nmcli: $build_nmcli"
|
||||
echo " nmtui: $build_nmtui"
|
||||
echo " iwd: $ac_with_iwd"
|
||||
echo
|
||||
|
||||
echo "Configuration plugins (main.plugins=${config_plugins_default})"
|
||||
|
|
|
|||
1844
src/devices/wifi/nm-device-iwd.c
Normal file
1844
src/devices/wifi/nm-device-iwd.c
Normal file
File diff suppressed because it is too large
Load diff
60
src/devices/wifi/nm-device-iwd.h
Normal file
60
src/devices/wifi/nm-device-iwd.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2017 Intel Corporation
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_DEVICE_IWD_H__
|
||||
#define __NETWORKMANAGER_DEVICE_IWD_H__
|
||||
|
||||
#include "devices/nm-device.h"
|
||||
#include "nm-wifi-ap.h"
|
||||
#include "nm-device-wifi.h"
|
||||
|
||||
#define NM_TYPE_DEVICE_IWD (nm_device_iwd_get_type ())
|
||||
#define NM_DEVICE_IWD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_IWD, NMDeviceIwd))
|
||||
#define NM_DEVICE_IWD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_IWD, NMDeviceIwdClass))
|
||||
#define NM_IS_DEVICE_IWD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_IWD))
|
||||
#define NM_IS_DEVICE_IWD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_IWD))
|
||||
#define NM_DEVICE_IWD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_IWD, NMDeviceIwdClass))
|
||||
|
||||
#define NM_DEVICE_IWD_MODE NM_DEVICE_WIFI_MODE
|
||||
#define NM_DEVICE_IWD_BITRATE NM_DEVICE_WIFI_BITRATE
|
||||
#define NM_DEVICE_IWD_ACCESS_POINTS NM_DEVICE_WIFI_ACCESS_POINTS
|
||||
#define NM_DEVICE_IWD_ACTIVE_ACCESS_POINT NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT
|
||||
#define NM_DEVICE_IWD_CAPABILITIES NM_DEVICE_WIFI_CAPABILITIES
|
||||
#define NM_DEVICE_IWD_SCANNING NM_DEVICE_WIFI_SCANNING
|
||||
|
||||
/* signals */
|
||||
#define NM_DEVICE_IWD_ACCESS_POINT_ADDED NM_DEVICE_WIFI_ACCESS_POINT_ADDED
|
||||
#define NM_DEVICE_IWD_ACCESS_POINT_REMOVED NM_DEVICE_WIFI_ACCESS_POINT_REMOVED
|
||||
|
||||
/* internal signals */
|
||||
#define NM_DEVICE_IWD_SCANNING_PROHIBITED NM_DEVICE_WIFI_SCANNING_PROHIBITED
|
||||
|
||||
typedef struct _NMDeviceIwd NMDeviceIwd;
|
||||
typedef struct _NMDeviceIwdClass NMDeviceIwdClass;
|
||||
|
||||
GType nm_device_iwd_get_type (void);
|
||||
|
||||
NMDevice *nm_device_iwd_new (const char *iface, NMDeviceWifiCapabilities capabilities);
|
||||
|
||||
void nm_device_iwd_set_dbus_object (NMDeviceIwd *device, GDBusObject *object);
|
||||
|
||||
const gchar *nm_device_iwd_agent_psk_query (NMDeviceIwd *device);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DEVICE_IWD_H__ */
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
#include "nm-auth-utils.h"
|
||||
#include "settings/nm-settings-connection.h"
|
||||
#include "settings/nm-settings.h"
|
||||
#include "nm-wifi-utils.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "nm-config.h"
|
||||
|
||||
|
|
@ -680,35 +681,14 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static NMWifiAP *
|
||||
find_first_compatible_ap (NMDeviceWifi *self,
|
||||
NMConnection *connection,
|
||||
gboolean allow_unstable_order)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
NMWifiAP *ap;
|
||||
NMWifiAP *cand_ap = NULL;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
|
||||
g_hash_table_iter_init (&iter, NM_DEVICE_WIFI_GET_PRIVATE (self)->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
if (!nm_wifi_ap_check_compatible (ap, connection))
|
||||
continue;
|
||||
if (allow_unstable_order)
|
||||
return ap;
|
||||
if (!cand_ap || (nm_wifi_ap_get_id (cand_ap) < nm_wifi_ap_get_id (ap)))
|
||||
cand_ap = ap;
|
||||
}
|
||||
return cand_ap;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_available (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
NMDeviceCheckConAvailableFlags flags,
|
||||
const char *specific_object)
|
||||
{
|
||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
NMSettingWireless *s_wifi;
|
||||
const char *mode;
|
||||
|
||||
|
|
@ -721,7 +701,7 @@ check_connection_available (NMDevice *device,
|
|||
if (specific_object) {
|
||||
NMWifiAP *ap;
|
||||
|
||||
ap = get_ap_by_path (NM_DEVICE_WIFI (device), specific_object);
|
||||
ap = get_ap_by_path (self, specific_object);
|
||||
return ap ? nm_wifi_ap_check_compatible (ap, connection) : FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -745,40 +725,7 @@ check_connection_available (NMDevice *device,
|
|||
return TRUE;
|
||||
|
||||
/* check at least one AP is compatible with this connection */
|
||||
return !!find_first_compatible_ap (NM_DEVICE_WIFI (device), connection, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_manf_default_ssid (const GByteArray *ssid)
|
||||
{
|
||||
int i;
|
||||
/*
|
||||
* List of manufacturer default SSIDs that are often unchanged by users.
|
||||
*
|
||||
* NOTE: this list should *not* contain networks that you would like to
|
||||
* automatically roam to like "Starbucks" or "AT&T" or "T-Mobile HotSpot".
|
||||
*/
|
||||
static const char *manf_defaults[] = {
|
||||
"linksys",
|
||||
"linksys-a",
|
||||
"linksys-g",
|
||||
"default",
|
||||
"belkin54g",
|
||||
"NETGEAR",
|
||||
"o2DSL",
|
||||
"WLAN",
|
||||
"ALICE-WLAN",
|
||||
"Speedport W 501V",
|
||||
"TURBONETT",
|
||||
};
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (manf_defaults); i++) {
|
||||
if (ssid->len == strlen (manf_defaults[i])) {
|
||||
if (memcmp (manf_defaults[i], ssid->data, ssid->len) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return !!nm_wifi_aps_find_first_compatible (priv->aps, connection, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -789,6 +736,7 @@ complete_connection (NMDevice *device,
|
|||
GError **error)
|
||||
{
|
||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
NMSettingWireless *s_wifi;
|
||||
const char *setting_mac;
|
||||
char *str_ssid = NULL;
|
||||
|
|
@ -825,7 +773,7 @@ complete_connection (NMDevice *device,
|
|||
|
||||
if (!nm_streq0 (mode, NM_SETTING_WIRELESS_MODE_AP)) {
|
||||
/* Find a compatible AP in the scan list */
|
||||
ap = find_first_compatible_ap (self, connection, FALSE);
|
||||
ap = nm_wifi_aps_find_first_compatible (priv->aps, connection, FALSE);
|
||||
|
||||
/* If we still don't have an AP, then the WiFI settings needs to be
|
||||
* fully specified by the client. Might not be able to find an AP
|
||||
|
|
@ -900,7 +848,7 @@ complete_connection (NMDevice *device,
|
|||
*/
|
||||
if (!nm_wifi_ap_complete_connection (ap,
|
||||
connection,
|
||||
is_manf_default_ssid (ssid),
|
||||
nm_wifi_utils_is_manf_default_ssid (ssid),
|
||||
error)) {
|
||||
if (tmp_ssid)
|
||||
g_byte_array_unref (tmp_ssid);
|
||||
|
|
@ -1007,6 +955,7 @@ can_auto_connect (NMDevice *device,
|
|||
char **specific_object)
|
||||
{
|
||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
NMSettingWireless *s_wifi;
|
||||
NMWifiAP *ap;
|
||||
const char *method, *mode;
|
||||
|
|
@ -1038,7 +987,7 @@ can_auto_connect (NMDevice *device,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
ap = find_first_compatible_ap (self, connection, FALSE);
|
||||
ap = nm_wifi_aps_find_first_compatible (priv->aps, connection, FALSE);
|
||||
if (ap) {
|
||||
/* All good; connection is usable */
|
||||
NM_SET_OUT (specific_object, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap))));
|
||||
|
|
@ -1048,78 +997,15 @@ can_auto_connect (NMDevice *device,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
ap_id_compare (gconstpointer p_a, gconstpointer p_b, gpointer user_data)
|
||||
{
|
||||
guint64 a_id = nm_wifi_ap_get_id (*((NMWifiAP **) p_a));
|
||||
guint64 b_id = nm_wifi_ap_get_id (*((NMWifiAP **) p_b));
|
||||
|
||||
return a_id < b_id ? -1 : (a_id == b_id ? 0 : 1);
|
||||
}
|
||||
|
||||
static NMWifiAP **
|
||||
ap_list_get_sorted (NMDeviceWifi *self, gboolean include_without_ssid)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv;
|
||||
NMWifiAP **list;
|
||||
GHashTableIter iter;
|
||||
NMWifiAP *ap;
|
||||
gsize i, n;
|
||||
|
||||
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
|
||||
n = g_hash_table_size (priv->aps);
|
||||
list = g_new (NMWifiAP *, n + 1);
|
||||
|
||||
i = 0;
|
||||
if (n > 0) {
|
||||
g_hash_table_iter_init (&iter, priv->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
nm_assert (i < n);
|
||||
if ( include_without_ssid
|
||||
|| nm_wifi_ap_get_ssid (ap))
|
||||
list[i++] = ap;
|
||||
}
|
||||
nm_assert (i <= n);
|
||||
nm_assert (!include_without_ssid || i == n);
|
||||
|
||||
g_qsort_with_data (list,
|
||||
i,
|
||||
sizeof (gpointer),
|
||||
ap_id_compare,
|
||||
NULL);
|
||||
}
|
||||
list[i] = NULL;
|
||||
return list;
|
||||
}
|
||||
|
||||
static const char **
|
||||
ap_list_get_sorted_paths (NMDeviceWifi *self, gboolean include_without_ssid)
|
||||
{
|
||||
gpointer *list;
|
||||
gsize i, j;
|
||||
|
||||
list = (gpointer *) ap_list_get_sorted (self, include_without_ssid);
|
||||
for (i = 0, j = 0; list[i]; i++) {
|
||||
NMWifiAP *ap = list[i];
|
||||
const char *path;
|
||||
|
||||
/* update @list inplace to hold instead the export-path. */
|
||||
path = nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap));
|
||||
nm_assert (path);
|
||||
list[j++] = (gpointer) path;
|
||||
}
|
||||
return (const char **) list;
|
||||
}
|
||||
|
||||
static void
|
||||
impl_device_wifi_get_access_points (NMDeviceWifi *self,
|
||||
GDBusMethodInvocation *context)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
gs_free const char **list = NULL;
|
||||
GVariant *v;
|
||||
|
||||
list = ap_list_get_sorted_paths (self, FALSE);
|
||||
list = nm_wifi_aps_get_sorted_paths (priv->aps, FALSE);
|
||||
v = g_variant_new_objv (list, -1);
|
||||
g_dbus_method_invocation_return_value (context, g_variant_new_tuple (&v, 1));
|
||||
}
|
||||
|
|
@ -1128,10 +1014,11 @@ static void
|
|||
impl_device_wifi_get_all_access_points (NMDeviceWifi *self,
|
||||
GDBusMethodInvocation *context)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
gs_free const char **list = NULL;
|
||||
GVariant *v;
|
||||
|
||||
list = ap_list_get_sorted_paths (self, TRUE);
|
||||
list = nm_wifi_aps_get_sorted_paths (priv->aps, TRUE);
|
||||
v = g_variant_new_objv (list, -1);
|
||||
g_dbus_method_invocation_return_value (context, g_variant_new_tuple (&v, 1));
|
||||
}
|
||||
|
|
@ -1616,7 +1503,7 @@ ap_list_dump (gpointer user_data)
|
|||
now_s,
|
||||
priv->last_scan,
|
||||
priv->scheduled_scan_time);
|
||||
list = ap_list_get_sorted (self, TRUE);
|
||||
list = nm_wifi_aps_get_sorted (priv->aps, TRUE);
|
||||
for (i = 0; list[i]; i++)
|
||||
_ap_dump (self, LOGL_DEBUG, list[i], "dump", now_s);
|
||||
}
|
||||
|
|
@ -2658,7 +2545,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|||
if (ap)
|
||||
goto done;
|
||||
|
||||
ap = find_first_compatible_ap (self, connection, FALSE);
|
||||
ap = nm_wifi_aps_find_first_compatible (priv->aps, connection, FALSE);
|
||||
}
|
||||
|
||||
if (ap) {
|
||||
|
|
@ -3291,7 +3178,7 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_set_uint (value, priv->capabilities);
|
||||
break;
|
||||
case PROP_ACCESS_POINTS:
|
||||
list = (char **) ap_list_get_sorted_paths (self, TRUE);
|
||||
list = (char **) nm_wifi_aps_get_sorted_paths (priv->aps, TRUE);
|
||||
for (i = 0; list[i]; i++)
|
||||
list[i] = g_strdup (list[i]);
|
||||
g_value_take_boxed (value, list);
|
||||
|
|
|
|||
552
src/devices/wifi/nm-iwd-manager.c
Normal file
552
src/devices/wifi/nm-iwd-manager.c
Normal file
|
|
@ -0,0 +1,552 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2017 Intel Corporation
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "nm-iwd-manager.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include "nm-logging.h"
|
||||
#include "nm-manager.h"
|
||||
#include "nm-device-iwd.h"
|
||||
#include "nm-utils/nm-random-utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
GCancellable *cancellable;
|
||||
gboolean running;
|
||||
GDBusObjectManager *object_manager;
|
||||
guint agent_id;
|
||||
gchar *agent_path;
|
||||
} NMIwdManagerPrivate;
|
||||
|
||||
struct _NMIwdManager {
|
||||
GObject parent;
|
||||
NMIwdManagerPrivate _priv;
|
||||
};
|
||||
|
||||
struct _NMIwdManagerClass {
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMIwdManager, nm_iwd_manager, G_TYPE_OBJECT)
|
||||
|
||||
#define NM_IWD_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMIwdManager, NM_IS_IWD_MANAGER)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _NMLOG_PREFIX_NAME "iwd-manager"
|
||||
#define _NMLOG_DOMAIN LOGD_WIFI
|
||||
|
||||
#define _NMLOG(level, ...) \
|
||||
G_STMT_START { \
|
||||
if (nm_logging_enabled (level, _NMLOG_DOMAIN)) { \
|
||||
char __prefix[32]; \
|
||||
\
|
||||
if (self) \
|
||||
g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", ""_NMLOG_PREFIX_NAME"", (self)); \
|
||||
else \
|
||||
g_strlcpy (__prefix, _NMLOG_PREFIX_NAME, sizeof (__prefix)); \
|
||||
_nm_log ((level), (_NMLOG_DOMAIN), 0, NULL, NULL, \
|
||||
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
||||
__prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
psk_agent_dbus_method_cb (GDBusConnection *connection,
|
||||
const gchar *sender, const gchar *object_path,
|
||||
const gchar *interface_name, const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMIwdManager *self = user_data;
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
GDBusObjectManagerClient *omc = G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager);
|
||||
const gchar *network_path, *device_path, *ifname;
|
||||
gs_unref_object GDBusInterface *network = NULL, *device_obj = NULL;
|
||||
gs_unref_variant GVariant *value = NULL;
|
||||
gint ifindex;
|
||||
NMManager *manager;
|
||||
NMDevice *device;
|
||||
const gchar *psk;
|
||||
|
||||
/* Be paranoid and check the sender address */
|
||||
if (!nm_streq0 (g_dbus_object_manager_client_get_name_owner (omc), sender))
|
||||
goto return_error;
|
||||
|
||||
g_variant_get (parameters, "(&o)", &network_path);
|
||||
|
||||
network = g_dbus_object_manager_get_interface (priv->object_manager,
|
||||
network_path,
|
||||
NM_IWD_NETWORK_INTERFACE);
|
||||
value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (network), "Device");
|
||||
device_path = g_variant_get_string (value, NULL);
|
||||
|
||||
if (!device_path) {
|
||||
_LOGE ("Device not cached for network %s in IWD Agent request",
|
||||
network_path);
|
||||
goto return_error;
|
||||
}
|
||||
|
||||
device_obj = g_dbus_object_manager_get_interface (priv->object_manager,
|
||||
device_path,
|
||||
NM_IWD_DEVICE_INTERFACE);
|
||||
g_variant_unref (value);
|
||||
value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (device_obj), "Name");
|
||||
ifname = g_variant_get_string (value, NULL);
|
||||
|
||||
if (!ifname) {
|
||||
_LOGE ("Name not cached for device %s in IWD Agent request",
|
||||
device_path);
|
||||
goto return_error;
|
||||
}
|
||||
|
||||
ifindex = if_nametoindex (ifname);
|
||||
if (!ifindex) {
|
||||
_LOGE ("if_nametoindex failed for Name %s for Device at %s: %i",
|
||||
ifname, device_path, errno);
|
||||
goto return_error;
|
||||
}
|
||||
|
||||
manager = nm_manager_get ();
|
||||
|
||||
device = nm_manager_get_device_by_ifindex (manager, ifindex);
|
||||
if (!NM_IS_DEVICE_IWD (device)) {
|
||||
_LOGE ("IWD device named %s is not a Wifi device in IWD Agent request",
|
||||
ifname);
|
||||
goto return_error;
|
||||
}
|
||||
|
||||
psk = nm_device_iwd_agent_psk_query (NM_DEVICE_IWD (device));
|
||||
if (!psk) {
|
||||
_LOGW ("Device %s had no PSK for the IWD Agent", ifname);
|
||||
goto return_error;
|
||||
}
|
||||
|
||||
_LOGI ("Sending the PSK to the IWD Agent for device %s", ifname);
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("(s)", psk));
|
||||
return;
|
||||
|
||||
return_error:
|
||||
/* IWD doesn't look at the specific error */
|
||||
g_dbus_method_invocation_return_error_literal (invocation, NM_DEVICE_ERROR,
|
||||
NM_DEVICE_ERROR_INVALID_CONNECTION,
|
||||
"No PSK available for this connection");
|
||||
}
|
||||
|
||||
|
||||
static guint
|
||||
psk_agent_export (GDBusConnection *connection, gpointer user_data,
|
||||
gchar **agent_path, GError **error)
|
||||
{
|
||||
static const GDBusArgInfo request_passphrase_arg_network = {
|
||||
-1,
|
||||
(gchar *) "network",
|
||||
(gchar *) "o",
|
||||
NULL,
|
||||
};
|
||||
static const GDBusArgInfo *const request_passphrase_in_args[] = {
|
||||
&request_passphrase_arg_network,
|
||||
NULL,
|
||||
};
|
||||
static const GDBusArgInfo request_passphrase_arg_passphrase = {
|
||||
-1,
|
||||
(gchar *) "passphrase",
|
||||
(gchar *) "s",
|
||||
NULL,
|
||||
};
|
||||
static const GDBusArgInfo *const request_passphrase_out_args[] = {
|
||||
&request_passphrase_arg_passphrase,
|
||||
NULL,
|
||||
};
|
||||
static const GDBusMethodInfo request_passphrase_info = {
|
||||
-1,
|
||||
(gchar *) "RequestPassphrase",
|
||||
(GDBusArgInfo **) &request_passphrase_in_args,
|
||||
(GDBusArgInfo **) &request_passphrase_out_args,
|
||||
NULL,
|
||||
};
|
||||
static const GDBusMethodInfo *const method_info[] = {
|
||||
&request_passphrase_info,
|
||||
NULL,
|
||||
};
|
||||
static GDBusInterfaceInfo interface_info = {
|
||||
-1,
|
||||
(gchar *) "net.connman.iwd.Agent",
|
||||
(GDBusMethodInfo **) &method_info,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
static GDBusInterfaceVTable vtable = {
|
||||
psk_agent_dbus_method_cb,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
gchar path[50];
|
||||
unsigned int rnd;
|
||||
guint id;
|
||||
|
||||
if (!nm_utils_random_bytes (&rnd, sizeof (rnd))) {
|
||||
g_set_error_literal (error,
|
||||
NM_DEVICE_ERROR,
|
||||
NM_DEVICE_ERROR_FAILED,
|
||||
"Can't read urandom.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
nm_sprintf_buf (path, "/agent/%u", rnd);
|
||||
|
||||
id = g_dbus_connection_register_object (connection, path,
|
||||
&interface_info, &vtable,
|
||||
user_data, NULL, error);
|
||||
|
||||
if (id)
|
||||
*agent_path = g_strdup (path);
|
||||
return id;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
set_device_dbus_object (NMIwdManager *self, GDBusInterface *interface,
|
||||
GDBusObject *object)
|
||||
{
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
GDBusProxy *proxy;
|
||||
GVariant *value;
|
||||
const char *ifname;
|
||||
gint ifindex;
|
||||
NMDevice *device;
|
||||
NMManager *manager;
|
||||
|
||||
if (!priv->running)
|
||||
return;
|
||||
|
||||
g_return_if_fail (G_IS_DBUS_PROXY (interface));
|
||||
|
||||
proxy = G_DBUS_PROXY (interface);
|
||||
|
||||
if (strcmp (g_dbus_proxy_get_interface_name (proxy),
|
||||
NM_IWD_DEVICE_INTERFACE))
|
||||
return;
|
||||
|
||||
value = g_dbus_proxy_get_cached_property (proxy, "Name");
|
||||
if (!value) {
|
||||
_LOGE ("Name not cached for Device at %s",
|
||||
g_dbus_proxy_get_object_path (proxy));
|
||||
return;
|
||||
}
|
||||
|
||||
ifname = g_variant_get_string (value, NULL);
|
||||
ifindex = if_nametoindex (ifname);
|
||||
g_variant_unref (value);
|
||||
|
||||
if (!ifindex) {
|
||||
_LOGE ("if_nametoindex failed for Name %s for Device at %s: %i",
|
||||
ifname, g_dbus_proxy_get_object_path (proxy), errno);
|
||||
return;
|
||||
}
|
||||
|
||||
manager = nm_manager_get ();
|
||||
|
||||
device = nm_manager_get_device_by_ifindex (manager, ifindex);
|
||||
if (!NM_IS_DEVICE_IWD (device)) {
|
||||
_LOGE ("IWD device named %s is not a Wifi device", ifname);
|
||||
return;
|
||||
}
|
||||
|
||||
nm_device_iwd_set_dbus_object (NM_DEVICE_IWD (device), object);
|
||||
}
|
||||
|
||||
static void
|
||||
interface_added (GDBusObjectManager *object_manager, GDBusObject *object,
|
||||
GDBusInterface *interface, gpointer user_data)
|
||||
{
|
||||
NMIwdManager *self = user_data;
|
||||
|
||||
set_device_dbus_object (self, interface, object);
|
||||
}
|
||||
|
||||
static void
|
||||
interface_removed (GDBusObjectManager *object_manager, GDBusObject *object,
|
||||
GDBusInterface *interface, gpointer user_data)
|
||||
{
|
||||
NMIwdManager *self = user_data;
|
||||
|
||||
/*
|
||||
* TODO: we may need to save the GDBusInterface or GDBusObject
|
||||
* pointer in the hash table because we may be no longer able to
|
||||
* access the Name property or map the name to ifindex with
|
||||
* if_nametoindex at this point.
|
||||
*/
|
||||
|
||||
set_device_dbus_object (self, interface, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_om_has_name_owner (GDBusObjectManager *object_manager)
|
||||
{
|
||||
gs_free char *name_owner = NULL;
|
||||
|
||||
nm_assert (G_IS_DBUS_OBJECT_MANAGER_CLIENT (object_manager));
|
||||
|
||||
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (object_manager));
|
||||
return !!name_owner;
|
||||
}
|
||||
|
||||
static void
|
||||
object_added (NMIwdManager *self, GDBusObject *object)
|
||||
{
|
||||
GList *interfaces, *iter;
|
||||
|
||||
interfaces = g_dbus_object_get_interfaces (object);
|
||||
for (iter = interfaces; iter; iter = iter->next) {
|
||||
GDBusInterface *interface = G_DBUS_INTERFACE (iter->data);
|
||||
|
||||
set_device_dbus_object (self, interface, object);
|
||||
}
|
||||
|
||||
g_list_free_full (interfaces, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
|
||||
{
|
||||
NMIwdManager *self = user_data;
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
GDBusObjectManager *object_manager = G_DBUS_OBJECT_MANAGER (object);
|
||||
|
||||
nm_assert (object_manager == priv->object_manager);
|
||||
|
||||
if (_om_has_name_owner (object_manager)) {
|
||||
GList *objects, *iter;
|
||||
|
||||
priv->running = true;
|
||||
|
||||
objects = g_dbus_object_manager_get_objects (object_manager);
|
||||
for (iter = objects; iter; iter = iter->next)
|
||||
object_added (self, G_DBUS_OBJECT (iter->data));
|
||||
|
||||
g_list_free_full (objects, g_object_unref);
|
||||
|
||||
if (priv->agent_id) {
|
||||
GDBusInterface *agent_manager;
|
||||
|
||||
agent_manager = g_dbus_object_manager_get_interface (object_manager,
|
||||
"/",
|
||||
NM_IWD_AGENT_MANAGER_INTERFACE);
|
||||
|
||||
/* Register our agent */
|
||||
g_dbus_proxy_call (G_DBUS_PROXY (agent_manager),
|
||||
"RegisterAgent",
|
||||
g_variant_new ("(o)", priv->agent_path),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (agent_manager);
|
||||
}
|
||||
} else {
|
||||
NMManager *manager = nm_manager_get ();
|
||||
const GSList *devices, *iter;
|
||||
|
||||
priv->running = false;
|
||||
|
||||
devices = nm_manager_get_devices (manager);
|
||||
for (iter = devices; iter; iter = iter->next) {
|
||||
NMDevice *device = NM_DEVICE (iter->data);
|
||||
|
||||
if (!NM_IS_DEVICE_IWD (device))
|
||||
continue;
|
||||
|
||||
nm_device_iwd_set_dbus_object (NM_DEVICE_IWD (device),
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_added (NMDevice *device, gpointer user_data)
|
||||
{
|
||||
NMIwdManager *self = user_data;
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
GList *objects, *iter;
|
||||
|
||||
if (!NM_IS_DEVICE_IWD (device))
|
||||
return;
|
||||
|
||||
if (!priv->running)
|
||||
return;
|
||||
|
||||
objects = g_dbus_object_manager_get_objects (priv->object_manager);
|
||||
for (iter = objects; iter; iter = iter->next) {
|
||||
GDBusObject *object = G_DBUS_OBJECT (iter->data);
|
||||
GDBusInterface *interface;
|
||||
GDBusProxy *proxy;
|
||||
GVariant *value;
|
||||
const char *obj_ifname;
|
||||
|
||||
interface = g_dbus_object_get_interface (object,
|
||||
NM_IWD_DEVICE_INTERFACE);
|
||||
if (!interface)
|
||||
continue;
|
||||
|
||||
proxy = G_DBUS_PROXY (interface);
|
||||
value = g_dbus_proxy_get_cached_property (proxy, "Name");
|
||||
if (!value) {
|
||||
g_object_unref (interface);
|
||||
continue;
|
||||
}
|
||||
|
||||
obj_ifname = g_variant_get_string (value, NULL);
|
||||
g_variant_unref (value);
|
||||
g_object_unref (interface);
|
||||
|
||||
if (strcmp (nm_device_get_iface (device), obj_ifname))
|
||||
continue;
|
||||
|
||||
nm_device_iwd_set_dbus_object (NM_DEVICE_IWD (device), object);
|
||||
break;
|
||||
}
|
||||
|
||||
g_list_free_full (objects, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
got_object_manager (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
NMIwdManager *self = user_data;
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
GDBusObjectManager *object_manager;
|
||||
GDBusConnection *connection;
|
||||
NMManager *manager = nm_manager_get ();
|
||||
|
||||
g_clear_object (&priv->cancellable);
|
||||
|
||||
object_manager = g_dbus_object_manager_client_new_for_bus_finish (result, &error);
|
||||
if (object_manager == NULL) {
|
||||
_LOGE ("failed to acquire IWD Object Manager: Wi-Fi will not be available (%s)",
|
||||
NM_G_ERROR_MSG (error));
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
priv->object_manager = object_manager;
|
||||
|
||||
g_signal_connect (priv->object_manager, "interface-added",
|
||||
G_CALLBACK (interface_added), self);
|
||||
g_signal_connect (priv->object_manager, "interface-removed",
|
||||
G_CALLBACK (interface_removed), self);
|
||||
g_signal_connect (priv->object_manager, "notify::name-owner",
|
||||
G_CALLBACK (name_owner_changed), self);
|
||||
|
||||
nm_assert (G_IS_DBUS_OBJECT_MANAGER_CLIENT (object_manager));
|
||||
|
||||
connection = g_dbus_object_manager_client_get_connection (G_DBUS_OBJECT_MANAGER_CLIENT (object_manager));
|
||||
|
||||
priv->agent_id = psk_agent_export (connection, self,
|
||||
&priv->agent_path, &error);
|
||||
if (!priv->agent_id) {
|
||||
_LOGE ("failed to export the IWD Agent: PSK/8021x WiFi networks will not work: %s",
|
||||
NM_G_ERROR_MSG (error));
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
name_owner_changed (G_OBJECT (object_manager), NULL, self);
|
||||
|
||||
g_signal_connect (manager, "device-added",
|
||||
G_CALLBACK (device_added), self);
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_object_manager (NMIwdManager *self)
|
||||
{
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
|
||||
g_dbus_object_manager_client_new_for_bus (NM_IWD_BUS_TYPE,
|
||||
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
|
||||
NM_IWD_SERVICE, "/",
|
||||
NULL, NULL, NULL,
|
||||
priv->cancellable,
|
||||
got_object_manager, self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_DEFINE_SINGLETON_GETTER (NMIwdManager, nm_iwd_manager_get,
|
||||
NM_TYPE_IWD_MANAGER);
|
||||
|
||||
static void
|
||||
nm_iwd_manager_init (NMIwdManager *self)
|
||||
{
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
|
||||
priv->cancellable = g_cancellable_new ();
|
||||
prepare_object_manager (self);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMIwdManager *self = (NMIwdManager *) object;
|
||||
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self);
|
||||
|
||||
if (priv->object_manager) {
|
||||
if (priv->agent_id) {
|
||||
GDBusConnection *connection;
|
||||
GDBusObjectManagerClient *omc = G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager);
|
||||
|
||||
/* No need to unregister the agent as IWD will detect
|
||||
* our DBus connection being closed.
|
||||
*/
|
||||
|
||||
connection = g_dbus_object_manager_client_get_connection (omc);
|
||||
|
||||
g_dbus_connection_unregister_object (connection, priv->agent_id);
|
||||
priv->agent_id = 0;
|
||||
}
|
||||
|
||||
g_clear_object (&priv->object_manager);
|
||||
}
|
||||
|
||||
nm_clear_g_free (&priv->agent_path);
|
||||
|
||||
nm_clear_g_cancellable (&priv->cancellable);
|
||||
|
||||
G_OBJECT_CLASS (nm_iwd_manager_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_iwd_manager_class_init (NMIwdManagerClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = dispose;
|
||||
}
|
||||
53
src/devices/wifi/nm-iwd-manager.h
Normal file
53
src/devices/wifi/nm-iwd-manager.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2017 Intel Corporation
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_IWD_MANAGER_H__
|
||||
#define __NETWORKMANAGER_IWD_MANAGER_H__
|
||||
|
||||
#include "devices/nm-device.h"
|
||||
|
||||
#define NM_IWD_BUS_TYPE G_BUS_TYPE_SYSTEM
|
||||
#define NM_IWD_SERVICE "net.connman.iwd"
|
||||
|
||||
#define NM_IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager"
|
||||
#define NM_IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter"
|
||||
#define NM_IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
|
||||
#define NM_IWD_NETWORK_INTERFACE "net.connman.iwd.Network"
|
||||
#define NM_IWD_AGENT_INTERFACE "net.connman.iwd.Agent"
|
||||
#define NM_IWD_WSC_INTERFACE \
|
||||
"net.connman.iwd.WiFiSimpleConfiguration"
|
||||
#define NM_IWD_KNOWN_NETWORKS_INTERFACE "net.connman.iwd.KnownNetworks"
|
||||
#define NM_IWD_SIGNAL_AGENT_INTERFACE "net.connman.iwd.SignalLevelAgent"
|
||||
|
||||
#define NM_TYPE_IWD_MANAGER (nm_iwd_manager_get_type ())
|
||||
#define NM_IWD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IWD_MANAGER, NMIwdManager))
|
||||
#define NM_IWD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IWD_MANAGER, NMIwdManagerClass))
|
||||
#define NM_IS_IWD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IWD_MANAGER))
|
||||
#define NM_IS_IWD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IWD_MANAGER))
|
||||
#define NM_IWD_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IWD_MANAGER, NMIwdManagerClass))
|
||||
|
||||
typedef struct _NMIwdManager NMIwdManager;
|
||||
typedef struct _NMIwdManagerClass NMIwdManagerClass;
|
||||
|
||||
GType nm_iwd_manager_get_type (void);
|
||||
|
||||
NMIwdManager *nm_iwd_manager_get (void);
|
||||
|
||||
#endif /* __NETWORKMANAGER_IWD_MANAGER_H__ */
|
||||
|
|
@ -1430,3 +1430,88 @@ nm_wifi_ap_class_init (NMWifiAPClass *ap_class)
|
|||
NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static int
|
||||
ap_id_compare (gconstpointer p_a, gconstpointer p_b, gpointer user_data)
|
||||
{
|
||||
guint64 a_id = nm_wifi_ap_get_id (*((NMWifiAP **) p_a));
|
||||
guint64 b_id = nm_wifi_ap_get_id (*((NMWifiAP **) p_b));
|
||||
|
||||
return a_id < b_id ? -1 : (a_id == b_id ? 0 : 1);
|
||||
}
|
||||
|
||||
NMWifiAP **
|
||||
nm_wifi_aps_get_sorted (GHashTable *aps, gboolean include_without_ssid)
|
||||
{
|
||||
NMWifiAP **list;
|
||||
GHashTableIter iter;
|
||||
NMWifiAP *ap;
|
||||
gsize i, n;
|
||||
|
||||
n = g_hash_table_size (aps);
|
||||
list = g_new (NMWifiAP *, n + 1);
|
||||
|
||||
i = 0;
|
||||
if (n > 0) {
|
||||
g_hash_table_iter_init (&iter, aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
nm_assert (i < n);
|
||||
if ( include_without_ssid
|
||||
|| nm_wifi_ap_get_ssid (ap))
|
||||
list[i++] = ap;
|
||||
}
|
||||
nm_assert (i <= n);
|
||||
nm_assert (!include_without_ssid || i == n);
|
||||
|
||||
g_qsort_with_data (list,
|
||||
i,
|
||||
sizeof (gpointer),
|
||||
ap_id_compare,
|
||||
NULL);
|
||||
}
|
||||
list[i] = NULL;
|
||||
return list;
|
||||
}
|
||||
|
||||
const char **
|
||||
nm_wifi_aps_get_sorted_paths (GHashTable *aps, gboolean include_without_ssid)
|
||||
{
|
||||
gpointer *list;
|
||||
gsize i, j;
|
||||
|
||||
list = (gpointer *) nm_wifi_aps_get_sorted (aps, include_without_ssid);
|
||||
for (i = 0, j = 0; list[i]; i++) {
|
||||
NMWifiAP *ap = list[i];
|
||||
const char *path;
|
||||
|
||||
/* update @list inplace to hold instead the export-path. */
|
||||
path = nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap));
|
||||
nm_assert (path);
|
||||
list[j++] = (gpointer) path;
|
||||
}
|
||||
return (const char **) list;
|
||||
}
|
||||
|
||||
NMWifiAP *
|
||||
nm_wifi_aps_find_first_compatible (GHashTable *aps,
|
||||
NMConnection *connection,
|
||||
gboolean allow_unstable_order)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
NMWifiAP *ap;
|
||||
NMWifiAP *cand_ap = NULL;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
|
||||
g_hash_table_iter_init (&iter, aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
if (!nm_wifi_ap_check_compatible (ap, connection))
|
||||
continue;
|
||||
if (allow_unstable_order)
|
||||
return ap;
|
||||
if (!cand_ap || (nm_wifi_ap_get_id (cand_ap) < nm_wifi_ap_get_id (ap)))
|
||||
cand_ap = ap;
|
||||
}
|
||||
return cand_ap;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,4 +95,12 @@ const char *nm_wifi_ap_to_string (const NMWifiAP *self,
|
|||
gulong buf_len,
|
||||
gint32 now_s);
|
||||
|
||||
NMWifiAP **nm_wifi_aps_get_sorted (GHashTable *aps,
|
||||
gboolean include_without_ssid);
|
||||
const char **nm_wifi_aps_get_sorted_paths (GHashTable *aps,
|
||||
gboolean include_without_ssid);
|
||||
NMWifiAP *nm_wifi_aps_find_first_compatible (GHashTable *aps,
|
||||
NMConnection *connection,
|
||||
gboolean allow_unstable_order);
|
||||
|
||||
#endif /* __NM_WIFI_AP_H__ */
|
||||
|
|
|
|||
|
|
@ -27,8 +27,10 @@
|
|||
#include "nm-setting-olpc-mesh.h"
|
||||
#include "nm-device-wifi.h"
|
||||
#include "nm-device-olpc-mesh.h"
|
||||
#include "nm-device-iwd.h"
|
||||
#include "settings/nm-settings-connection.h"
|
||||
#include "platform/nm-platform.h"
|
||||
#include "nm-config.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -75,6 +77,7 @@ create_device (NMDeviceFactory *factory,
|
|||
{
|
||||
NMDeviceWifiCapabilities capabilities;
|
||||
NM80211Mode mode;
|
||||
gs_free char *backend = NULL;
|
||||
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
g_return_val_if_fail (plink != NULL, NULL);
|
||||
|
|
@ -98,10 +101,24 @@ create_device (NMDeviceFactory *factory,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (plink->type == NM_LINK_TYPE_WIFI)
|
||||
return nm_device_wifi_new (iface, capabilities);
|
||||
else
|
||||
if (plink->type != NM_LINK_TYPE_WIFI)
|
||||
return nm_device_olpc_mesh_new (iface);
|
||||
|
||||
backend = nm_config_data_get_value (NM_CONFIG_GET_DATA,
|
||||
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
||||
NM_CONFIG_KEYFILE_KEY_MAIN_WIFI_BACKEND,
|
||||
NM_CONFIG_GET_VALUE_STRIP);
|
||||
|
||||
nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI, "(%s) config: backend is %s, %i", iface, backend, WITH_IWD);
|
||||
if (!backend || !strcasecmp (backend, "wpa_supplicant"))
|
||||
return nm_device_wifi_new (iface, capabilities);
|
||||
#if WITH_IWD
|
||||
else if (!strcasecmp (backend, "iwd"))
|
||||
return nm_device_iwd_new (iface, capabilities);
|
||||
#endif
|
||||
|
||||
nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s) config: unknown or unsupported wifi-backend %s", iface, backend);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -782,3 +782,35 @@ nm_wifi_utils_level_to_quality (gint val)
|
|||
return CLAMP (val, 0, 100);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_wifi_utils_is_manf_default_ssid (const GByteArray *ssid)
|
||||
{
|
||||
int i;
|
||||
/*
|
||||
* List of manufacturer default SSIDs that are often unchanged by users.
|
||||
*
|
||||
* NOTE: this list should *not* contain networks that you would like to
|
||||
* automatically roam to like "Starbucks" or "AT&T" or "T-Mobile HotSpot".
|
||||
*/
|
||||
static const char *manf_defaults[] = {
|
||||
"linksys",
|
||||
"linksys-a",
|
||||
"linksys-g",
|
||||
"default",
|
||||
"belkin54g",
|
||||
"NETGEAR",
|
||||
"o2DSL",
|
||||
"WLAN",
|
||||
"ALICE-WLAN",
|
||||
"Speedport W 501V",
|
||||
"TURBONETT",
|
||||
};
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (manf_defaults); i++) {
|
||||
if (ssid->len == strlen (manf_defaults[i])) {
|
||||
if (memcmp (manf_defaults[i], ssid->data, ssid->len) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,6 @@ gboolean nm_wifi_utils_complete_connection (const GByteArray *ssid,
|
|||
|
||||
guint32 nm_wifi_utils_level_to_quality (gint val);
|
||||
|
||||
gboolean nm_wifi_utils_is_manf_default_ssid (const GByteArray *ssid);
|
||||
|
||||
#endif /* __NM_WIFI_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG "debug"
|
||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE "hostname-mode"
|
||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER "slaves-order"
|
||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_WIFI_BACKEND "wifi-backend"
|
||||
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
|
||||
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
|
||||
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue