Commit a11067f5 authored by Jiří Klimeš's avatar Jiří Klimeš

libnm-glib: add errors to device classes and nm_device_connection_compatible()

Add nm_device_connection_compatible() that returns an error when it fails.
nm_device_connection_valid() does the same work except it doesn't set GError.
parent 43ba4eb0
......@@ -1233,11 +1233,11 @@ find_device_for_connection (NmCli *nmc,
if (iface) {
const char *dev_iface = nm_device_get_iface (dev);
if ( !strcmp (dev_iface, iface)
&& nm_device_connection_valid (dev, connection)) {
&& nm_device_connection_compatible (dev, connection, NULL)) {
found_device = dev;
}
} else {
if (nm_device_connection_valid (dev, connection)) {
if (nm_device_connection_compatible (dev, connection, NULL)) {
found_device = dev;
}
}
......
......@@ -58,17 +58,24 @@ global:
nm_client_wwan_get_enabled;
nm_client_wwan_hardware_get_enabled;
nm_client_wwan_set_enabled;
nm_device_bond_error_get_type;
nm_device_bond_error_quark;
nm_device_bond_get_carrier;
nm_device_bond_get_hw_address;
nm_device_bond_get_type;
nm_device_bond_new;
nm_device_bt_error_get_type;
nm_device_bt_error_quark;
nm_device_bt_get_capabilities;
nm_device_bt_get_hw_address;
nm_device_bt_get_name;
nm_device_bt_get_type;
nm_device_bt_new;
nm_device_connection_compatible;
nm_device_connection_valid;
nm_device_disconnect;
nm_device_ethernet_error_get_type;
nm_device_ethernet_error_quark;
nm_device_ethernet_get_carrier;
nm_device_ethernet_get_hw_address;
nm_device_ethernet_get_permanent_hw_address;
......@@ -94,24 +101,34 @@ global:
nm_device_get_type;
nm_device_get_udi;
nm_device_get_vendor;
nm_device_infiniband_error_get_type;
nm_device_infiniband_error_quark;
nm_device_infiniband_get_carrier;
nm_device_infiniband_get_hw_address;
nm_device_infiniband_get_type;
nm_device_infiniband_new;
nm_device_modem_error_get_type;
nm_device_modem_error_quark;
nm_device_modem_get_current_capabilities;
nm_device_modem_get_modem_capabilities;
nm_device_modem_get_type;
nm_device_new;
nm_device_olpc_mesh_error_get_type;
nm_device_olpc_mesh_error_quark;
nm_device_olpc_mesh_get_active_channel;
nm_device_olpc_mesh_get_companion;
nm_device_olpc_mesh_get_hw_address;
nm_device_olpc_mesh_get_type;
nm_device_olpc_mesh_new;
nm_device_vlan_error_get_type;
nm_device_vlan_error_quark;
nm_device_vlan_get_carrier;
nm_device_vlan_get_hw_address;
nm_device_vlan_get_type;
nm_device_vlan_get_vlan_id;
nm_device_vlan_new;
nm_device_wifi_error_get_type;
nm_device_wifi_error_quark;
nm_device_wifi_get_access_point_by_path;
nm_device_wifi_get_access_points;
nm_device_wifi_get_active_access_point;
......@@ -122,6 +139,8 @@ global:
nm_device_wifi_get_permanent_hw_address;
nm_device_wifi_get_type;
nm_device_wifi_new;
nm_device_wimax_error_get_type;
nm_device_wimax_error_quark;
nm_device_wimax_get_active_nsp;
nm_device_wimax_get_bsid;
nm_device_wimax_get_center_frequency;
......
......@@ -17,8 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
* Copyright (C) 2012 Red Hat, Inc.
*/
#include <config.h>
......@@ -55,6 +54,23 @@ enum {
#define DBUS_PROP_HW_ADDRESS "HwAddress"
#define DBUS_PROP_CARRIER "Carrier"
/**
* nm_device_bond_error_quark:
*
* Registers an error quark for #NMDeviceBond if necessary.
*
* Returns: the error quark used for #NMDeviceBond errors.
**/
GQuark
nm_device_bond_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-bond-error-quark");
return quark;
}
/**
* nm_device_bond_new:
* @connection: the #DBusGConnection
......@@ -116,27 +132,38 @@ nm_device_bond_get_carrier (NMDeviceBond *device)
}
static gboolean
connection_valid (NMDevice *device, NMConnection *connection)
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingBond *s_bond;
const char *ctype, *dev_iface_name, *bond_iface_name;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_BOND_SETTING_NAME) != 0)
if (strcmp (ctype, NM_SETTING_BOND_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_BOND_ERROR, NM_DEVICE_BOND_ERROR_NOT_BOND_CONNECTION,
"The connection was not a bond connection.");
return FALSE;
}
s_bond = nm_connection_get_setting_bond (connection);
if (!s_bond)
if (!s_bond) {
g_set_error (error, NM_DEVICE_BOND_ERROR, NM_DEVICE_BOND_ERROR_INVALID_BOND_CONNECTION,
"The connection was not a valid bond connection.");
return FALSE;
}
dev_iface_name = nm_device_get_iface (device);
bond_iface_name = nm_setting_bond_get_interface_name (s_bond);
if (g_strcmp0 (dev_iface_name, bond_iface_name) != 0)
if (g_strcmp0 (dev_iface_name, bond_iface_name) != 0) {
g_set_error (error, NM_DEVICE_BOND_ERROR, NM_DEVICE_BOND_ERROR_INTERFACE_MISMATCH,
"The interfaces of the device and the connection didn't match.");
return FALSE;
}
/* FIXME: check slaves? But we can't... */
......@@ -240,7 +267,7 @@ nm_device_bond_class_init (NMDeviceBondClass *eth_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_valid = connection_valid;
device_class->connection_compatible = connection_compatible;
/* properties */
......
......@@ -17,8 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
* Copyright (C) 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_BOND_H
......@@ -35,6 +34,23 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_BOND))
#define NM_DEVICE_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BOND, NMDeviceBondClass))
/**
* NMDeviceBondError:
* @NM_DEVICE_BOND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_BOND_ERROR_NOT_BOND_CONNECTION: the connection was not of bond type
* @NM_DEVICE_BOND_ERROR_INVALID_BOND_CONNECTION: the bond connection was invalid
* @NM_DEVICE_BOND_ERROR_INTERFACE_MISMATCH: the interfaces of the connection and the device mismatched
*/
typedef enum {
NM_DEVICE_BOND_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_BOND_ERROR_NOT_BOND_CONNECTION, /*< nick=NotBondConnection >*/
NM_DEVICE_BOND_ERROR_INVALID_BOND_CONNECTION, /*< nick=InvalidBondConnection >*/
NM_DEVICE_BOND_ERROR_INTERFACE_MISMATCH, /*< nick=InterfaceMismatch >*/
} NMDeviceBondError;
#define NM_DEVICE_BOND_ERROR nm_device_bond_error_quark ()
GQuark nm_device_bond_error_quark (void);
#define NM_DEVICE_BOND_HW_ADDRESS "hw-address"
#define NM_DEVICE_BOND_CARRIER "carrier"
......
......@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
* Copyright (C) 2007 - 2012 Red Hat, Inc.
*/
#include <config.h>
......@@ -59,6 +59,23 @@ enum {
#define DBUS_PROP_NAME "Name"
#define DBUS_PROP_BT_CAPABILITIES "BtCapabilities"
/**
* nm_device_bt_error_quark:
*
* Registers an error quark for #NMDeviceBt if necessary.
*
* Returns: the error quark used for #NMDeviceBt errors.
**/
GQuark
nm_device_bt_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-bt-error-quark");
return quark;
}
/**
* nm_device_bt_new:
* @connection: the #DBusGConnection
......@@ -154,7 +171,7 @@ get_connection_bt_type (NMConnection *connection)
}
static gboolean
connection_valid (NMDevice *device, NMConnection *connection)
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingBluetooth *s_bt;
......@@ -165,30 +182,49 @@ connection_valid (NMDevice *device, NMConnection *connection)
NMBluetoothCapabilities dev_caps;
NMBluetoothCapabilities bt_type;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME) != 0)
if (strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION,
"The connection was not a Bluetooth connection.");
return FALSE;
}
s_bt = nm_connection_get_setting_bluetooth (connection);
if (!s_bt)
if (!s_bt) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION,
"The connection was not a valid Bluetooth connection.");
return FALSE;
}
/* Check BT address */
hw_str = nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
if (hw_str) {
hw_mac = ether_aton (hw_str);
if (!hw_mac) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_bluetooth_get_bdaddr (s_bt);
if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN))
if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match.");
return FALSE;
}
}
dev_caps = nm_device_bt_get_capabilities (NM_DEVICE_BT (device));
bt_type = get_connection_bt_type (connection);
if (!(bt_type & dev_caps))
if (!(bt_type & dev_caps)) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS,
"The device missed BT capabilities required by the connection.");
return FALSE;
}
return TRUE;
}
......@@ -296,7 +332,7 @@ nm_device_bt_class_init (NMDeviceBtClass *bt_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_valid = connection_valid;
device_class->connection_compatible = connection_compatible;
/* properties */
......
......@@ -17,7 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 - 2009 Red Hat, Inc.
* Copyright (C) 2008 - 2012 Red Hat, Inc.
* Copyright (C) 2008 Novell, Inc.
*/
......@@ -36,6 +36,27 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_BT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_BT))
#define NM_DEVICE_BT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BT, NMDeviceBtClass))
/**
* NMDeviceBtError:
* @NM_DEVICE_BT_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION: the connection was not of bluetooth type
* @NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION: the bluetooth connection was invalid
* @NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC: the device's MAC was invalid
* @NM_DEVICE_BT_ERROR_MAC_MISMATCH: the MACs of the connection and the device mismatched
* @NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS: the device missed required capabilities
*/
typedef enum {
NM_DEVICE_BT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION, /*< nick=NotBtConnection >*/
NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION, /*< nick=InvalidBtConnection >*/
NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC, /*< nick=InvalidDeviceMac >*/
NM_DEVICE_BT_ERROR_MAC_MISMATCH, /*< nick=MacMismatch >*/
NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS, /*< nick=MissingDeviceCaps >*/
} NMDeviceBtError;
#define NM_DEVICE_BT_ERROR nm_device_bt_error_quark ()
GQuark nm_device_bt_error_quark (void);
#define NM_DEVICE_BT_HW_ADDRESS "hw-address"
#define NM_DEVICE_BT_NAME "name"
#define NM_DEVICE_BT_CAPABILITIES "bt-capabilities"
......
......@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
* Copyright (C) 2007 - 2012 Red Hat, Inc.
*/
#include <config.h>
......@@ -63,6 +63,23 @@ enum {
#define DBUS_PROP_SPEED "Speed"
#define DBUS_PROP_CARRIER "Carrier"
/**
* nm_device_ethernet_error_quark:
*
* Registers an error quark for #NMDeviceEthernet if necessary.
*
* Returns: the error quark used for #NMDeviceEthernet errors.
**/
GQuark
nm_device_ethernet_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-ethernet-error-quark");
return quark;
}
/**
* nm_device_ethernet_new:
* @connection: the #DBusGConnection
......@@ -159,26 +176,34 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device)
}
static gboolean
connection_valid (NMDevice *device, NMConnection *connection)
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingWired *s_wired;
const char *ctype;
gboolean is_pppoe = FALSE;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (!strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
is_pppoe = TRUE;
else if (strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) != 0)
else if (strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION,
"The connection was not a wired or PPPoE connection.");
return FALSE;
}
s_wired = nm_connection_get_setting_wired (connection);
/* Wired setting optional for PPPoE */
if (!is_pppoe && !s_wired)
if (!is_pppoe && !s_wired) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION,
"The connection was not a valid ethernet connection.");
return FALSE;
}
if (s_wired) {
const GByteArray *mac;
......@@ -191,9 +216,17 @@ connection_valid (NMDevice *device, NMConnection *connection)
perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
if (perm_str) {
perm_mac = ether_aton (perm_str);
if (!perm_mac) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_wired_get_mac_address (s_wired);
if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN))
if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match.");
return FALSE;
}
}
}
......@@ -310,7 +343,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_valid = connection_valid;
device_class->connection_compatible = connection_compatible;
/* properties */
......
......@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_ETHERNET_H
......@@ -35,6 +35,25 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_ETHERNET))
#define NM_DEVICE_ETHERNET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetClass))
/**
* NMDeviceEthernetError:
* @NM_DEVICE_ETHERNET_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION: the connection was not of ethernet or PPPoE type
* @NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION: the ethernet connection was invalid
* @NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC: the device's MAC was invalid
* @NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH: the MACs of the connection and the device mismatched
*/
typedef enum {
NM_DEVICE_ETHERNET_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION, /*< nick=NotEthernetConnection >*/
NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION, /*< nick=InvalidEthernetConnection >*/
NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC, /*< nick=InvalidDeviceMac >*/
NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH, /*< nick=MacMismatch >*/
} NMDeviceEthernetError;
#define NM_DEVICE_ETHERNET_ERROR nm_device_ethernet_error_quark ()
GQuark nm_device_ethernet_error_quark (void);
#define NM_DEVICE_ETHERNET_HW_ADDRESS "hw-address"
#define NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS "perm-hw-address"
#define NM_DEVICE_ETHERNET_SPEED "speed"
......
......@@ -17,8 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
* Copyright (C) 2011 - 2012 Red Hat, Inc.
*/
#include <config.h>
......@@ -56,6 +55,23 @@ enum {
#define DBUS_PROP_HW_ADDRESS "HwAddress"
#define DBUS_PROP_CARRIER "Carrier"
/**
* nm_device_infiniband_error_quark:
*
* Registers an error quark for #NMDeviceInfiniband if necessary.
*
* Returns: the error quark used for #NMDeviceInfiniband errors.
**/
GQuark
nm_device_infiniband_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-infiniband-error-quark");
return quark;
}
/**
* nm_device_infiniband_new:
* @connection: the #DBusGConnection
......@@ -117,7 +133,7 @@ nm_device_infiniband_get_carrier (NMDeviceInfiniband *device)
}
static gboolean
connection_valid (NMDevice *device, NMConnection *connection)
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingInfiniband *s_infiniband;
......@@ -125,23 +141,39 @@ connection_valid (NMDevice *device, NMConnection *connection)
const GByteArray *mac;
guint8 *hwaddr, hwaddr_buf[INFINIBAND_ALEN];
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_INFINIBAND_SETTING_NAME) != 0)
if (strcmp (ctype, NM_SETTING_INFINIBAND_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION,
"The connection was not a InfiniBand connection.");
return FALSE;
}
s_infiniband = nm_connection_get_setting_infiniband (connection);
if (!s_infiniband)
if (!s_infiniband) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION,
"The connection was not a valid InfiniBand connection.");
return FALSE;
}
hwaddr_str = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
if (hwaddr_str) {
hwaddr = nm_utils_hwaddr_aton (hwaddr_str, ARPHRD_INFINIBAND, hwaddr_buf);
if (!hwaddr) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
if (mac && hwaddr && memcmp (mac->data, hwaddr, INFINIBAND_ALEN))
if (mac && hwaddr && memcmp (mac->data, hwaddr, INFINIBAND_ALEN)) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match.");
return FALSE;
}
}
return TRUE;
......@@ -244,7 +276,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *eth_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_valid = connection_valid;
device_class->connection_compatible = connection_compatible;
/* properties */
......
......@@ -17,8 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
* Copyright (C) 2011 - 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_INFINIBAND_H
......@@ -35,6 +34,25 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_INFINIBAND))
#define NM_DEVICE_INFINIBAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandClass))
/**
* NMDeviceInfinibandError:
* @NM_DEVICE_INFINIBAND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION: the connection was not of InfiniBand type
* @NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION: the InfiniBand connection was invalid
* @NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC: the device's MAC was invalid
* @NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH: the MACs of the connection and the device mismatched
*/
typedef enum {
NM_DEVICE_INFINIBAND_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION, /*< nick=NotInfinibandConnection >*/
NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION, /*< nick=InvalidInfinibandConnection >*/
NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC, /*< nick=InvalidDeviceMac >*/
NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH, /*< nick=MacMismatch >*/
} NMDeviceInfinibandError;
#define NM_DEVICE_INFINIBAND_ERROR nm_device_infiniband_error_quark ()
GQuark nm_device_infiniband_error_quark (void);
#define NM_DEVICE_INFINIBAND_HW_ADDRESS "hw-address"
#define NM_DEVICE_INFINIBAND_CARRIER "carrier"
......
......@@ -17,7 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2011 Red Hat, Inc.
* Copyright (C) 2011 - 2012 Red Hat, Inc.
* Copyright (C) 2008 Novell, Inc.
*/
......@@ -58,6 +58,23 @@ enum {
#define DBUS_PROP_MODEM_CAPS "ModemCapabilities"
#define DBUS_PROP_CURRENT_CAPS "CurrentCapabilities"
/**
* nm_device_modem_error_quark:
*
* Registers an error quark for #NMDeviceModem if necessary.
*
* Returns: the error quark used for #NMDeviceModem errors.
**/
GQuark