1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2011 - 2012 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-setting-connection.h"
26 #include "nm-setting-infiniband.h"
29 #include "nm-device-infiniband.h"
30 #include "nm-device-private.h"
31 #include "nm-object-private.h"
33 G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE)
35 #define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate))
40 } NMDeviceInfinibandPrivate;
51 * nm_device_infiniband_get_hw_address:
52 * @device: a #NMDeviceInfiniband
54 * Gets the hardware (MAC) address of the #NMDeviceInfiniband
56 * Returns: the hardware address. This is the internal string used by the
57 * device, and must not be modified.
60 nm_device_infiniband_get_hw_address (NMDeviceInfiniband *device)
62 g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), NULL);
64 return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address;
68 * nm_device_infiniband_get_carrier:
69 * @device: a #NMDeviceInfiniband
71 * Whether the device has carrier.
73 * Returns: %TRUE if the device has carrier
76 nm_device_infiniband_get_carrier (NMDeviceInfiniband *device)
78 g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), FALSE);
80 return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->carrier;
84 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
86 NMSettingInfiniband *s_infiniband;
87 const char *hwaddr, *setting_hwaddr;
89 if (!NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->connection_compatible (device, connection, error))
92 if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) {
93 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
94 _("The connection was not an InfiniBand connection."));
98 hwaddr = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
100 if (!nm_utils_hwaddr_valid (hwaddr, INFINIBAND_ALEN)) {
101 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
102 _("Invalid device MAC address."));
106 s_infiniband = nm_connection_get_setting_infiniband (connection);
107 setting_hwaddr = nm_setting_infiniband_get_mac_address (s_infiniband);
108 if (setting_hwaddr && !nm_utils_hwaddr_matches (setting_hwaddr, -1, hwaddr, -1)) {
109 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
110 _("The MACs of the device and the connection didn't match."));
119 get_setting_type (NMDevice *device)
121 return NM_TYPE_SETTING_INFINIBAND;
125 get_hw_address (NMDevice *device)
127 return nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
130 /***********************************************************/
133 nm_device_infiniband_init (NMDeviceInfiniband *device)
135 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_INFINIBAND);
139 init_dbus (NMObject *object)
141 NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object);
142 const NMPropertiesInfo property_info[] = {
143 { NM_DEVICE_INFINIBAND_HW_ADDRESS, &priv->hw_address },
144 { NM_DEVICE_INFINIBAND_CARRIER, &priv->carrier },
148 NM_OBJECT_CLASS (nm_device_infiniband_parent_class)->init_dbus (object);
150 _nm_object_register_properties (object,
151 NM_DBUS_INTERFACE_DEVICE_INFINIBAND,
156 finalize (GObject *object)
158 NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object);
160 g_free (priv->hw_address);
162 G_OBJECT_CLASS (nm_device_infiniband_parent_class)->finalize (object);
166 get_property (GObject *object,
171 NMDeviceInfiniband *device = NM_DEVICE_INFINIBAND (object);
174 case PROP_HW_ADDRESS:
175 g_value_set_string (value, nm_device_infiniband_get_hw_address (device));
178 g_value_set_boolean (value, nm_device_infiniband_get_carrier (device));
181 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
187 nm_device_infiniband_class_init (NMDeviceInfinibandClass *ib_class)
189 GObjectClass *object_class = G_OBJECT_CLASS (ib_class);
190 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ib_class);
191 NMDeviceClass *device_class = NM_DEVICE_CLASS (ib_class);
193 g_type_class_add_private (ib_class, sizeof (NMDeviceInfinibandPrivate));
195 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_INFINIBAND);
197 /* virtual methods */
198 object_class->finalize = finalize;
199 object_class->get_property = get_property;
201 nm_object_class->init_dbus = init_dbus;
203 device_class->connection_compatible = connection_compatible;
204 device_class->get_setting_type = get_setting_type;
205 device_class->get_hw_address = get_hw_address;
210 * NMDeviceInfiniband:hw-address:
212 * The hardware (MAC) address of the device.
214 g_object_class_install_property
215 (object_class, PROP_HW_ADDRESS,
216 g_param_spec_string (NM_DEVICE_INFINIBAND_HW_ADDRESS, "", "",
219 G_PARAM_STATIC_STRINGS));
222 * NMDeviceInfiniband:carrier:
224 * Whether the device has carrier.
226 g_object_class_install_property
227 (object_class, PROP_CARRIER,
228 g_param_spec_boolean (NM_DEVICE_INFINIBAND_CARRIER, "", "",
231 G_PARAM_STATIC_STRINGS));