mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
devices: add NMDeviceWpan
This commit is contained in:
parent
9a92468ac2
commit
179909a4f2
|
@ -1590,6 +1590,8 @@ src_libNetworkManager_la_SOURCES = \
|
|||
src/devices/nm-device-vlan.h \
|
||||
src/devices/nm-device-vxlan.c \
|
||||
src/devices/nm-device-vxlan.h \
|
||||
src/devices/nm-device-wpan.c \
|
||||
src/devices/nm-device-wpan.h \
|
||||
\
|
||||
src/dhcp/nm-dhcp-dhcpcanon.c \
|
||||
src/dhcp/nm-dhcp-dhclient.c \
|
||||
|
|
|
@ -213,6 +213,7 @@ typedef enum {
|
|||
* @NM_DEVICE_TYPE_OVS_INTERFACE: a OpenVSwitch interface
|
||||
* @NM_DEVICE_TYPE_OVS_PORT: a OpenVSwitch port
|
||||
* @NM_DEVICE_TYPE_OVS_BRIDGE: a OpenVSwitch bridge
|
||||
* @NM_DEVICE_TYPE_WPAN: a IEEE 802.15.4 (WPAN) MAC Layer Device
|
||||
*
|
||||
* #NMDeviceType values indicate the type of hardware represented by a
|
||||
* device object.
|
||||
|
@ -245,6 +246,7 @@ typedef enum {
|
|||
NM_DEVICE_TYPE_OVS_INTERFACE = 24,
|
||||
NM_DEVICE_TYPE_OVS_PORT = 25,
|
||||
NM_DEVICE_TYPE_OVS_BRIDGE = 26,
|
||||
NM_DEVICE_TYPE_WPAN = 27,
|
||||
} NMDeviceType;
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2007 - 2008 Novell, Inc.
|
||||
* Copyright 2007 - 2012 Red Hat, Inc.
|
||||
* Copyright 2007 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
@ -284,6 +284,7 @@ coerce_type (NMDeviceType type)
|
|||
case NM_DEVICE_TYPE_UNKNOWN:
|
||||
case NM_DEVICE_TYPE_DUMMY:
|
||||
case NM_DEVICE_TYPE_PPP:
|
||||
case NM_DEVICE_TYPE_WPAN:
|
||||
return type;
|
||||
}
|
||||
return NM_DEVICE_TYPE_UNKNOWN;
|
||||
|
@ -1345,6 +1346,8 @@ get_type_name (NMDevice *device)
|
|||
return _("Dummy");
|
||||
case NM_DEVICE_TYPE_PPP:
|
||||
return _("PPP");
|
||||
case NM_DEVICE_TYPE_WPAN:
|
||||
return _("IEEE 802.15.4");
|
||||
case NM_DEVICE_TYPE_GENERIC:
|
||||
case NM_DEVICE_TYPE_UNUSED1:
|
||||
case NM_DEVICE_TYPE_UNUSED2:
|
||||
|
|
|
@ -181,6 +181,7 @@ src/devices/nm-device-macvlan.c
|
|||
src/devices/nm-device-tun.c
|
||||
src/devices/nm-device-vlan.c
|
||||
src/devices/nm-device-vxlan.c
|
||||
src/devices/nm-device-wpan.c
|
||||
src/devices/team/nm-device-team.c
|
||||
src/devices/wifi/nm-device-olpc-mesh.c
|
||||
src/devices/wifi/nm-device-wifi.c
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2014 Red Hat, Inc.
|
||||
* Copyright (C) 2014 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
@ -430,6 +430,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call
|
|||
_ADD_INTERNAL (nm_veth_device_factory_get_type);
|
||||
_ADD_INTERNAL (nm_vlan_device_factory_get_type);
|
||||
_ADD_INTERNAL (nm_vxlan_device_factory_get_type);
|
||||
_ADD_INTERNAL (nm_wpan_device_factory_get_type);
|
||||
|
||||
load_factories_from_dir (NMPLUGINDIR, callback, user_data);
|
||||
}
|
||||
|
|
251
src/devices/nm-device-wpan.c
Normal file
251
src/devices/nm-device-wpan.c
Normal file
|
@ -0,0 +1,251 @@
|
|||
/* 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 2018 Lubomir Rintel <lkundrak@v3.sk>
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "nm-manager.h"
|
||||
#include "nm-device-wpan.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "nm-act-request.h"
|
||||
#include "nm-device-private.h"
|
||||
#include "nm-ip4-config.h"
|
||||
#include "platform/nm-platform.h"
|
||||
#include "nm-device-factory.h"
|
||||
#include "nm-setting-wpan.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include "nm-device-logging.h"
|
||||
_LOG_DECLARE_SELF(NMDeviceWpan);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _NMDeviceWpan {
|
||||
NMDevice parent;
|
||||
};
|
||||
|
||||
struct _NMDeviceWpanClass {
|
||||
NMDeviceClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceWpan, nm_device_wpan, NM_TYPE_DEVICE)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
complete_connection (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
const char *specific_object,
|
||||
NMConnection *const*existing_connections,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingWpan *s_wpan;
|
||||
|
||||
nm_utils_complete_generic (nm_device_get_platform (device),
|
||||
connection,
|
||||
NM_SETTING_WPAN_SETTING_NAME,
|
||||
existing_connections,
|
||||
NULL,
|
||||
_("WPAN connection"),
|
||||
NULL,
|
||||
TRUE);
|
||||
|
||||
s_wpan = nm_connection_get_setting_wpan (connection);
|
||||
if (!s_wpan) {
|
||||
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
||||
"A 'wpan' setting is required.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
update_connection (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
NMSettingWpan *s_wpan = nm_connection_get_setting_wpan (connection);
|
||||
|
||||
if (!s_wpan) {
|
||||
s_wpan = (NMSettingWpan *) nm_setting_wpan_new ();
|
||||
nm_connection_add_setting (connection, (NMSetting *) s_wpan);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
NMSettingWpan *s_wpan;
|
||||
const char *mac, *hw_addr;
|
||||
|
||||
if (!NM_DEVICE_CLASS (nm_device_wpan_parent_class)->check_connection_compatible (device, connection))
|
||||
return FALSE;
|
||||
|
||||
s_wpan = nm_connection_get_setting_wpan (connection);
|
||||
if (!s_wpan)
|
||||
return FALSE;
|
||||
|
||||
mac = nm_setting_wpan_get_mac_address (s_wpan);
|
||||
if (mac) {
|
||||
hw_addr = nm_device_get_hw_address (device);
|
||||
if (!nm_utils_hwaddr_matches (mac, -1, hw_addr, -1))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NMActStageReturn
|
||||
act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
||||
{
|
||||
NMDeviceWpan *self = NM_DEVICE_WPAN (device);
|
||||
NMConnection *connection;
|
||||
NMSettingWpan *s_wpan;
|
||||
NMPlatform *platform;
|
||||
guint16 pan_id;
|
||||
guint16 short_address;
|
||||
int ifindex;
|
||||
const guint8 *hwaddr;
|
||||
gsize hwaddr_len = 0;
|
||||
const NMPlatformLink *lowpan_plink;
|
||||
NMDevice *lowpan_device = NULL;
|
||||
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
|
||||
ret = NM_DEVICE_CLASS (nm_device_wpan_parent_class)->act_stage1_prepare (device, out_failure_reason);
|
||||
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
|
||||
return ret;
|
||||
|
||||
platform = nm_device_get_platform (device);
|
||||
g_return_val_if_fail (platform, NM_ACT_STAGE_RETURN_FAILURE);
|
||||
|
||||
ifindex = nm_device_get_ifindex (device);
|
||||
g_return_val_if_fail (ifindex > 0, NM_ACT_STAGE_RETURN_FAILURE);
|
||||
|
||||
connection = nm_device_get_applied_connection (device);
|
||||
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
|
||||
|
||||
s_wpan = nm_connection_get_setting_wpan (connection);
|
||||
g_return_val_if_fail (s_wpan, NM_ACT_STAGE_RETURN_FAILURE);
|
||||
|
||||
hwaddr = nm_platform_link_get_address (platform, ifindex, &hwaddr_len);
|
||||
g_return_val_if_fail (hwaddr, NM_ACT_STAGE_RETURN_FAILURE);
|
||||
|
||||
/* As of kernel 4.16, the 6LoWPAN devices layered on top of WPANs
|
||||
* need to be DOWN as well as the WPAN device itself in order to
|
||||
* modify the WPAN properties. */
|
||||
lowpan_plink = nm_platform_link_get_by_address (platform,
|
||||
NM_LINK_TYPE_6LOWPAN,
|
||||
hwaddr,
|
||||
hwaddr_len);
|
||||
if (lowpan_plink && NM_FLAGS_HAS (lowpan_plink->n_ifi_flags, IFF_UP)) {
|
||||
lowpan_device = nm_manager_get_device_by_ifindex (nm_manager_get (),
|
||||
lowpan_plink->ifindex);
|
||||
}
|
||||
|
||||
if (lowpan_device)
|
||||
nm_device_take_down (lowpan_device, TRUE);
|
||||
|
||||
nm_device_take_down (device, TRUE);
|
||||
|
||||
pan_id = nm_setting_wpan_get_pan_id (s_wpan);
|
||||
if (pan_id != G_MAXUINT16) {
|
||||
if (!nm_platform_wpan_set_pan_id (platform, ifindex, pan_id)) {
|
||||
_LOGW (LOGD_DEVICE, "unable to set the PAN ID");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
short_address = nm_setting_wpan_get_short_address (s_wpan);
|
||||
if (short_address != G_MAXUINT16) {
|
||||
if (!nm_platform_wpan_set_short_addr (platform, ifindex, short_address)) {
|
||||
_LOGW (LOGD_DEVICE, "unable to set the short address");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ret = NM_ACT_STAGE_RETURN_SUCCESS;
|
||||
out:
|
||||
nm_device_bring_up (device, TRUE, NULL);
|
||||
|
||||
if (lowpan_device)
|
||||
nm_device_bring_up (lowpan_device, TRUE, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nm_device_wpan_init (NMDeviceWpan *self)
|
||||
{
|
||||
}
|
||||
|
||||
static const NMDBusInterfaceInfoExtended interface_info_device_wpan = {
|
||||
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
|
||||
NM_DBUS_INTERFACE_DEVICE_WPAN,
|
||||
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
|
||||
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("HwAddress", "s", NM_DEVICE_HW_ADDRESS),
|
||||
),
|
||||
),
|
||||
};
|
||||
|
||||
static void
|
||||
nm_device_wpan_class_init (NMDeviceWpanClass *klass)
|
||||
{
|
||||
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
||||
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass);
|
||||
|
||||
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_WPAN)
|
||||
|
||||
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device_wpan);
|
||||
|
||||
device_class->connection_type = NM_SETTING_WPAN_SETTING_NAME;
|
||||
device_class->complete_connection = complete_connection;
|
||||
device_class->check_connection_compatible = check_connection_compatible;
|
||||
device_class->update_connection = update_connection;
|
||||
device_class->act_stage1_prepare = act_stage1_prepare;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_TYPE_WPAN_DEVICE_FACTORY (nm_wpan_device_factory_get_type ())
|
||||
#define NM_WPAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WPAN_DEVICE_FACTORY, NMWpanDeviceFactory))
|
||||
|
||||
static NMDevice *
|
||||
create_device (NMDeviceFactory *factory,
|
||||
const char *iface,
|
||||
const NMPlatformLink *plink,
|
||||
NMConnection *connection,
|
||||
gboolean *out_ignore)
|
||||
{
|
||||
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_WPAN,
|
||||
NM_DEVICE_IFACE, iface,
|
||||
NM_DEVICE_TYPE_DESC, "WPAN",
|
||||
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WPAN,
|
||||
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_WPAN,
|
||||
NULL);
|
||||
}
|
||||
|
||||
NM_DEVICE_FACTORY_DEFINE_INTERNAL (WPAN, Wpan, wpan,
|
||||
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_WPAN)
|
||||
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_WPAN_SETTING_NAME),
|
||||
factory_class->create_device = create_device;
|
||||
);
|
35
src/devices/nm-device-wpan.h
Normal file
35
src/devices/nm-device-wpan.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* 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 2018 Lubomir Rintel <lkundrak@v3.sk>
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_DEVICE_WPAN_H__
|
||||
#define __NETWORKMANAGER_DEVICE_WPAN_H__
|
||||
|
||||
#define NM_TYPE_DEVICE_WPAN (nm_device_wpan_get_type ())
|
||||
#define NM_DEVICE_WPAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_WPAN, NMDeviceWpan))
|
||||
#define NM_DEVICE_WPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_WPAN, NMDeviceWpanClass))
|
||||
#define NM_IS_DEVICE_WPAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_WPAN))
|
||||
#define NM_IS_DEVICE_WPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_WPAN))
|
||||
#define NM_DEVICE_WPAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_WPAN, NMDeviceWpanClass))
|
||||
|
||||
typedef struct _NMDeviceWpan NMDeviceWpan;
|
||||
typedef struct _NMDeviceWpanClass NMDeviceWpanClass;
|
||||
|
||||
GType nm_device_wpan_get_type (void);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DEVICE_WPAN_H__ */
|
|
@ -15,7 +15,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2005 - 2017 Red Hat, Inc.
|
||||
* Copyright (C) 2005 - 2018 Red Hat, Inc.
|
||||
* Copyright (C) 2006 - 2008 Novell, Inc.
|
||||
*/
|
||||
|
||||
|
@ -1914,6 +1914,8 @@ nm_device_get_route_metric_default (NMDeviceType device_type)
|
|||
case NM_DEVICE_TYPE_OVS_INTERFACE:
|
||||
case NM_DEVICE_TYPE_OVS_PORT:
|
||||
return 800;
|
||||
case NM_DEVICE_TYPE_WPAN:
|
||||
return 850;
|
||||
case NM_DEVICE_TYPE_GENERIC:
|
||||
return 950;
|
||||
case NM_DEVICE_TYPE_UNKNOWN:
|
||||
|
|
|
@ -110,6 +110,7 @@ sources = files(
|
|||
'devices/nm-device-veth.c',
|
||||
'devices/nm-device-vlan.c',
|
||||
'devices/nm-device-vxlan.c',
|
||||
'devices/nm-device-wpan.c',
|
||||
'devices/nm-lldp-listener.c',
|
||||
'dhcp/nm-dhcp-dhclient.c',
|
||||
'dhcp/nm-dhcp-dhclient-utils.c',
|
||||
|
|
Loading…
Reference in a new issue