[PATCH 3/3] Add libnm-glib and nmcli code



For the finale, this is the libnm-glib and nmcli part of the support,
with this you can now make a full pppoatm connection from NetworkManager
by configuring it in system scope in a keyfile.

As an example, here is mine:
(password and username snipped for obvious reasons)

[connection]
id=MYISP
uuid=34d04e69-fdd9-4231-af2c-25ed1f34dc1e
type=adsl
timestamp=1304621332

[adsl]
username=user myisp com
password=mypassword
vpi=8
vci=35
encapsulation=vcmux
protocol=pppoa

[ipv6]
method=ignore

[ipv4]
method=auto

Extract from logs:
NetworkManager[29155]: <info> Activation (ueagle-atm0) starting connection 'MYISP'
NetworkManager[29155]: <info> (ueagle-atm0): device state change: disconnected -> prepare (reason 'none') [30 40 0]
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 1 of 5 (Device Prepare) scheduled...
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 1 of 5 (Device Prepare) started...
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) scheduled...
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 1 of 5 (Device Prepare) complete.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) starting...
NetworkManager[29155]: <info> (ueagle-atm0): device state change: prepare -> config (reason 'none') [40 50 0]
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) successful.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 3 of 5 (IP Configure Start) scheduled.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) complete.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 3 of 5 (IP Configure Start) started...
NetworkManager[29155]: <info> (ueagle-atm0): device state change: config -> ip-config (reason 'none') [50 70 0]
NetworkManager[29155]: <info> starting PPP connection
NetworkManager[29155]: <debug> [1304671146.590156] [nm-ppp-manager.c:1047] nm_ppp_manager_start(): command line: /usr/sbin/pppd nodetach lock nodefaultroute user user myisp com plugin pppoatm.so 8.35 noipdefault noauth usepeerdns lcp-echo-failure 0 lcp-echo-interval 0 ipparam /org/freedesktop/NetworkManager/PPP/0 plugin /opt/nmadsl/lib/pppd/2.4.5/nm-pppd-plugin.so
NetworkManager[29155]: <info> pppd started with pid 29175
NetworkManager[29155]: <debug> [1304671146.591235] [NetworkManagerUtils.c:816] nm_utils_get_proc_sys_net_value(): (ueagle-atm0): error reading /proc/sys/net/ipv6/conf/ueagle-atm0/accept_ra: (4) Failed to open file '/proc/sys/net/ipv6/conf/ueagle-atm0/accept_ra': No such file or directory
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 3 of 5 (IP Configure Start) complete.
Plugin pppoatm.so loaded.
Plugin /opt/nmadsl/lib/pppd/2.4.5/nm-pppd-plugin.so loaded.
** Message: nm-ppp-plugin: (plugin_init): initializing
** Message: nm-ppp-plugin: (nm_phasechange): status 3 / phase 'serial connection'
NetworkManager[29155]: <debug> [1304671146.612937] [nm-udev-manager.c:621] handle_uevent(): UDEV event: action 'add' subsys 'net' device 'ppp0'
NetworkManager[29155]: <debug> [1304671146.613134] [nm-udev-manager.c:525] net_add(): ignoring interface with type 512
NetworkManager[29155]: <debug> [1304671146.617308] [nm-netlink-monitor.c:117] link_msg_handler(): netlink link message: iface idx 35 flags 0x1090
Using interface ppp0
Connect: ppp0 <--> 8.35
** Message: nm-ppp-plugin: (nm_phasechange): status 5 / phase 'establish'
** Message: nm-ppp-plugin: (nm_phasechange): status 6 / phase 'authenticate'
** Message: nm-ppp-plugin: (get_credentials): passwd-hook, requesting credentials...
NetworkManager[29155]: <debug> [1304671149.639511] [nm-agent-manager.c:1044] nm_agent_manager_get_secrets(): Secrets requested for connection /org/freedesktop/NetworkManager/Settings/0 (adsl)
NetworkManager[29155]: <debug> [1304671149.639684] [nm-settings-connection.c:717] nm_settings_connection_get_secrets(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) secrets requested flags 0x1 hint 'password'
NetworkManager[29155]: <debug> [1304671149.640950] [nm-agent-manager.c:959] get_start(): (0x9b4ad10/adsl) system settings secrets sufficient
NetworkManager[29155]: <debug> [1304671149.641332] [nm-settings-connection.c:573] agent_secrets_done_cb(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) existing secrets returned
NetworkManager[29155]: <debug> [1304671149.641541] [nm-settings-connection.c:579] agent_secrets_done_cb(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) secrets request completed
NetworkManager[29155]: <debug> [1304671149.643074] [nm-settings-connection.c:618] agent_secrets_done_cb(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) new agent secrets processed
** Message: nm-ppp-plugin: (get_credentials): got credentials from NetworkManager
PAP authentication succeeded
** Message: nm-ppp-plugin: (nm_phasechange): status 8 / phase 'network'
local  IP address 94.70.90.201
remote IP address 80.106.108.12
primary   DNS address 195.170.0.1
secondary DNS address 195.170.2.2
** Message: nm-ppp-plugin: (nm_phasechange): status 9 / phase 'running'
** Message: nm-ppp-plugin: (nm_ip_up): ip-up event
** Message: nm-ppp-plugin: (nm_ip_up): sending Ip4Config to NetworkManager...
NetworkManager[29155]: <debug> [1304671150.607440] [nm-netlink-monitor.c:117] link_msg_handler(): netlink link message: iface idx 35 flags 0x110D1
NetworkManager[29155]: <info> PPP manager(IP Config Get) reply received.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 4 of 5 (IP4 Configure Get) scheduled...
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 4 of 5 (IP4 Configure Get) started...
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 5 of 5 (IP Configure Commit) scheduled...
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 4 of 5 (IP4 Configure Get) complete.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 5 of 5 (IP Configure Commit) started...
NetworkManager[29155]: <debug> [1304671150.608918] [nm-system.c:222] sync_addresses(): (ppp0): syncing addresses (family 2)
NetworkManager[29155]: <info> (ueagle-atm0): device state change: ip-config -> activated (reason 'none') [70 100 0]
NetworkManager[29155]: <info> Policy set 'MYISP' (ppp0) as default for IPv4 routing and DNS.
NetworkManager[29155]: <info> Activation (ueagle-atm0) successful, device activated.
NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 5 of 5 (IP Configure Commit) complete.

Signed-off-by: Pantelis Koukousoulas <pktoss gmail com>
---
 cli/src/connections.c       |   66 ++++++++++--
 cli/src/devices.c           |    4 +
 cli/src/settings.c          |   50 +++++++++
 cli/src/settings.h          |    2 +
 libnm-glib/Makefile.am      |    6 +
 libnm-glib/libnm-glib.ver   |    4 +-
 libnm-glib/nm-device-adsl.c |  236 +++++++++++++++++++++++++++++++++++++++++++
 libnm-glib/nm-device-adsl.h |   62 +++++++++++
 libnm-glib/nm-device.c      |   10 ++-
 libnm-util/nm-connection.c  |   25 +++++-
 libnm-util/nm-connection.h  |    2 +
 11 files changed, 451 insertions(+), 16 deletions(-)
 create mode 100644 libnm-glib/nm-device-adsl.c
 create mode 100644 libnm-glib/nm-device-adsl.h

diff --git a/cli/src/connections.c b/cli/src/connections.c
index 2646aa9..5308f04 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -34,6 +34,7 @@
 #include <nm-client.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
+#include <nm-setting-adsl.h>
 #include <nm-setting-pppoe.h>
 #include <nm-setting-wireless.h>
 #include <nm-setting-gsm.h>
@@ -44,6 +45,7 @@
 #include <nm-setting-wimax.h>
 #endif
 #include <nm-device-ethernet.h>
+#include <nm-device-adsl.h>
 #include <nm-device-wifi.h>
 #if WITH_WIMAX
 #include <nm-device-wimax.h>
@@ -104,12 +106,13 @@ static NmcOutputField nmc_fields_settings_names[] = {
 	SETTING_FIELD (NM_SETTING_SERIAL_SETTING_NAME, 0),                /* 7 */
 	SETTING_FIELD (NM_SETTING_PPP_SETTING_NAME, 0),                   /* 8 */
 	SETTING_FIELD (NM_SETTING_PPPOE_SETTING_NAME, 0),                 /* 9 */
-	SETTING_FIELD (NM_SETTING_GSM_SETTING_NAME, 0),                   /* 10 */
-	SETTING_FIELD (NM_SETTING_CDMA_SETTING_NAME, 0),                  /* 11 */
-	SETTING_FIELD (NM_SETTING_BLUETOOTH_SETTING_NAME, 0),             /* 12 */
-	SETTING_FIELD (NM_SETTING_OLPC_MESH_SETTING_NAME, 0),             /* 13 */
-	SETTING_FIELD (NM_SETTING_VPN_SETTING_NAME, 0),                   /* 14 */
-	SETTING_FIELD (NM_SETTING_WIMAX_SETTING_NAME, 0),                 /* 15 */
+	SETTING_FIELD (NM_SETTING_ADSL_SETTING_NAME, 0),                  /* 10 */
+	SETTING_FIELD (NM_SETTING_GSM_SETTING_NAME, 0),                   /* 11 */
+	SETTING_FIELD (NM_SETTING_CDMA_SETTING_NAME, 0),                  /* 12 */
+	SETTING_FIELD (NM_SETTING_BLUETOOTH_SETTING_NAME, 0),             /* 13 */
+	SETTING_FIELD (NM_SETTING_OLPC_MESH_SETTING_NAME, 0),             /* 14 */
+	SETTING_FIELD (NM_SETTING_VPN_SETTING_NAME, 0),                   /* 15 */
+	SETTING_FIELD (NM_SETTING_WIMAX_SETTING_NAME, 0),                 /* 16 */
 	{NULL, NULL, 0, NULL, 0}
 };
 #define NMC_FIELDS_SETTINGS_NAMES_ALL_X  NM_SETTING_CONNECTION_SETTING_NAME","\
@@ -122,6 +125,7 @@ static NmcOutputField nmc_fields_settings_names[] = {
                                          NM_SETTING_SERIAL_SETTING_NAME","\
                                          NM_SETTING_PPP_SETTING_NAME","\
                                          NM_SETTING_PPPOE_SETTING_NAME","\
+                                         NM_SETTING_ADSL_SETTING_NAME","\
                                          NM_SETTING_GSM_SETTING_NAME","\
                                          NM_SETTING_CDMA_SETTING_NAME","\
                                          NM_SETTING_BLUETOOTH_SETTING_NAME","\
@@ -331,6 +335,15 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
 		}
 
 		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[10].name)) {
+			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_ADSL);
+			if (setting) {
+				setting_adsl_details (setting, nmc);
+				was_output = TRUE;
+				continue;
+			}
+		}
+
+		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[11].name)) {
 			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM);
 			if (setting) {
 				setting_gsm_details (setting, nmc);
@@ -339,7 +352,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
 			}
 		}
 
-		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[11].name)) {
+		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[12].name)) {
 			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_CDMA);
 			if (setting) {
 				setting_cdma_details (setting, nmc);
@@ -348,7 +361,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
 			}
 		}
 
-		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[12].name)) {
+		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[13].name)) {
 			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
 			if (setting) {
 				setting_bluetooth_details (setting, nmc);
@@ -357,7 +370,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
 			}
 		}
 
-		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[13].name)) {
+		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[14].name)) {
 			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_OLPC_MESH);
 			if (setting) {
 				setting_olpc_mesh_details (setting, nmc);
@@ -366,7 +379,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
 			}
 		}
 
-		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[14].name)) {
+		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[15].name)) {
 			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
 			if (setting) {
 				setting_vpn_details (setting, nmc);
@@ -376,7 +389,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
 		}
 
 #if WITH_WIMAX
-		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[15].name)) {
+		if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[16].name)) {
 			setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX);
 			if (setting) {
 				setting_wimax_details (setting, nmc);
@@ -968,6 +981,35 @@ check_modem_compatible (NMDeviceModem *device, NMConnection *connection, GError
 }
 
 static gboolean
+check_adsl_compatible (NMDeviceAdsl *device, NMConnection *connection, GError **error)
+{
+	NMSettingConnection *s_con;
+	NMSettingAdsl *s_adsl;
+	const char *connection_type;
+
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (s_con);
+
+	connection_type = nm_setting_connection_get_connection_type (s_con);
+	if (strcmp (connection_type, NM_SETTING_ADSL_SETTING_NAME)) {
+		g_set_error (error, 0, 0,
+		             "The connection was not an ADSL connection.");
+		return FALSE;
+	}
+
+	s_adsl = nm_connection_get_setting_adsl (connection);
+	if (!s_adsl) {
+		g_set_error (error, 0, 0,
+		             "The connection was not a valid ADSL connection.");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static gboolean
 nm_device_is_connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
 {
 	g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
@@ -987,6 +1029,8 @@ nm_device_is_connection_compatible (NMDevice *device, NMConnection *connection,
 #endif
 	else if (NM_IS_DEVICE_MODEM (device))
 		return check_modem_compatible (NM_DEVICE_MODEM (device), connection, error);
+	else if (NM_IS_DEVICE_ADSL (device))
+		return check_adsl_compatible (NM_DEVICE_ADSL (device), connection, error);
 
 	g_set_error (error, 0, 0, "unhandled device type '%s'", G_OBJECT_TYPE_NAME (device));
 	return FALSE;
diff --git a/cli/src/devices.c b/cli/src/devices.c
index c6228ba..7d55c43 100644
--- a/cli/src/devices.c
+++ b/cli/src/devices.c
@@ -34,6 +34,7 @@
 #include <nm-client.h>
 #include <nm-device.h>
 #include <nm-device-ethernet.h>
+#include <nm-device-adsl.h>
 #include <nm-device-wifi.h>
 #include <nm-device-modem.h>
 #include <nm-device-bt.h>
@@ -47,6 +48,7 @@
 #include <nm-vpn-connection.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
+#include <nm-setting-adsl.h>
 #include <nm-setting-pppoe.h>
 #include <nm-setting-wireless.h>
 #include <nm-setting-gsm.h>
@@ -320,6 +322,8 @@ device_type_to_string (NMDevice *device)
 	switch (nm_device_get_device_type (device)) {
 	case NM_DEVICE_TYPE_ETHERNET:
 		return NM_SETTING_WIRED_SETTING_NAME;
+	case NM_DEVICE_TYPE_ADSL:
+		return NM_SETTING_ADSL_SETTING_NAME;
 	case NM_DEVICE_TYPE_WIFI:
 		return NM_SETTING_WIRELESS_SETTING_NAME;
 	case NM_DEVICE_TYPE_MODEM:
diff --git a/cli/src/settings.c b/cli/src/settings.c
index c238537..1283b5b 100644
--- a/cli/src/settings.c
+++ b/cli/src/settings.c
@@ -320,6 +320,26 @@ static NmcOutputField nmc_fields_setting_pppoe[] = {
                                          NM_SETTING_PPPOE_PASSWORD
 #define NMC_FIELDS_SETTING_PPPOE_COMMON  NMC_FIELDS_SETTING_PPP_ALL
 
+/* Available fields for NM_SETTING_ADSL_SETTING_NAME */
+static NmcOutputField nmc_fields_setting_adsl[] = {
+	SETTING_FIELD ("name", 10),                                /* 0 */
+	SETTING_FIELD (NM_SETTING_ADSL_USERNAME, 15),              /* 1 */
+	SETTING_FIELD (NM_SETTING_ADSL_PASSWORD, 15),              /* 2 */
+	SETTING_FIELD (NM_SETTING_ADSL_VPI, 10),                   /* 3 */
+	SETTING_FIELD (NM_SETTING_ADSL_VCI, 10),                   /* 4 */
+	SETTING_FIELD (NM_SETTING_ADSL_ENCAPSULATION, 10),         /* 5 */
+	SETTING_FIELD (NM_SETTING_ADSL_PROTOCOL, 10),              /* 6 */
+	{NULL, NULL, 0, NULL, 0}
+};
+#define NMC_FIELDS_SETTING_ADSL_ALL     "name"","\
+                                        NM_SETTING_ADSL_USERNAME","\
+                                        NM_SETTING_ADSL_PASSWORD","\
+                                        NM_SETTING_ADSL_VPI","\
+                                        NM_SETTING_ADSL_VCI","\
+                                        NM_SETTING_ADSL_ENCAPSULATION","\
+                                        NM_SETTING_ADSL_PROTOCOL
+#define NMC_FIELDS_SETTING_ADSL_COMMON  NMC_FIELDS_SETTING_ADSL_ALL
+
 /* Available fields for NM_SETTING_GSM_SETTING_NAME */
 static NmcOutputField nmc_fields_setting_gsm[] = {
 	SETTING_FIELD ("name", 10),                                        /* 0 */
@@ -1204,6 +1224,36 @@ setting_pppoe_details (NMSetting *setting, NmCli *nmc)
 }
 
 gboolean
+setting_adsl_details (NMSetting *setting, NmCli *nmc)
+{
+	NMSettingAdsl *s_adsl;
+	guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
+	guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
+	guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
+
+	g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), FALSE);
+	s_adsl = (NMSettingAdsl *) setting;
+
+	nmc->allowed_fields = nmc_fields_setting_adsl;
+	nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_ADSL_ALL, nmc->allowed_fields, NULL);
+	nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
+	print_fields (nmc->print_fields, nmc->allowed_fields);  /* Print field names */
+
+	nmc->allowed_fields[0].value = NM_SETTING_ADSL_SETTING_NAME;
+	nmc->allowed_fields[1].value = nm_setting_adsl_get_username (s_adsl);
+	nmc->allowed_fields[2].value = nm_setting_adsl_get_password (s_adsl);
+	nmc->allowed_fields[3].value = g_strdup_printf ("%s", nm_setting_adsl_get_vpi (s_adsl));
+	nmc->allowed_fields[4].value = g_strdup_printf ("%s", nm_setting_adsl_get_vci (s_adsl));
+	nmc->allowed_fields[5].value = nm_setting_adsl_get_encapsulation (s_adsl);
+	nmc->allowed_fields[6].value = nm_setting_adsl_get_protocol (s_adsl);
+
+	nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
+	print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
+
+	return TRUE;
+}
+
+gboolean
 setting_gsm_details (NMSetting *setting, NmCli *nmc)
 {
 	NMSettingGsm *s_gsm;
diff --git a/cli/src/settings.h b/cli/src/settings.h
index 4901bf2..61c9557 100644
--- a/cli/src/settings.h
+++ b/cli/src/settings.h
@@ -22,6 +22,7 @@
 
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
+#include <nm-setting-adsl.h>
 #include <nm-setting-8021x.h>
 #include <nm-setting-wireless.h>
 #include <nm-setting-wireless-security.h>
@@ -51,6 +52,7 @@ gboolean setting_ip6_config_details (NMSetting *setting, NmCli *nmc);
 gboolean setting_serial_details (NMSetting *setting, NmCli *nmc);
 gboolean setting_ppp_details (NMSetting *setting, NmCli *nmc);
 gboolean setting_pppoe_details (NMSetting *setting, NmCli *nmc);
+gboolean setting_adsl_details (NMSetting *setting, NmCli *nmc);
 gboolean setting_gsm_details (NMSetting *setting, NmCli *nmc);
 gboolean setting_cdma_details (NMSetting *setting, NmCli *nmc);
 gboolean setting_bluetooth_details (NMSetting *setting, NmCli *nmc);
diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am
index 08a61cc..5955564 100644
--- a/libnm-glib/Makefile.am
+++ b/libnm-glib/Makefile.am
@@ -10,6 +10,7 @@ BUILT_SOURCES = \
 	nm-client-bindings.h \
 	nm-device-bindings.h \
 	nm-device-ethernet-bindings.h \
+	nm-device-adsl-bindings.h \
 	nm-device-wifi-bindings.h \
 	nm-device-bt-bindings.h \
 	nm-settings-connection-bindings.h \
@@ -70,6 +71,7 @@ libnminclude_HEADERS = \
 	nm-client.h \
 	nm-device.h \
 	nm-device-ethernet.h \
+	nm-device-adsl.h \
 	nm-device-wifi.h \
 	nm-device-bt.h \
 	nm-access-point.h \
@@ -98,6 +100,7 @@ libnm_glib_la_csources = \
 	nm-dbus-utils.c \
 	nm-device.c \
 	nm-device-ethernet.c \
+	nm-device-adsl.c \
 	nm-device-wifi.c \
 	nm-device-bt.c \
 	nm-access-point.c \
@@ -189,6 +192,9 @@ nm-device-bindings.h: $(top_srcdir)/introspection/nm-device.xml
 nm-device-ethernet-bindings.h: $(top_srcdir)/introspection/nm-device-ethernet.xml
 	$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_ethernet --mode=glib-client --output=$@ $<
 
+nm-device-adsl-bindings.h: $(top_srcdir)/introspection/nm-device-adsl.xml
+	$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_adsl --mode=glib-client --output=$@ $<
+
 nm-device-wifi-bindings.h: $(top_srcdir)/introspection/nm-device-wifi.xml
 	$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_wifi --mode=glib-client --output=$@ $<
 
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index a59bec9..3b17c66 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -65,6 +65,9 @@ global:
 	nm_device_ethernet_get_speed;
 	nm_device_ethernet_get_type;
 	nm_device_ethernet_new;
+	nm_device_adsl_get_carrier;
+	nm_device_adsl_get_type;
+	nm_device_adsl_new;
 	nm_device_filter_connections;
 	nm_device_get_capabilities;
 	nm_device_get_device_type;
@@ -75,7 +78,6 @@ global:
 	nm_device_get_iface;
 	nm_device_get_ip4_config;
 	nm_device_get_ip6_config;
-	nm_device_get_ip_iface;
 	nm_device_get_managed;
 	nm_device_get_product;
 	nm_device_get_state;
diff --git a/libnm-glib/nm-device-adsl.c b/libnm-glib/nm-device-adsl.c
new file mode 100644
index 0000000..e0d5da5
--- /dev/null
+++ b/libnm-glib/nm-device-adsl.c
@@ -0,0 +1,236 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * libnm_glib -- Access network status & information from glib applications
+ *
+ * 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.
+ *
+ * author: Pantelis Koukousoulas <pktoss gmail com>
+ * Copyright 2009 - 2011 Red Hat, Inc.
+ */
+
+#include "nm-device-adsl.h"
+#include "nm-device-private.h"
+#include "nm-object-private.h"
+
+#include "nm-setting-adsl.h"
+
+#include <string.h>
+
+#include "nm-device-adsl-bindings.h"
+
+G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate))
+
+typedef struct {
+	DBusGProxy *proxy;
+
+	gboolean carrier;
+
+	gboolean disposed;
+} NMDeviceAdslPrivate;
+
+enum {
+	PROP_0,
+	PROP_CARRIER,
+	LAST_PROP
+};
+#define DBUS_PROP_CARRIER "Carrier"
+
+/**
+ * nm_device_adsl_new:
+ * @connection: the #DBusGConnection
+ * @path: the DBus object path of the device
+ *
+ * Creates a new #NMDeviceAdsl.
+ *
+ * Returns: a new device
+ **/
+GObject *
+nm_device_adsl_new (DBusGConnection *connection, const char *path)
+{
+	g_return_val_if_fail (connection != NULL, NULL);
+	g_return_val_if_fail (path != NULL, NULL);
+
+	return g_object_new (NM_TYPE_DEVICE_ADSL,
+	                     NM_OBJECT_DBUS_CONNECTION, connection,
+	                     NM_OBJECT_DBUS_PATH, path,
+	                     NULL);
+}
+
+/**
+ * nm_device_adsl_get_carrier:
+ * @device: a #NMDeviceAdsl
+ *
+ * Whether the device has carrier.
+ *
+ * Returns: %TRUE if the device has carrier
+ **/
+gboolean
+nm_device_adsl_get_carrier (NMDeviceAdsl *device)
+{
+	NMDeviceAdslPrivate *priv;
+
+	g_return_val_if_fail (NM_IS_DEVICE_ADSL (device), FALSE);
+
+	priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
+	priv->carrier = _nm_object_get_boolean_property (NM_OBJECT (device),
+		                                                NM_DBUS_INTERFACE_DEVICE_ADSL,
+		                                                DBUS_PROP_CARRIER,
+		                                                NULL);
+	return priv->carrier;
+}
+
+static gboolean
+connection_valid (NMDevice *device, NMConnection *connection)
+{
+	NMSettingConnection *s_con;
+	NMSettingAdsl *s_adsl;
+	const char *ctype;
+
+	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_ADSL_SETTING_NAME) != 0)
+		return FALSE;
+
+	s_adsl = nm_connection_get_setting_adsl (connection);
+	if (!s_adsl)
+		return FALSE;
+
+	return TRUE;
+}
+
+static void
+nm_device_adsl_init (NMDeviceAdsl *device)
+{
+	NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
+
+	priv->disposed = FALSE;
+	priv->carrier = FALSE;
+}
+
+static void
+register_for_property_changed (NMDeviceAdsl *device)
+{
+	NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
+	const NMPropertiesChangedInfo property_changed_info[] = {
+		{ NM_DEVICE_ADSL_CARRIER,              _nm_object_demarshal_generic, &priv->carrier },
+		{ NULL },
+	};
+
+	_nm_object_handle_properties_changed (NM_OBJECT (device),
+	                                     priv->proxy,
+	                                     property_changed_info);
+}
+
+static GObject*
+constructor (GType type,
+			 guint n_construct_params,
+			 GObjectConstructParam *construct_params)
+{
+	GObject *object;
+	NMDeviceAdslPrivate *priv;
+
+	object = G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructor (type,
+																		n_construct_params,
+																		construct_params);
+	if (!object)
+		return NULL;
+
+	priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
+
+	priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
+	                                         NM_DBUS_SERVICE,
+	                                         nm_object_get_path (NM_OBJECT (object)),
+	                                         NM_DBUS_INTERFACE_DEVICE_ADSL);
+
+	register_for_property_changed (NM_DEVICE_ADSL (object));
+
+	return object;
+}
+
+static void
+dispose (GObject *object)
+{
+	NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
+
+	if (priv->disposed) {
+		G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
+		return;
+	}
+
+	priv->disposed = TRUE;
+
+	g_object_unref (priv->proxy);
+
+	G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+	G_OBJECT_CLASS (nm_device_adsl_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object,
+              guint prop_id,
+              GValue *value,
+              GParamSpec *pspec)
+{
+	NMDeviceAdsl *device = NM_DEVICE_ADSL (object);
+
+	switch (prop_id) {
+	case PROP_CARRIER:
+		g_value_set_boolean (value, nm_device_adsl_get_carrier (device));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (adsl_class);
+	NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class);
+
+	g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate));
+
+	/* virtual methods */
+	object_class->constructor = constructor;
+	object_class->dispose = dispose;
+	object_class->finalize = finalize;
+	object_class->get_property = get_property;
+	device_class->connection_valid = connection_valid;
+
+	/* properties */
+	/**
+	 * NMDeviceAdsl:carrier:
+	 *
+	 * Whether the device has carrier.
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_CARRIER,
+		 g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER,
+					    "Carrier",
+					    "Carrier",
+					    FALSE,
+					    G_PARAM_READABLE));
+}
diff --git a/libnm-glib/nm-device-adsl.h b/libnm-glib/nm-device-adsl.h
new file mode 100644
index 0000000..73223cd
--- /dev/null
+++ b/libnm-glib/nm-device-adsl.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * libnm_glib -- Access network status & information from glib applications
+ *
+ * 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 (C) 2011 Pantelis Koukousoulas <pktoss gmail com>
+ */
+
+#ifndef NM_DEVICE_ADSL_H
+#define NM_DEVICE_ADSL_H
+
+#include "nm-device.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DEVICE_ADSL            (nm_device_adsl_get_type ())
+#define NM_DEVICE_ADSL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_ADSL, NMDeviceAdsl))
+#define NM_DEVICE_ADSL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_ADSL, NMDeviceAdslClass))
+#define NM_IS_DEVICE_ADSL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_ADSL))
+#define NM_IS_DEVICE_ADSL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_ADSL))
+#define NM_DEVICE_ADSL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_ADSL, NMDeviceAdslClass))
+
+#define NM_DEVICE_ADSL_CARRIER "carrier"
+
+typedef struct {
+	NMDevice parent;
+} NMDeviceAdsl;
+
+typedef struct {
+	NMDeviceClass parent;
+
+	/* Padding for future expansion */
+	void (*_reserved1) (void);
+	void (*_reserved2) (void);
+	void (*_reserved3) (void);
+	void (*_reserved4) (void);
+	void (*_reserved5) (void);
+	void (*_reserved6) (void);
+} NMDeviceAdslClass;
+
+GType nm_device_adsl_get_type (void);
+
+GObject *nm_device_adsl_new (DBusGConnection *connection, const char *path);
+gboolean nm_device_adsl_get_carrier (NMDeviceAdsl *device);
+
+G_END_DECLS
+
+#endif /* NM_DEVICE_ADSL_H */
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c
index 57aa2cf..ac0da9d 100644
--- a/libnm-glib/nm-device.c
+++ b/libnm-glib/nm-device.c
@@ -27,6 +27,7 @@
 
 #include "NetworkManager.h"
 #include "nm-device-ethernet.h"
+#include "nm-device-adsl.h"
 #include "nm-device-wifi.h"
 #include "nm-device-modem.h"
 #include "nm-device-bt.h"
@@ -748,6 +749,9 @@ nm_device_new (DBusGConnection *connection, const char *path)
 	case NM_DEVICE_TYPE_ETHERNET:
 		dtype = NM_TYPE_DEVICE_ETHERNET;
 		break;
+	case NM_DEVICE_TYPE_ADSL:
+		dtype = NM_TYPE_DEVICE_ADSL;
+		break;
 	case NM_DEVICE_TYPE_WIFI:
 		dtype = NM_TYPE_DEVICE_WIFI;
 		break;
@@ -1203,7 +1207,7 @@ get_decoded_property (GUdevDevice *device, const char *property)
 }
 
 static void
-_device_update_description (NMDevice *device)
+nm_device_update_description (NMDevice *device)
 {
 	NMDevicePrivate *priv;
 	const char *subsys[3] = { "net", "tty", NULL };
@@ -1318,7 +1322,7 @@ nm_device_get_product (NMDevice *device)
 
 	priv = NM_DEVICE_GET_PRIVATE (device);
 	if (!priv->product)
-		_device_update_description (device);
+		nm_device_update_description (device);
 	return priv->product;
 }
 
@@ -1340,7 +1344,7 @@ nm_device_get_vendor (NMDevice *device)
 
 	priv = NM_DEVICE_GET_PRIVATE (device);
 	if (!priv->vendor)
-		_device_update_description (device);
+		nm_device_update_description (device);
 	return priv->vendor;
 }
 
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index cd9d53f..e2e5988 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -40,6 +40,7 @@
 #include "nm-setting-pppoe.h"
 #include "nm-setting-wimax.h"
 #include "nm-setting-wired.h"
+#include "nm-setting-adsl.h"
 #include "nm-setting-wireless.h"
 #include "nm-setting-wireless-security.h"
 #include "nm-setting-vpn.h"
@@ -134,7 +135,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 static GHashTable *registered_settings = NULL;
 
-#define DEFAULT_MAP_SIZE 16
+#define DEFAULT_MAP_SIZE 17
 
 static struct SettingInfo {
 	const char *name;
@@ -261,6 +262,11 @@ register_default_settings (void)
 	                      NM_SETTING_PPPOE_ERROR,
 	                      3, TRUE);
 
+	register_one_setting (NM_SETTING_ADSL_SETTING_NAME,
+	                      NM_TYPE_SETTING_ADSL,
+	                      NM_SETTING_ADSL_ERROR,
+	                      3, TRUE);
+
 	register_one_setting (NM_SETTING_802_1X_SETTING_NAME,
 	                      NM_TYPE_SETTING_802_1X,
 	                      NM_SETTING_802_1X_ERROR,
@@ -1453,6 +1459,23 @@ nm_connection_get_setting_wired (NMConnection *connection)
 }
 
 /**
+ * nm_connection_get_setting_adsl:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingAdsl the connection might contain.
+ *
+ * Returns: (transfer none): an #NMSettingAdsl if the connection contains one, otherwise NULL
+ **/
+NMSettingAdsl *
+nm_connection_get_setting_adsl (NMConnection *connection)
+{
+	g_return_val_if_fail (connection != NULL, NULL);
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+	return (NMSettingAdsl *) nm_connection_get_setting (connection, NM_TYPE_SETTING_ADSL);
+}
+
+/**
  * nm_connection_get_setting_wireless:
  * @connection: the #NMConnection
  *
diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h
index 87b053c..2e42265 100644
--- a/libnm-util/nm-connection.h
+++ b/libnm-util/nm-connection.h
@@ -43,6 +43,7 @@
 #include <nm-setting-vpn.h>
 #include <nm-setting-wimax.h>
 #include <nm-setting-wired.h>
+#include <nm-setting-adsl.h>
 #include <nm-setting-wireless.h>
 #include <nm-setting-wireless-security.h>
 
@@ -184,6 +185,7 @@ NMSettingPPP *             nm_connection_get_setting_ppp               (NMConnec
 NMSettingPPPOE *           nm_connection_get_setting_pppoe             (NMConnection *connection);
 NMSettingVPN *             nm_connection_get_setting_vpn               (NMConnection *connection);
 NMSettingWimax *           nm_connection_get_setting_wimax             (NMConnection *connection);
+NMSettingAdsl *            nm_connection_get_setting_adsl              (NMConnection *connection);
 NMSettingWired *           nm_connection_get_setting_wired             (NMConnection *connection);
 NMSettingWireless *        nm_connection_get_setting_wireless          (NMConnection *connection);
 NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security (NMConnection *connection);
-- 
1.7.4.1



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