From 3cd9322298b3e2aa948fd33eb018451e8d6ed639 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 22 May 2018 16:45:05 +0200 Subject: [PATCH] libnm: add support form 6LoWPAN devices --- Makefile.am | 2 + libnm/NetworkManager.h | 1 + libnm/libnm.ver | 1 + libnm/meson.build | 2 + libnm/nm-client.c | 3 + libnm/nm-device-6lowpan.c | 193 ++++++++++++++++++++++++++++++++++++++ libnm/nm-device-6lowpan.h | 50 ++++++++++ libnm/nm-types.h | 1 + po/POTFILES.in | 1 + 9 files changed, 254 insertions(+) create mode 100644 libnm/nm-device-6lowpan.c create mode 100644 libnm/nm-device-6lowpan.h diff --git a/Makefile.am b/Makefile.am index ea43127e81..4974a33182 100644 --- a/Makefile.am +++ b/Makefile.am @@ -780,6 +780,7 @@ libnm_lib_h_pub_real = \ libnm/nm-autoptr.h \ libnm/nm-checkpoint.h \ libnm/nm-client.h \ + libnm/nm-device-6lowpan.h \ libnm/nm-device-adsl.h \ libnm/nm-device-bond.h \ libnm/nm-device-bridge.h \ @@ -837,6 +838,7 @@ libnm_lib_c_real = \ libnm/nm-checkpoint.c \ libnm/nm-client.c \ libnm/nm-dbus-helpers.c \ + libnm/nm-device-6lowpan.c \ libnm/nm-device-adsl.c \ libnm/nm-device-bond.c \ libnm/nm-device-bridge.c \ diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index 9b62d969dc..73186f74ea 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -29,6 +29,7 @@ #include "nm-connection.h" #include "nm-core-enum-types.h" #include "nm-dbus-interface.h" +#include "nm-device-6lowpan.h" #include "nm-device-adsl.h" #include "nm-device-bond.h" #include "nm-device-bridge.h" diff --git a/libnm/libnm.ver b/libnm/libnm.ver index f8423d789d..74dda254db 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1349,6 +1349,7 @@ global: nm_client_checkpoint_rollback_finish; nm_client_get_checkpoints; nm_connection_get_setting_tc_config; + nm_device_6lowpan_get_type; nm_device_ip_tunnel_get_flags; nm_device_wifi_get_last_scan; nm_device_wpan_get_type; diff --git a/libnm/meson.build b/libnm/meson.build index f82b05c21e..b5c834ce5b 100644 --- a/libnm/meson.build +++ b/libnm/meson.build @@ -32,6 +32,7 @@ libnm_headers = files( 'nm-autoptr.h', 'nm-checkpoint.h', 'nm-client.h', + 'nm-device-6lowpan.h', 'nm-device-adsl.h', 'nm-device-bond.h', 'nm-device-bridge.h', @@ -94,6 +95,7 @@ libnm_sources = files( 'nm-checkpoint.c', 'nm-client.c', 'nm-dbus-helpers.c', + 'nm-device-6lowpan.c', 'nm-device-adsl.c', 'nm-device-bond.c', 'nm-device-bridge.c', diff --git a/libnm/nm-client.c b/libnm/nm-client.c index a0f6350a38..543dd4e8ea 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -51,6 +51,7 @@ #include "nm-access-point.h" #include "nm-active-connection.h" #include "nm-checkpoint.h" +#include "nm-device-6lowpan.h" #include "nm-device-adsl.h" #include "nm-device-bond.h" #include "nm-device-bridge.h" @@ -2524,6 +2525,8 @@ obj_nm_for_gdbus_object (NMClient *self, GDBusObject *object, GDBusObjectManager type = NM_TYPE_ACCESS_POINT; else if (strcmp (ifname, NM_DBUS_INTERFACE_ACTIVE_CONNECTION) == 0 && type != NM_TYPE_VPN_CONNECTION) type = NM_TYPE_ACTIVE_CONNECTION; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_6LOWPAN) == 0) + type = NM_TYPE_DEVICE_6LOWPAN; else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_ADSL) == 0) type = NM_TYPE_DEVICE_ADSL; else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BOND) == 0) diff --git a/libnm/nm-device-6lowpan.c b/libnm/nm-device-6lowpan.c new file mode 100644 index 0000000000..9a305d26ae --- /dev/null +++ b/libnm/nm-device-6lowpan.c @@ -0,0 +1,193 @@ +/* + * 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 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 Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2018 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-device-6lowpan.h" +#include "nm-object-private.h" + +typedef struct { + NMDevice *parent; + char *hw_address; +} NMDevice6LowpanPrivate; + +/** + * NMDevice6Lowpan: + */ +struct _NMDevice6Lowpan { + NMDevice parent; +}; + +typedef struct { + NMDeviceClass parent; + + /*< private >*/ + gpointer padding[4]; +} NMDevice6LowpanClass; + +G_DEFINE_TYPE (NMDevice6Lowpan, nm_device_6lowpan, NM_TYPE_DEVICE) + +#define NM_DEVICE_6LOWPAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_6LOWPAN, NMDevice6LowpanPrivate)) + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_PARENT, + PROP_HW_ADDRESS, +); + +/** + * nm_device_6lowpan_get_parent: + * @device: a #NMDevice6Lowpan + * + * Returns: (transfer none): the device's parent device + * + * Since: 1.14 + **/ +NMDevice * +nm_device_6lowpan_get_parent (NMDevice6Lowpan *device) +{ + g_return_val_if_fail (NM_IS_DEVICE_6LOWPAN (device), NULL); + + return NM_DEVICE_6LOWPAN_GET_PRIVATE (device)->parent; +} + +/** + * nm_device_6lowpan_get_hw_address: + * @device: a #NMDevice6Lowpan + * + * Gets the hardware (MAC) address of the #NMDevice6Lowpan + * + * Returns: the hardware address. This is the internal string used by the + * device, and must not be modified. + * + * Since: 1.14 + **/ +const char * +nm_device_6lowpan_get_hw_address (NMDevice6Lowpan *device) +{ + g_return_val_if_fail (NM_IS_DEVICE_6LOWPAN (device), NULL); + + return NM_DEVICE_6LOWPAN_GET_PRIVATE (device)->hw_address; +} + +static const char * +get_hw_address (NMDevice *device) +{ + return nm_device_6lowpan_get_hw_address (NM_DEVICE_6LOWPAN (device)); +} + +/***********************************************************/ + +static void +nm_device_6lowpan_init (NMDevice6Lowpan *device) +{ +} + +static void +init_dbus (NMObject *object) +{ + NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (object); + const NMPropertiesInfo property_info[] = { + { NM_DEVICE_6LOWPAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, + { NM_DEVICE_6LOWPAN_HW_ADDRESS, &priv->hw_address }, + { NULL }, + }; + + NM_OBJECT_CLASS (nm_device_6lowpan_parent_class)->init_dbus (object); + + _nm_object_register_properties (object, + NM_DBUS_INTERFACE_DEVICE_6LOWPAN, + property_info); +} + +static void +finalize (GObject *object) +{ + NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (object); + + g_free (priv->hw_address); + g_clear_object (&priv->parent); + + G_OBJECT_CLASS (nm_device_6lowpan_parent_class)->finalize (object); +} + +static void +get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + NMDevice6Lowpan *device = NM_DEVICE_6LOWPAN (object); + + switch (prop_id) { + case PROP_PARENT: + g_value_set_object (value, nm_device_6lowpan_get_parent (device)); + break; + case PROP_HW_ADDRESS: + g_value_set_string (value, nm_device_6lowpan_get_hw_address (device)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); + + g_type_class_add_private (klass, sizeof (NMDevice6LowpanPrivate)); + + object_class->finalize = finalize; + object_class->get_property = get_property; + + nm_object_class->init_dbus = init_dbus; + + device_class->get_hw_address = get_hw_address; + + /** + * NMDevice6Lowpan:parent: + * + * The devices's parent device. + * + * Since: 1.14 + **/ + obj_properties[PROP_PARENT] = + g_param_spec_object (NM_DEVICE_6LOWPAN_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + /** + * NMDevice6Lowpan:hw-address: + * + * The hardware (MAC) address of the device. + * + * Since: 1.14 + **/ + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_6LOWPAN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); +} diff --git a/libnm/nm-device-6lowpan.h b/libnm/nm-device-6lowpan.h new file mode 100644 index 0000000000..96f34dc312 --- /dev/null +++ b/libnm/nm-device-6lowpan.h @@ -0,0 +1,50 @@ +/* + * 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 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 Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2018 Red Hat, Inc. + */ + +#ifndef __NM_DEVICE_6LOWPAN_H__ +#define __NM_DEVICE_6LOWPAN_H__ + +#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION) +#error "Only can be included directly." +#endif + +#include "nm-device.h" + +G_BEGIN_DECLS + +#define NM_TYPE_DEVICE_6LOWPAN (nm_device_6lowpan_get_type ()) +#define NM_DEVICE_6LOWPAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_6LOWPAN, NMDevice6Lowpan)) +#define NM_DEVICE_6LOWPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_6LOWPAN, NMDevice6LowpanClass)) +#define NM_IS_DEVICE_6LOWPAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_6LOWPAN)) +#define NM_IS_DEVICE_6LOWPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_6LOWPAN)) +#define NM_DEVICE_6LOWPAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_6LOWPAN, NMDevice6LowpanClass)) + +#define NM_DEVICE_6LOWPAN_PARENT "parent" +#define NM_DEVICE_6LOWPAN_HW_ADDRESS "hw-address" + +NM_AVAILABLE_IN_1_14 +GType nm_device_6lowpan_get_type (void); + +NM_AVAILABLE_IN_1_14 +NMDevice * nm_device_6lowpan_get_parent (NMDevice6Lowpan *device); +NM_AVAILABLE_IN_1_14 +const char * nm_device_6lowpan_get_hw_address (NMDevice6Lowpan *device); +G_END_DECLS + +#endif /* __NM_DEVICE_6LOWPAN_H__ */ diff --git a/libnm/nm-types.h b/libnm/nm-types.h index 3a2c812fc7..d759b890ae 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -31,6 +31,7 @@ typedef struct _NMActiveConnection NMActiveConnection; typedef struct _NMCheckpoint NMCheckpoint; typedef struct _NMClient NMClient; typedef struct _NMDevice NMDevice; +typedef struct _NMDevice6Lowpan NMDevice6Lowpan; typedef struct _NMDeviceAdsl NMDeviceAdsl; typedef struct _NMDeviceBond NMDeviceBond; typedef struct _NMDeviceBridge NMDeviceBridge; diff --git a/po/POTFILES.in b/po/POTFILES.in index 8fe7d35cb6..f432d5f0d2 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -131,6 +131,7 @@ libnm-util/nm-setting-wired.c libnm-util/nm-setting-wireless-security.c libnm-util/nm-setting-wireless.c libnm-util/nm-utils.c +libnm/nm-device-6lowpan.c libnm/nm-device-adsl.c libnm/nm-device-bond.c libnm/nm-device-bridge.c