core: add NMSettingWpan

This commit is contained in:
Lubomir Rintel 2018-03-09 10:51:49 +01:00
parent ae8713471c
commit 8884b2cb5e
14 changed files with 372 additions and 7 deletions

View file

@ -430,6 +430,7 @@ libnm_core_lib_h_pub_real = \
libnm-core/nm-setting-wired.h \
libnm-core/nm-setting-wireless-security.h \
libnm-core/nm-setting-wireless.h \
libnm-core/nm-setting-wpan.h \
libnm-core/nm-setting.h \
libnm-core/nm-simple-connection.h \
libnm-core/nm-utils.h \
@ -497,7 +498,8 @@ libnm_core_lib_c_settings_real = \
libnm-core/nm-setting-wimax.c \
libnm-core/nm-setting-wired.c \
libnm-core/nm-setting-wireless-security.c \
libnm-core/nm-setting-wireless.c
libnm-core/nm-setting-wireless.c \
libnm-core/nm-setting-wpan.c
libnm_core_lib_c_real = \
$(libnm_core_lib_c_settings_real) \
shared/nm-utils/c-list-util.c \

View file

@ -391,3 +391,7 @@
#define DESCRIBE_DOC_NM_SETTING_WIMAX_MAC_ADDRESS N_("If specified, this connection will only apply to the WiMAX device whose MAC address matches. This property does not change the MAC address of the device (known as MAC spoofing). Deprecated: 1")
#define DESCRIBE_DOC_NM_SETTING_WIMAX_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".")
#define DESCRIBE_DOC_NM_SETTING_WIMAX_NETWORK_NAME N_("Network Service Provider (NSP) name of the WiMAX network this connection should use. Deprecated: 1")
#define DESCRIBE_DOC_NM_SETTING_WPAN_MAC_ADDRESS N_("If specified, this connection will only apply to the IEEE 802.15.4 (WPAN) MAC layer device whose permanent MAC address matches.")
#define DESCRIBE_DOC_NM_SETTING_WPAN_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".")
#define DESCRIBE_DOC_NM_SETTING_WPAN_PAN_ID N_("IEEE 802.15.4 Personal Area Network (PAN) identifier.")
#define DESCRIBE_DOC_NM_SETTING_WPAN_SHORT_ADDRESS N_("Short IEEE 802.15.4 address to be used within a restricted environment.")

View file

@ -45,6 +45,7 @@ libnm_core_headers = files(
'nm-setting-wired.h',
'nm-setting-wireless-security.h',
'nm-setting-wireless.h',
'nm-setting-wpan.h',
'nm-setting.h',
'nm-simple-connection.h',
'nm-utils.h',
@ -94,7 +95,8 @@ libnm_core_settings_sources = files(
'nm-setting-wimax.c',
'nm-setting-wired.c',
'nm-setting-wireless-security.c',
'nm-setting-wireless.c'
'nm-setting-wireless.c',
'nm-setting-wpan.c'
)
libnm_core_sources = libnm_core_settings_sources + files(

View file

@ -831,6 +831,8 @@ _supports_addr_family (NMConnection *self, int family)
g_return_val_if_fail (connection_type, TRUE);
if (strcmp (connection_type, NM_SETTING_OVS_INTERFACE_SETTING_NAME) == 0)
return TRUE;
if (strcmp (connection_type, NM_SETTING_WPAN_SETTING_NAME) == 0)
return FALSE;
return !nm_setting_connection_get_master (nm_connection_get_setting_connection (self));
}
@ -2744,6 +2746,22 @@ nm_connection_get_setting_vlan (NMConnection *connection)
return _connection_get_setting_check (connection, NM_TYPE_SETTING_VLAN);
}
/**
* nm_connection_get_setting_wpan:
* @connection: the #NMConnection
*
* A shortcut to return any #NMSettingWpan the connection might contain.
*
* Returns: (transfer none): an #NMSettingWpan if the connection contains one, otherwise %NULL
*
* Since: 1.14
**/
NMSettingWpan *
nm_connection_get_setting_wpan (NMConnection *connection)
{
return _connection_get_setting_check (connection, NM_TYPE_SETTING_WPAN);
}
NMSettingBluetooth *
_nm_connection_get_setting_bluetooth_for_nap (NMConnection *connection)
{

View file

@ -16,7 +16,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2017 Red Hat, Inc.
* Copyright 2007 - 2018 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
@ -241,6 +241,8 @@ NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security (NMConnec
NMSettingVlan * nm_connection_get_setting_vlan (NMConnection *connection);
NM_AVAILABLE_IN_1_2
NMSettingVxlan * nm_connection_get_setting_vxlan (NMConnection *connection);
NM_AVAILABLE_IN_1_14
NMSettingWpan * nm_connection_get_setting_wpan (NMConnection *connection);
G_END_DECLS

View file

@ -48,6 +48,7 @@
#include "nm-setting-wired.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wpan.h"
#include "nm-setting.h"
#include "nm-simple-connection.h"
#include "nm-utils.h"

View file

@ -15,7 +15,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2014 - 2017 Red Hat, Inc.
* (C) Copyright 2014 - 2018 Red Hat, Inc.
*/
#ifndef NM_CORE_NM_INTERNAL_H
@ -75,6 +75,7 @@
#include "nm-setting-wired.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wpan.h"
#include "nm-setting.h"
#include "nm-simple-connection.h"
#include "nm-utils.h"

View file

@ -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 2014 - 2017 Red Hat, Inc.
* Copyright 2014 - 2018 Red Hat, Inc.
*/
#ifndef __NM_CORE_TYPES_H__
@ -69,6 +69,7 @@ typedef struct _NMSettingWimax NMSettingWimax;
typedef struct _NMSettingWired NMSettingWired;
typedef struct _NMSettingWireless NMSettingWireless;
typedef struct _NMSettingWirelessSecurity NMSettingWirelessSecurity;
typedef struct _NMSettingWpan NMSettingWpan;
typedef struct _NMSimpleConnection NMSimpleConnection;
#endif /* __NM_CORE_TYPES_H__ */

View file

@ -0,0 +1,273 @@
/*
* 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 Lubomir Rintel <lkundrak@v3.sk>
*/
#include "nm-default.h"
#include "nm-setting-wpan.h"
#include "nm-connection-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
#include "nm-utils-private.h"
/* Ideally we'll be able to get this from a public header. */
#ifndef IEEE802154_ADDR_LEN
#define IEEE802154_ADDR_LEN 8
#endif
enum {
PROP_0,
PROP_MAC_ADDRESS,
PROP_PAN_ID,
PROP_SHORT_ADDRESS,
};
typedef struct {
char *mac_address;
guint16 pan_id;
guint16 short_address;
} NMSettingWpanPrivate;
/**
* NMSettingWpan:
*
* IEEE 802.15.4 (WPAN) MAC Settings
*/
struct _NMSettingWpan {
NMSetting parent;
};
typedef struct {
NMSettingClass parent;
} NMSettingWpanClass;
/**
* SECTION:nm-setting-wpan
* @short_description: Describes connection properties for IEEE 802.15.4 (WPAN) MAC
*
* The #NMSettingWpan object is a #NMSetting subclass that describes properties
* necessary for configuring IEEE 802.15.4 (WPAN) MAC layer devices.
**/
G_DEFINE_TYPE_WITH_CODE (NMSettingWpan, nm_setting_wpan, NM_TYPE_SETTING,
_nm_register_setting (WPAN, NM_SETTING_PRIORITY_HW_BASE))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WPAN)
#define NM_SETTING_WPAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WPAN, NMSettingWpanPrivate))
/**
* nm_setting_wpan_get_mac_address:
* @setting: the #NMSettingWpan
*
* Returns: the #NMSettingWpan:mac-address property of the setting
*
* Since: 1.14
**/
const char *
nm_setting_wpan_get_mac_address (NMSettingWpan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WPAN (setting), NULL);
return NM_SETTING_WPAN_GET_PRIVATE (setting)->mac_address;
}
/**
* nm_setting_wpan_get_pan_id:
* @setting: the #NMSettingWpan
*
* Returns: the #NMSettingWpan:pan-id property of the setting
*
* Since: 1.14
**/
guint16
nm_setting_wpan_get_pan_id (NMSettingWpan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WPAN (setting), G_MAXUINT16);
return NM_SETTING_WPAN_GET_PRIVATE (setting)->pan_id;
}
/**
* nm_setting_wpan_get_short_address:
* @setting: the #NMSettingWpan
*
* Returns: the #NMSettingWpan:short-address property of the setting
*
* Since: 1.14
**/
guint16
nm_setting_wpan_get_short_address (NMSettingWpan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WPAN (setting), G_MAXUINT16);
return NM_SETTING_WPAN_GET_PRIVATE (setting)->short_address;
}
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE (setting);
if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, IEEE802154_ADDR_LEN)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_WPAN_SETTING_NAME, NM_SETTING_WPAN_MAC_ADDRESS);
return FALSE;
}
return TRUE;
}
static void
get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
NMSettingWpan *setting = NM_SETTING_WPAN (object);
switch (prop_id) {
case PROP_MAC_ADDRESS:
g_value_set_string (value, nm_setting_wpan_get_mac_address (setting));
break;
case PROP_PAN_ID:
g_value_set_uint (value, nm_setting_wpan_get_pan_id (setting));
break;
case PROP_SHORT_ADDRESS:
g_value_set_uint (value, nm_setting_wpan_get_short_address (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE (object);
switch (prop_id) {
case PROP_MAC_ADDRESS:
g_free (priv->mac_address);
priv->mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
IEEE802154_ADDR_LEN);
break;
case PROP_PAN_ID:
priv->pan_id = g_value_get_uint (value);
break;
case PROP_SHORT_ADDRESS:
priv->short_address = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_wpan_init (NMSettingWpan *setting)
{
NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE (setting);
priv->short_address = G_MAXUINT16;
priv->pan_id = G_MAXUINT16;
}
/**
* nm_setting_wpan_new:
*
* Creates a new #NMSettingWpan object with default values.
*
* Returns: (transfer full): the new empty #NMSettingWpan object
*
* Since: 1.14
**/
NMSetting *
nm_setting_wpan_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_WPAN, NULL);
}
static void
finalize (GObject *object)
{
NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE (object);
g_free (priv->mac_address);
G_OBJECT_CLASS (nm_setting_wpan_parent_class)->finalize (object);
}
static void
nm_setting_wpan_class_init (NMSettingWpanClass *setting_wpan_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_wpan_class);
NMSettingClass *setting_class = NM_SETTING_CLASS (setting_wpan_class);
g_type_class_add_private (setting_class, sizeof (NMSettingWpanPrivate));
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
setting_class->verify = verify;
/**
* NMSettingWpan:mac-address:
*
* If specified, this connection will only apply to the IEEE 802.15.4 (WPAN)
* MAC layer device whose permanent MAC address matches.
**/
/* ---keyfile---
* property: mac-address
* format: usual hex-digits-and-colons notation
* description: MAC address in hex-digits-and-colons notation
* (e.g. 76:d8:9b:87:66:60:84:ee).
* ---end---
*/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
g_param_spec_string (NM_SETTING_WPAN_MAC_ADDRESS, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingWpan:pan-id:
*
* IEEE 802.15.4 Personal Area Network (PAN) identifier.
**/
g_object_class_install_property
(object_class, PROP_PAN_ID,
g_param_spec_uint (NM_SETTING_WPAN_PAN_ID, "", "",
0, G_MAXUINT16, G_MAXUINT16,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingWpan:short-address:
*
* Short IEEE 802.15.4 address to be used within a restricted environment.
**/
g_object_class_install_property
(object_class, PROP_SHORT_ADDRESS,
g_param_spec_uint (NM_SETTING_WPAN_SHORT_ADDRESS, "", "",
0, G_MAXUINT16, G_MAXUINT16,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View file

@ -0,0 +1,57 @@
/*
* 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 Lubomir Rintel <lkundrak@v3.sk>
*/
#ifndef __NM_SETTING_WPAN_H__
#define __NM_SETTING_WPAN_H__
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
#error "Only <NetworkManager.h> can be included directly."
#endif
#include "nm-setting.h"
G_BEGIN_DECLS
#define NM_TYPE_SETTING_WPAN (nm_setting_wpan_get_type ())
#define NM_SETTING_WPAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_WPAN, NMSettingWpan))
#define NM_SETTING_WPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_WPANCONFIG, NMSettingWpanClass))
#define NM_IS_SETTING_WPAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_WPAN))
#define NM_IS_SETTING_WPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_WPAN))
#define NM_SETTING_WPAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_WPAN, NMSettingWpanClass))
#define NM_SETTING_WPAN_SETTING_NAME "wpan"
#define NM_SETTING_WPAN_MAC_ADDRESS "mac-address"
#define NM_SETTING_WPAN_PAN_ID "pan-id"
#define NM_SETTING_WPAN_SHORT_ADDRESS "short-address"
NM_AVAILABLE_IN_1_14
GType nm_setting_wpan_get_type (void);
NM_AVAILABLE_IN_1_14
NMSetting *nm_setting_wpan_new (void);
NM_AVAILABLE_IN_1_14
const char *nm_setting_wpan_get_mac_address (NMSettingWpan *setting);
NM_AVAILABLE_IN_1_14
guint16 nm_setting_wpan_get_pan_id (NMSettingWpan *setting);
NM_AVAILABLE_IN_1_14
guint16 nm_setting_wpan_get_short_address (NMSettingWpan *setting);
G_END_DECLS
#endif /* __NM_SETTING_WPAN_H__ */

View file

@ -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 2008 - 2011 Red Hat, Inc.
* Copyright 2008 - 2018 Red Hat, Inc.
*
*/
@ -61,6 +61,7 @@
#include "nm-setting-wired.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-wpan.h"
#include "nm-simple-connection.h"
#include "nm-keyfile-internal.h"
#include "nm-utils/nm-dedup-multi.h"

View file

@ -15,7 +15,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2014 - 2017 Red Hat, Inc.
* Copyright 2014 - 2018 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_H__
@ -98,6 +98,7 @@
#include "nm-setting-wired.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-wpan.h"
#include "nm-setting.h"
#include "nm-simple-connection.h"
#include "nm-utils.h"

View file

@ -1365,6 +1365,7 @@ global:
nm_setting_wireless_security_fils_get_type;
nm_setting_wireless_get_wake_on_wlan;
nm_setting_wireless_wake_on_wlan_get_type;
nm_setting_wpan_get_type;
nm_settings_connection_flags_get_type;
nm_utils_get_timestamp_msec;
nm_vpn_service_plugin_shutdown;

View file

@ -94,6 +94,7 @@ libnm-core/nm-setting-wimax.c
libnm-core/nm-setting-wired.c
libnm-core/nm-setting-wireless-security.c
libnm-core/nm-setting-wireless.c
libnm-core/nm-setting-wpan.c
libnm-core/nm-setting.c
libnm-core/nm-utils.c
libnm-core/nm-vpn-editor-plugin.c