[network-manager-applet] connection-editor: add InfiniBand support



commit 2b2e5975481fb10a8a220b9952279600f069c497
Author: Dan Winship <danw gnome org>
Date:   Wed Mar 7 09:58:06 2012 -0500

    connection-editor: add InfiniBand support
    
    As part of this, make the CEPage MAC addr utilities support both
    ethernet and infiniband MACs.

 po/POTFILES.in                               |    2 +
 src/connection-editor/Makefile.am            |    3 +
 src/connection-editor/ce-page-infiniband.ui  |  154 ++++++++++++
 src/connection-editor/ce-page.c              |   60 ++----
 src/connection-editor/ce-page.h              |    7 +-
 src/connection-editor/new-connection.c       |    7 +
 src/connection-editor/nm-connection-editor.c |    9 +
 src/connection-editor/nm-connection-list.c   |    2 +
 src/connection-editor/page-infiniband.c      |  326 ++++++++++++++++++++++++++
 src/connection-editor/page-infiniband.h      |   61 +++++
 src/connection-editor/page-wimax.c           |    4 +-
 src/connection-editor/page-wired.c           |   11 +-
 src/connection-editor/page-wireless.c        |   18 +-
 13 files changed, 602 insertions(+), 62 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 018c9c8..ac2b057 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -20,6 +20,7 @@ src/connection-editor/ce-page.c
 [type: gettext/glade]src/connection-editor/ce-ip4-routes.ui
 [type: gettext/glade]src/connection-editor/ce-ip6-routes.ui
 [type: gettext/glade]src/connection-editor/ce-page-dsl.ui
+[type: gettext/glade]src/connection-editor/ce-page-infiniband.ui
 [type: gettext/glade]src/connection-editor/ce-page-ip4.ui
 [type: gettext/glade]src/connection-editor/ce-page-ip6.ui
 [type: gettext/glade]src/connection-editor/ce-page-mobile.ui
@@ -34,6 +35,7 @@ src/connection-editor/ip4-routes-dialog.c
 src/connection-editor/ip6-routes-dialog.c
 src/connection-editor/new-connection.c
 src/connection-editor/page-dsl.c
+src/connection-editor/page-infiniband.c
 src/connection-editor/page-ip4.c
 src/connection-editor/page-ip6.c
 src/connection-editor/page-mobile.c
diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am
index c54db06..f22c9f9 100644
--- a/src/connection-editor/Makefile.am
+++ b/src/connection-editor/Makefile.am
@@ -36,6 +36,8 @@ nm_connection_editor_SOURCES = \
 	page-wireless-security.c \
 	page-wimax.h \
 	page-wimax.c \
+	page-infiniband.h \
+	page-infiniband.c \
 	page-ip4.h \
 	page-ip4.c \
 	page-ip6.h \
@@ -81,6 +83,7 @@ ui_DATA = \
 	ce-page-wireless.ui \
 	ce-page-wireless-security.ui \
 	ce-page-wimax.ui \
+	ce-page-infiniband.ui \
 	ce-page-ip4.ui \
 	ce-ip4-routes.ui \
 	ce-page-ip6.ui \
diff --git a/src/connection-editor/ce-page-infiniband.ui b/src/connection-editor/ce-page-infiniband.ui
new file mode 100644
index 0000000..30548fa
--- /dev/null
+++ b/src/connection-editor/ce-page-infiniband.ui
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <object class="GtkTable" id="InfinibandPage">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="n_rows">3</property>
+    <property name="n_columns">2</property>
+    <property name="column_spacing">12</property>
+    <property name="row_spacing">6</property>
+    <child>
+      <object class="GtkLabel" id="infiniband_mode_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Transport mode:</property>
+        <property name="use_underline">True</property>
+      </object>
+      <packing>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="infiniband_device_mac_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Device MAC address:</property>
+        <property name="use_underline">True</property>
+      </object>
+      <packing>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkAlignment" id="infiniband_device_mac_alignment">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkComboBox" id="infiniband_mode">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="model">infiniband_mode_model</property>
+        <child>
+          <object class="GtkCellRendererText" id="renderer1"/>
+          <attributes>
+            <attribute name="text">0</attribute>
+          </attributes>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options">GTK_FILL</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkHBox" id="hbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkSpinButton" id="infiniband_mtu">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="invisible_char">â</property>
+            <property name="invisible_char_set">True</property>
+            <property name="adjustment">adjustment1</property>
+            <property name="climb_rate">1</property>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label29">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">bytes</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options">GTK_FILL</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="infiniband_mtu_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_MTU:</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">infiniband_mtu</property>
+      </object>
+      <packing>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+  </object>
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="upper">65520</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkListStore" id="infiniband_mode_model">
+    <columns>
+      <!-- column-name mode -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes" comments="IP-over-Infiniband &quot;datagram mode&quot;">Datagram</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes" comments="IP-over-Infiniband &quot;connected mode&quot;">Connected</col>
+      </row>
+    </data>
+  </object>
+</interface>
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index 44806d7..f9b73a6 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -136,9 +136,8 @@ ce_page_get_mac_list (CEPage *self)
 }
 
 void
-ce_page_mac_to_entry (const GByteArray *mac, GtkEntry *entry)
+ce_page_mac_to_entry (const GByteArray *mac, int type, GtkEntry *entry)
 {
-	struct ether_addr addr;
 	char *str_addr;
 
 	g_return_if_fail (entry != NULL);
@@ -147,51 +146,17 @@ ce_page_mac_to_entry (const GByteArray *mac, GtkEntry *entry)
 	if (!mac || !mac->len)
 		return;
 
-	memcpy (addr.ether_addr_octet, mac->data, ETH_ALEN);
-	/* we like leading zeros and all-caps, instead
-	 * of what glibc's ether_ntop() gives us
-	 */
-	str_addr = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
-	                            addr.ether_addr_octet[0], addr.ether_addr_octet[1],
-	                            addr.ether_addr_octet[2], addr.ether_addr_octet[3],
-	                            addr.ether_addr_octet[4], addr.ether_addr_octet[5]);
+	if (mac->len != nm_utils_hwaddr_len (type))
+		return;
+
+	str_addr = nm_utils_hwaddr_ntoa (mac->data, type);
 	gtk_entry_set_text (entry, str_addr);
 	g_free (str_addr);
 }
 
-static gboolean
-is_mac_valid (const struct ether_addr *addr)
-{
-	guint8 invalid1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-	guint8 invalid2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-	guint8 invalid3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
-	guint8 invalid4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
-
-	g_return_val_if_fail (addr != NULL, FALSE);
-
-	/* Compare the AP address the card has with invalid ethernet MAC addresses. */
-	if (!memcmp (addr->ether_addr_octet, &invalid1, ETH_ALEN))
-		return FALSE;
-
-	if (!memcmp (addr->ether_addr_octet, &invalid2, ETH_ALEN))
-		return FALSE;
-
-	if (!memcmp (addr->ether_addr_octet, &invalid3, ETH_ALEN))
-		return FALSE;
-
-	if (!memcmp (addr->ether_addr_octet, &invalid4, ETH_ALEN))
-		return FALSE;
-
-	if (addr->ether_addr_octet[0] & 1) /* Multicast addresses */
-		return FALSE;
-
-	return TRUE;
-}
-
 GByteArray *
-ce_page_entry_to_mac (GtkEntry *entry, gboolean *invalid)
+ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid)
 {
-	struct ether_addr *ether;
 	const char *temp;
 	GByteArray *mac;
 
@@ -205,15 +170,20 @@ ce_page_entry_to_mac (GtkEntry *entry, gboolean *invalid)
 	if (!temp || !strlen (temp))
 		return NULL;
 
-	ether = ether_aton (temp);
-	if (!ether || !is_mac_valid (ether)) {
+	mac = nm_utils_hwaddr_atoba (temp, type);
+	if (!mac) {
+		if (invalid)
+			*invalid = TRUE;
+		return NULL;
+	}
+
+	if (type == ARPHRD_ETHER && !utils_ether_addr_valid ((struct ether_addr *)mac->data)) {
+		g_byte_array_free (mac, TRUE);
 		if (invalid)
 			*invalid = TRUE;
 		return NULL;
 	}
 
-	mac = g_byte_array_sized_new (ETH_ALEN);
-	g_byte_array_append (mac, (const guint8 *) ether->ether_addr_octet, ETH_ALEN);
 	return mac;
 }
 
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index 3ab04c4..cf09131 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -34,6 +34,9 @@
 #include <nm-remote-settings.h>
 #include "utils.h"
 
+/* for ARPHRD_ETHER / ARPHRD_INFINIBAND for MAC utilies */
+#include <net/if_arp.h>
+
 typedef void (*PageNewConnectionResultFunc) (NMConnection *connection,
                                              gboolean canceled,
                                              GError *error,
@@ -110,9 +113,9 @@ char **ce_page_get_mac_list (CEPage *self);
 
 void ce_page_changed (CEPage *self);
 
-void ce_page_mac_to_entry (const GByteArray *mac, GtkEntry *entry);
+void ce_page_mac_to_entry (const GByteArray *mac, int type, GtkEntry *entry);
 
-GByteArray *ce_page_entry_to_mac (GtkEntry *entry, gboolean *invalid);
+GByteArray *ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid);
 
 gint ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data);
 
diff --git a/src/connection-editor/new-connection.c b/src/connection-editor/new-connection.c
index 27afb44..a236b28 100644
--- a/src/connection-editor/new-connection.c
+++ b/src/connection-editor/new-connection.c
@@ -29,6 +29,7 @@
 #include "page-mobile.h"
 #include "page-wimax.h"
 #include "page-dsl.h"
+#include "page-infiniband.h"
 #include "page-vpn.h"
 #include "vpn-helpers.h"
 
@@ -114,6 +115,12 @@ get_connection_type_list (void)
 	data.setting_type = NM_TYPE_SETTING_PPPOE;
 	g_array_append_val (array, data);
 
+	data.name = _("InfiniBand");
+	ICON_LOAD (data.icon, "nm-device-wired");
+	data.new_connection_func = infiniband_connection_new;
+	data.setting_type = NM_TYPE_SETTING_INFINIBAND;
+	g_array_append_val (array, data);
+
 	/* Add "VPN" only if there are plugins */
 	vpn_plugins_hash = vpn_get_plugins (NULL);
 	have_vpn_plugins  = vpn_plugins_hash && g_hash_table_size (vpn_plugins_hash);
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 43d23ac..fb321c8 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -46,6 +46,7 @@
 #include <nm-setting-gsm.h>
 #include <nm-setting-cdma.h>
 #include <nm-setting-wimax.h>
+#include <nm-setting-infiniband.h>
 #include <nm-utils.h>
 
 #include <nm-remote-connection.h>
@@ -65,6 +66,7 @@
 #include "page-ppp.h"
 #include "page-vpn.h"
 #include "page-wimax.h"
+#include "page-infiniband.h"
 #include "ce-polkit-button.h"
 #include "vpn-helpers.h"
 
@@ -789,6 +791,13 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor,
 			goto out;
 		if (!add_page (editor, ce_page_ip6_new, editor->connection, error))
 			goto out;
+	} else if (!strcmp (connection_type, NM_SETTING_INFINIBAND_SETTING_NAME)) {
+		if (!add_page (editor, ce_page_infiniband_new, editor->connection, error))
+			goto out;
+		if (!add_page (editor, ce_page_ip4_new, editor->connection, error))
+			goto out;
+		if (!add_page (editor, ce_page_ip6_new, editor->connection, error))
+			goto out;
 	} else {
 		g_warning ("Unhandled setting type '%s'", connection_type);
 	}
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 5f8a8e2..0972985 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -43,6 +43,7 @@
 #include <nm-setting-ppp.h>
 #include <nm-setting-serial.h>
 #include <nm-setting-wimax.h>
+#include <nm-setting-infiniband.h>
 #include <nm-utils.h>
 #include <nm-remote-settings.h>
 
@@ -53,6 +54,7 @@
 #include "page-dsl.h"
 #include "page-vpn.h"
 #include "page-wimax.h"
+#include "page-infiniband.h"
 #include "nm-connection-editor.h"
 #include "nm-connection-list.h"
 #include "vpn-helpers.h"
diff --git a/src/connection-editor/page-infiniband.c b/src/connection-editor/page-infiniband.c
new file mode 100644
index 0000000..0845a60
--- /dev/null
+++ b/src/connection-editor/page-infiniband.c
@@ -0,0 +1,326 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2012 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include <nm-setting-connection.h>
+#include <nm-setting-infiniband.h>
+#include <nm-device-infiniband.h>
+#include <nm-utils.h>
+
+#include <net/if_arp.h>
+#include <linux/if_infiniband.h>
+
+#include "page-infiniband.h"
+
+G_DEFINE_TYPE (CEPageInfiniband, ce_page_infiniband, CE_TYPE_PAGE)
+
+#define CE_PAGE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_INFINIBAND, CEPageInfinibandPrivate))
+
+typedef struct {
+	NMSettingInfiniband *setting;
+
+#if GTK_CHECK_VERSION(2,24,0)
+	GtkComboBoxText *device_mac;  /* Permanent MAC of the device */
+#else
+	GtkComboBoxEntry *device_mac;
+#endif
+
+	GtkComboBox *transport_mode;
+	GtkSpinButton *mtu;
+} CEPageInfinibandPrivate;
+
+#define TRANSPORT_MODE_DATAGRAM  0
+#define TRANSPORT_MODE_CONNECTED 1
+
+static void
+infiniband_private_init (CEPageInfiniband *self)
+{
+	CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self);
+	GtkBuilder *builder;
+	GtkWidget *align;
+	GtkLabel *label;
+
+	builder = CE_PAGE (self)->builder;
+
+#if GTK_CHECK_VERSION(2,24,0)
+	priv->device_mac = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
+	gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->device_mac), 0);
+#else
+	priv->device_mac = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ());
+	gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (priv->device_mac), 0);
+#endif
+	gtk_widget_set_tooltip_text (GTK_WIDGET (priv->device_mac),
+	                             _("This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55"));
+
+	align = GTK_WIDGET (gtk_builder_get_object (builder, "infiniband_device_mac_alignment"));
+	gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->device_mac));
+	gtk_widget_show_all (GTK_WIDGET (priv->device_mac));
+
+	/* Set mnemonic widget for device MAC label */
+	label = GTK_LABEL (GTK_WIDGET (gtk_builder_get_object (builder, "infiniband_device_mac_label")));
+	gtk_label_set_mnemonic_widget (label, GTK_WIDGET (priv->device_mac));
+
+	priv->transport_mode = GTK_COMBO_BOX (gtk_builder_get_object (builder, "infiniband_mode"));
+	priv->mtu = GTK_SPIN_BUTTON (GTK_WIDGET (gtk_builder_get_object (builder, "infiniband_mtu")));
+}
+
+static void
+stuff_changed (GtkWidget *w, gpointer user_data)
+{
+	ce_page_changed (CE_PAGE (user_data));
+}
+
+static void
+populate_ui (CEPageInfiniband *self)
+{
+	CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self);
+	NMSettingInfiniband *setting = priv->setting;
+	const char *mode;
+	int mode_idx = TRANSPORT_MODE_DATAGRAM;
+	int mtu_def;
+	char **mac_list, **iter;
+	const GByteArray *s_mac;
+	char *s_mac_str;
+	char *active_mac = NULL;
+	GtkWidget *entry;
+
+	/* Port */
+	mode = nm_setting_infiniband_get_transport_mode (setting);
+	if (mode) {
+		if (!strcmp (mode, "datagram"))
+			mode_idx = TRANSPORT_MODE_DATAGRAM;
+		else if (!strcmp (mode, "connected"))
+			mode_idx = TRANSPORT_MODE_CONNECTED;
+	}
+	gtk_combo_box_set_active (priv->transport_mode, mode_idx);
+
+	/* Device MAC address */
+	mac_list = ce_page_get_mac_list (CE_PAGE (self));
+	s_mac = nm_setting_infiniband_get_mac_address (setting);
+	s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_INFINIBAND):
+	                    NULL;
+
+	for (iter = mac_list; iter && *iter; iter++) {
+#if GTK_CHECK_VERSION (2,24,0)
+		gtk_combo_box_text_append_text (priv->device_mac, *iter);
+#else
+		gtk_combo_box_append_text (GTK_COMBO_BOX (priv->device_mac), *iter);
+#endif
+		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 17) == 0)
+			active_mac = *iter;
+	}
+
+	if (s_mac_str) {
+		if (!active_mac) {
+#if GTK_CHECK_VERSION (2,24,0)
+			gtk_combo_box_text_prepend_text (priv->device_mac, s_mac_str);
+#else
+			gtk_combo_box_prepend_text (GTK_COMBO_BOX (priv->device_mac), s_mac_str);
+#endif
+		}
+
+		entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+		if (entry)
+			gtk_entry_set_text (GTK_ENTRY (entry), active_mac ? active_mac : s_mac_str);
+	}
+	g_strfreev (mac_list);
+	g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
+
+	/* MTU */
+	mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_INFINIBAND_MTU);
+	g_signal_connect (priv->mtu, "output",
+	                  G_CALLBACK (ce_spin_output_with_default),
+	                  GINT_TO_POINTER (mtu_def));
+
+	gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_infiniband_get_mtu (setting));
+}
+
+static void
+finish_setup (CEPageInfiniband *self, gpointer unused, GError *error, gpointer user_data)
+{
+	CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self);
+
+	if (error)
+		return;
+
+	populate_ui (self);
+
+	g_signal_connect (priv->transport_mode, "changed", G_CALLBACK (stuff_changed), self);
+	g_signal_connect (priv->mtu, "value-changed", G_CALLBACK (stuff_changed), self);
+}
+
+CEPage *
+ce_page_infiniband_new (NMConnection *connection,
+                        GtkWindow *parent_window,
+                        NMClient *client,
+                        const char **out_secrets_setting_name,
+                        GError **error)
+{
+	CEPageInfiniband *self;
+	CEPageInfinibandPrivate *priv;
+
+	self = CE_PAGE_INFINIBAND (ce_page_new (CE_TYPE_PAGE_INFINIBAND,
+	                                        connection,
+	                                        parent_window,
+	                                        client,
+	                                        UIDIR "/ce-page-infiniband.ui",
+	                                        "InfinibandPage",
+	                                        _("Infiniband")));
+	if (!self) {
+		g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
+		                     _("Could not load Infiniband user interface."));
+		return NULL;
+	}
+
+	infiniband_private_init (self);
+	priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self);
+
+	priv->setting = nm_connection_get_setting_infiniband (connection);
+	if (!priv->setting) {
+		priv->setting = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ());
+		nm_connection_add_setting (connection, NM_SETTING (priv->setting));
+	}
+
+	g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
+
+	return CE_PAGE (self);
+}
+
+static void
+ui_to_setting (CEPageInfiniband *self)
+{
+	CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self);
+	const char *mode;
+	GByteArray *device_mac = NULL;
+	GtkWidget *entry;
+
+	/* Transport mode */
+	if (gtk_combo_box_get_active (priv->transport_mode) == TRANSPORT_MODE_CONNECTED)
+		mode = "connected";
+	else
+		mode = "datagram";
+
+	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+	if (entry)
+		device_mac = nm_utils_hwaddr_atoba (gtk_entry_get_text (GTK_ENTRY (entry)),
+		                                    ARPHRD_INFINIBAND);
+
+	g_object_set (priv->setting,
+	              NM_SETTING_INFINIBAND_MAC_ADDRESS, device_mac,
+	              NM_SETTING_INFINIBAND_MTU, (guint32) gtk_spin_button_get_value_as_int (priv->mtu),
+	              NM_SETTING_INFINIBAND_TRANSPORT_MODE, mode,
+	              NULL);
+
+	if (device_mac)
+		g_byte_array_free (device_mac, TRUE);
+}
+
+static gboolean
+validate (CEPage *page, NMConnection *connection, GError **error)
+{
+	CEPageInfiniband *self = CE_PAGE_INFINIBAND (page);
+	CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self);
+	GtkWidget *entry;
+	char buf[INFINIBAND_ALEN];
+	const char *hwaddr;
+
+	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+	hwaddr = gtk_entry_get_text (GTK_ENTRY (entry));
+	if (hwaddr && *hwaddr && !nm_utils_hwaddr_aton (hwaddr, ARPHRD_INFINIBAND, buf))
+		return FALSE;
+
+	ui_to_setting (self);
+	return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
+}
+
+static char **
+get_mac_list (CEPage *page)
+{
+	const GPtrArray *devices;
+	GString *mac_str;
+	char **mac_list;
+	int i;
+
+	if (!page->client)
+		return NULL;
+
+	mac_str = g_string_new (NULL);
+	devices = nm_client_get_devices (page->client);
+	for (i = 0; devices && (i < devices->len); i++) {
+		const char *mac, *iface;
+		NMDevice *dev = g_ptr_array_index (devices, i);
+
+		if (!NM_IS_DEVICE_INFINIBAND (dev))
+			continue;
+
+		mac = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (dev));
+		iface = nm_device_get_iface (NM_DEVICE (dev));
+		g_string_append_printf (mac_str, "%s (%s),", mac, iface);
+	}
+	g_string_truncate (mac_str, mac_str->len-1);
+
+	mac_list = g_strsplit (mac_str->str, ",", 0);
+	g_string_free (mac_str, TRUE);
+
+	return mac_list;
+}
+
+static void
+ce_page_infiniband_init (CEPageInfiniband *self)
+{
+}
+
+static void
+ce_page_infiniband_class_init (CEPageInfinibandClass *infiniband_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (infiniband_class);
+	CEPageClass *parent_class = CE_PAGE_CLASS (infiniband_class);
+
+	g_type_class_add_private (object_class, sizeof (CEPageInfinibandPrivate));
+
+	/* virtual methods */
+	parent_class->validate = validate;
+	parent_class->get_mac_list = get_mac_list;
+}
+
+
+void
+infiniband_connection_new (GtkWindow *parent,
+                           const char *detail,
+                           NMRemoteSettings *settings,
+                           PageNewConnectionResultFunc result_func,
+                           gpointer user_data)
+{
+	NMConnection *connection;
+
+	connection = ce_page_new_connection (_("Infiniband connection %d"),
+	                                     NM_SETTING_INFINIBAND_SETTING_NAME,
+	                                     TRUE,
+	                                     settings,
+	                                     user_data);
+	nm_connection_add_setting (connection, nm_setting_infiniband_new ());
+
+	(*result_func) (connection, FALSE, NULL, user_data);
+}
+
diff --git a/src/connection-editor/page-infiniband.h b/src/connection-editor/page-infiniband.h
new file mode 100644
index 0000000..5b81314
--- /dev/null
+++ b/src/connection-editor/page-infiniband.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2012 Red Hat, Inc.
+ */
+
+#ifndef __PAGE_INFINIBAND_H__
+#define __PAGE_INFINIBAND_H__
+
+#include <nm-connection.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "ce-page.h"
+
+#define CE_TYPE_PAGE_INFINIBAND            (ce_page_infiniband_get_type ())
+#define CE_PAGE_INFINIBAND(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_INFINIBAND, CEPageInfiniband))
+#define CE_PAGE_INFINIBAND_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_INFINIBAND, CEPageInfinibandClass))
+#define CE_IS_PAGE_INFINIBAND(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_INFINIBAND))
+#define CE_IS_PAGE_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), CE_TYPE_PAGE_INFINIBAND))
+#define CE_PAGE_INFINIBAND_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_INFINIBAND, CEPageInfinibandClass))
+
+typedef struct {
+	CEPage parent;
+} CEPageInfiniband;
+
+typedef struct {
+	CEPageClass parent;
+} CEPageInfinibandClass;
+
+GType ce_page_infiniband_get_type (void);
+
+CEPage *ce_page_infiniband_new (NMConnection *connection,
+                                GtkWindow *parent,
+                                NMClient *client,
+                                const char **out_secrets_setting_name,
+                                GError **error);
+
+void infiniband_connection_new (GtkWindow *parent,
+                                const char *detail,
+                                NMRemoteSettings *settings,
+                                PageNewConnectionResultFunc result_func,
+                                gpointer user_data);
+
+#endif  /* __PAGE_INFINIBAND_H__ */
+
diff --git a/src/connection-editor/page-wimax.c b/src/connection-editor/page-wimax.c
index 56f2c3c..304804c 100644
--- a/src/connection-editor/page-wimax.c
+++ b/src/connection-editor/page-wimax.c
@@ -187,7 +187,7 @@ ui_to_setting (CEPageWimax *self)
 
 	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 	if (entry)
-		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), NULL);
+		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL);
 
 	g_object_set (priv->setting,
 	              NM_SETTING_WIMAX_NETWORK_NAME, name,
@@ -214,7 +214,7 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 
 	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 	if (entry) {
-		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), &invalid);
+		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid);
 		if (invalid)
 			return FALSE;
 		if (ignore)
diff --git a/src/connection-editor/page-wired.c b/src/connection-editor/page-wired.c
index 0b7f72c..bc8a0dc 100644
--- a/src/connection-editor/page-wired.c
+++ b/src/connection-editor/page-wired.c
@@ -206,7 +206,8 @@ populate_ui (CEPageWired *self)
 	g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
 
 	/* Cloned MAC address */
-	ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting), priv->cloned_mac);
+	ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting),
+	                      ARPHRD_ETHER, priv->cloned_mac);
 	g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self);
 
 	/* MTU */
@@ -339,8 +340,8 @@ ui_to_setting (CEPageWired *self)
 
 	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 	if (entry)
-		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), NULL);
-	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, NULL);
+		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL);
+	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, NULL);
 
 	g_object_set (priv->setting,
 				  NM_SETTING_WIRED_MAC_ADDRESS, device_mac,
@@ -370,14 +371,14 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 
 	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 	if (entry) {
-		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), &invalid);
+		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid);
 		if (invalid)
 			return FALSE;
 		if (ignore)
 			g_byte_array_free (ignore, TRUE);
 	}
 
-	ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid);
+	ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid);
 	if (invalid)
 		return FALSE;
 	if (ignore)
diff --git a/src/connection-editor/page-wireless.c b/src/connection-editor/page-wireless.c
index 1f03298..a727414 100644
--- a/src/connection-editor/page-wireless.c
+++ b/src/connection-editor/page-wireless.c
@@ -371,7 +371,8 @@ populate_ui (CEPageWireless *self)
 	g_signal_connect_swapped (priv->channel, "value-changed", G_CALLBACK (ce_page_changed), self);
 
 	/* BSSID */
-	ce_page_mac_to_entry (nm_setting_wireless_get_bssid (setting), priv->bssid);
+	ce_page_mac_to_entry (nm_setting_wireless_get_bssid (setting),
+	                      ARPHRD_ETHER, priv->bssid);
 	g_signal_connect_swapped (priv->bssid, "changed", G_CALLBACK (ce_page_changed), self);
 
 	/* Device MAC address */
@@ -409,7 +410,8 @@ populate_ui (CEPageWireless *self)
 	g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
 
 	/* Cloned MAC address */
-	ce_page_mac_to_entry (nm_setting_wireless_get_cloned_mac_address (setting), priv->cloned_mac);
+	ce_page_mac_to_entry (nm_setting_wireless_get_cloned_mac_address (setting),
+	                      ARPHRD_ETHER, priv->cloned_mac);
 	g_signal_connect_swapped (priv->cloned_mac, "changed", G_CALLBACK (ce_page_changed), self);
 
 	gtk_spin_button_set_value (priv->rate, (gdouble) nm_setting_wireless_get_rate (setting));
@@ -529,11 +531,11 @@ ui_to_setting (CEPageWireless *self)
 		break;
 	}
 
-	bssid = ce_page_entry_to_mac (priv->bssid, NULL);
+	bssid = ce_page_entry_to_mac (priv->bssid, ARPHRD_ETHER, NULL);
 	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 	if (entry)
-		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), NULL);
-	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, NULL);
+		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL);
+	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, NULL);
 
 	g_object_set (priv->setting,
 				  NM_SETTING_WIRELESS_SSID, ssid,
@@ -569,7 +571,7 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	GByteArray *ignore;
 	GtkWidget *entry;
 
-	ignore = ce_page_entry_to_mac (priv->bssid, &invalid);
+	ignore = ce_page_entry_to_mac (priv->bssid, ARPHRD_ETHER, &invalid);
 	if (invalid)
 		return FALSE;
 	if (ignore)
@@ -577,14 +579,14 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 
 	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 	if (entry) {
-		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), &invalid);
+		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid);
 		if (invalid)
 			return FALSE;
 		if (ignore)
 			g_byte_array_free (ignore, TRUE);
 	}
 
-	ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid);
+	ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid);
 	if (invalid)
 		return FALSE;
 	if (ignore)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]