libnm: add support form 6LoWPAN devices

This commit is contained in:
Lubomir Rintel 2018-05-22 16:45:05 +02:00
parent b7173ad7a7
commit 3cd9322298
9 changed files with 254 additions and 0 deletions

View file

@ -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 \

View file

@ -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"

View file

@ -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;

View file

@ -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',

View file

@ -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)

193
libnm/nm-device-6lowpan.c Normal file
View file

@ -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);
}

50
libnm/nm-device-6lowpan.h Normal file
View file

@ -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 <NetworkManager.h> 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__ */

View file

@ -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;

View file

@ -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