NetworkManager r3877 - in branches/modem-manager: . introspection src src/modem-manager



Author: tambeti
Date: Thu Jul 31 14:27:33 2008
New Revision: 3877
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3877&view=rev

Log:
Use ModemManager.


Added:
   branches/modem-manager/src/modem-manager/
   branches/modem-manager/src/modem-manager/Makefile.am
   branches/modem-manager/src/modem-manager/nm-modem-device.c
   branches/modem-manager/src/modem-manager/nm-modem-device.h
   branches/modem-manager/src/modem-manager/nm-modem-manager.c
   branches/modem-manager/src/modem-manager/nm-modem-manager.h
   branches/modem-manager/src/modem-manager/nm-modem-types.h
Removed:
   branches/modem-manager/src/nm-cdma-device.c
   branches/modem-manager/src/nm-cdma-device.h
   branches/modem-manager/src/nm-gsm-device.c
   branches/modem-manager/src/nm-gsm-device.h
   branches/modem-manager/src/nm-serial-device.c
   branches/modem-manager/src/nm-serial-device.h
Modified:
   branches/modem-manager/configure.in
   branches/modem-manager/introspection/nm-device-gsm.xml
   branches/modem-manager/src/Makefile.am
   branches/modem-manager/src/NetworkManagerPolicy.c
   branches/modem-manager/src/nm-hal-manager.c
   branches/modem-manager/src/nm-manager.c

Modified: branches/modem-manager/configure.in
==============================================================================
--- branches/modem-manager/configure.in	(original)
+++ branches/modem-manager/configure.in	Thu Jul 31 14:27:33 2008
@@ -418,6 +418,7 @@
 src/supplicant-manager/Makefile
 src/ppp-manager/Makefile
 src/dnsmasq-manager/Makefile
+src/modem-manager/Makefile
 src/backends/Makefile
 libnm-util/libnm-util.pc
 libnm-util/Makefile

Modified: branches/modem-manager/introspection/nm-device-gsm.xml
==============================================================================
--- branches/modem-manager/introspection/nm-device-gsm.xml	(original)
+++ branches/modem-manager/introspection/nm-device-gsm.xml	Thu Jul 31 14:27:33 2008
@@ -3,6 +3,10 @@
 <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0";>
   <interface name="org.freedesktop.NetworkManager.Device.Gsm">
 
+   <signal name="SignalQuality">
+     <arg name="quality" type="u"/>
+   </signal>
+
     <signal name="PropertiesChanged">
         <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
             <tp:docstring>

Modified: branches/modem-manager/src/Makefile.am
==============================================================================
--- branches/modem-manager/src/Makefile.am	(original)
+++ branches/modem-manager/src/Makefile.am	Thu Jul 31 14:27:33 2008
@@ -5,7 +5,8 @@
 	supplicant-manager \
 	ppp-manager \
 	backends \
-	dnsmasq-manager
+	dnsmasq-manager \
+	modem-manager
 
 INCLUDES = -I${top_srcdir}                   \
            -I${top_srcdir}/include           \
@@ -15,6 +16,7 @@
            -I${top_srcdir}/src/dhcp-manager  \
            -I${top_srcdir}/src/supplicant-manager  \
            -I${top_srcdir}/src/dnsmasq-manager  \
+           -I${top_srcdir}/src/modem-manager  \
            -I${top_srcdir}/libnm-util \
            -I${top_srcdir}/callouts
 
@@ -59,12 +61,6 @@
 		nm-activation-request.h		\
 		nm-properties-changed-signal.c	\
 		nm-properties-changed-signal.h	\
-		nm-serial-device.c		\
-		nm-serial-device.h		\
-		nm-gsm-device.c		\
-		nm-gsm-device.h		\
-		nm-cdma-device.c		\
-		nm-cdma-device.h		\
 		wpa.c				\
 		wpa.h				\
 		nm-netlink.c			\
@@ -87,15 +83,6 @@
 nm-device-wifi-glue.h: $(top_srcdir)/introspection/nm-device-wifi.xml
 	dbus-binding-tool --prefix=nm_device_wifi --mode=glib-server --output=$@ $<
 
-nm-serial-device-glue.h: $(top_srcdir)/introspection/nm-device-serial.xml
-	dbus-binding-tool --prefix=nm_serial_device --mode=glib-server --output=$@ $<
-
-nm-cdma-device-glue.h: $(top_srcdir)/introspection/nm-device-cdma.xml
-	dbus-binding-tool --prefix=nm_cdma_device --mode=glib-server --output=$@ $<
-
-nm-gsm-device-glue.h: $(top_srcdir)/introspection/nm-device-gsm.xml
-	dbus-binding-tool --prefix=nm_gsm_device --mode=glib-server --output=$@ $<
-
 nm-ip4-config-glue.h: $(top_srcdir)/introspection/nm-ip4-config.xml
 	dbus-binding-tool --prefix=nm_ip4_config --mode=glib-server --output=$@ $<
 
@@ -111,9 +98,6 @@
 	nm-device-interface-glue.h			\
 	nm-device-ethernet-glue.h			\
 	nm-device-wifi-glue.h		\
-	nm-serial-device-glue.h \
-	nm-cdma-device-glue.h \
-	nm-gsm-device-glue.h \
 	nm-ip4-config-glue.h				\
 	nm-active-connection-glue.h \
 	nm-dhcp4-config-glue.h
@@ -148,6 +132,7 @@
 			./supplicant-manager/libsupplicant-manager.la		\
 			./dnsmasq-manager/libdnsmasq-manager.la		\
 			./ppp-manager/libppp-manager.la		\
+			./modem-manager/libmodem-manager.la		\
 			./backends/libnmbackend.la			\
 			$(top_builddir)/libnm-util/libnm-util.la
 

Modified: branches/modem-manager/src/NetworkManagerPolicy.c
==============================================================================
--- branches/modem-manager/src/NetworkManagerPolicy.c	(original)
+++ branches/modem-manager/src/NetworkManagerPolicy.c	Thu Jul 31 14:27:33 2008
@@ -41,8 +41,6 @@
 #include "nm-device.h"
 #include "nm-device-wifi.h"
 #include "nm-device-ethernet.h"
-#include "nm-gsm-device.h"
-#include "nm-cdma-device.h"
 #include "nm-dbus-manager.h"
 #include "nm-setting-ip4-config.h"
 #include "nm-setting-connection.h"
@@ -99,10 +97,10 @@
 static guint32
 get_device_priority (NMDevice *dev)
 {
-	if (NM_IS_CDMA_DEVICE (dev))
+	if (nm_device_get_device_type (dev) == NM_DEVICE_TYPE_CDMA)
 		return 2;
 
-	if (NM_IS_GSM_DEVICE (dev))
+	if (nm_device_get_device_type (dev) == NM_DEVICE_TYPE_GSM)
 		return 3;
 
 	if (NM_IS_DEVICE_WIFI (dev))

Added: branches/modem-manager/src/modem-manager/Makefile.am
==============================================================================
--- (empty file)
+++ branches/modem-manager/src/modem-manager/Makefile.am	Thu Jul 31 14:27:33 2008
@@ -0,0 +1,29 @@
+INCLUDES = \
+	-I${top_srcdir}/src \
+	-I${top_srcdir}/include \
+	-I${top_srcdir}/libnm-util \
+	-I${top_builddir}/marshallers
+
+noinst_LTLIBRARIES = libmodem-manager.la
+
+libmodem_manager_la_SOURCES = \
+	nm-modem-device.c \
+	nm-modem-device.h \
+	nm-modem-manager.h \
+	nm-modem-manager.c \
+	nm-modem-types.h
+
+libmodem_manager_la_CPPFLAGS = \
+	$(DBUS_CFLAGS)
+
+libmodem_manager_la_LIBADD = \
+	$(DBUS_LIBS) \
+	$(top_builddir)/marshallers/libmarshallers.la
+
+nm-gsm-device-glue.h: $(top_srcdir)/introspection/nm-device-gsm.xml
+	dbus-binding-tool --prefix=nm_gsm_device --mode=glib-server --output=$@ $<
+
+BUILT_SOURCES = \
+	nm-gsm-device-glue.h
+
+CLEANFILES = $(BUILT_SOURCES)

Added: branches/modem-manager/src/modem-manager/nm-modem-device.c
==============================================================================
--- (empty file)
+++ branches/modem-manager/src/modem-manager/nm-modem-device.c	Thu Jul 31 14:27:33 2008
@@ -0,0 +1,702 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
+#include <string.h>
+#include "nm-modem-device.h"
+#include "nm-device-private.h"
+#include "nm-device-interface.h"
+#include "nm-dbus-manager.h"
+#include "nm-setting-connection.h"
+#include "nm-setting-gsm.h"
+#include "nm-setting-cdma.h"
+#include "nm-marshal.h"
+#include "nm-properties-changed-signal.h"
+#include "nm-modem-types.h"
+#include "nm-utils.h"
+#include "nm-gsm-device-glue.h"
+
+G_DEFINE_TYPE (NMModemDevice, nm_modem_device, NM_TYPE_DEVICE)
+
+#define NM_MODEM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MODEM_DEVICE, NMModemDevicePrivate))
+
+enum {
+	PROP_0,
+	PROP_PATH,
+	PROP_TYPE,
+
+	LAST_PROP
+};
+
+enum {
+	MODEM_STATE_BEGIN,
+	MODEM_STATE_ENABLE,
+	MODEM_STATE_SET_PIN,
+	MODEM_STATE_REGISTER,
+	MODEM_STATE_CONNECT
+};
+
+typedef struct {
+	NMDBusManager *dbus_mgr;
+	char *path;
+	DBusGProxy *proxy;
+	NMPPPManager *ppp_manager;
+	NMIP4Config  *pending_ip4_config;
+
+	int modem_state;
+	guint state_to_disconnected_id;
+
+	/* PPP stats */
+	guint32 in_bytes;
+	guint32 out_bytes;
+} NMModemDevicePrivate;
+
+enum {
+	SIGNAL_QUALITY,
+	PPP_STATS,
+	PROPERTIES_CHANGED,
+
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+NMModemDevice *
+nm_modem_device_new (const char *path,
+				 const char *data_device,
+				 const char *driver,
+				 int device_type)
+{
+	g_return_val_if_fail (path != NULL, NULL);
+	g_return_val_if_fail (data_device != NULL, NULL);
+	g_return_val_if_fail (driver != NULL, NULL);
+
+
+	return (NMModemDevice *) g_object_new (NM_TYPE_MODEM_DEVICE,
+								    NM_DEVICE_INTERFACE_UDI, path,
+								    NM_DEVICE_INTERFACE_IFACE, data_device,
+								    NM_DEVICE_INTERFACE_DRIVER, driver,
+								    NM_DEVICE_INTERFACE_MANAGED, TRUE,
+								    NM_MODEM_DEVICE_PATH, path,
+								    NM_MODEM_DEVICE_TYPE, device_type,
+								    NULL);
+}
+
+NMPPPManager *
+nm_modem_device_get_ppp_manager (NMModemDevice *device)
+{
+	g_return_val_if_fail (NM_IS_MODEM_DEVICE (device), NULL);
+
+	return NM_MODEM_DEVICE_GET_PRIVATE (device)->ppp_manager;
+}
+
+static NMSetting *
+modem_device_get_setting (NMModemDevice *device, GType setting_type)
+{
+	NMActRequest *req;
+	NMSetting *setting = NULL;
+
+	req = nm_device_get_act_request (NM_DEVICE (device));
+	if (req) {
+		NMConnection *connection;
+
+		connection = nm_act_request_get_connection (req);
+		if (connection)
+			setting = nm_connection_get_setting (connection, setting_type);
+	}
+
+	return setting;
+}
+
+static void
+state_machine_cdma (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
+{
+	NMModemDevice *modem = NM_MODEM_DEVICE (user_data);
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (modem);
+	NMSettingCdma *setting;
+	GError *error = NULL;
+
+	setting = NM_SETTING_CDMA (modem_device_get_setting (modem, NM_TYPE_SETTING_CDMA));
+
+	if (call_id)
+		dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID);
+
+	if (error) {
+		nm_warning ("CDMA device connection failed: %s", error->message);
+		nm_device_state_changed (NM_DEVICE (modem), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NONE);
+		return;
+	}
+
+	switch (priv->modem_state) {
+	case MODEM_STATE_BEGIN:
+		priv->modem_state = MODEM_STATE_ENABLE;
+		dbus_g_proxy_begin_call (proxy, "Enable", state_machine_cdma,
+							modem, NULL,
+							G_TYPE_BOOLEAN, TRUE,
+							G_TYPE_INVALID);
+		break;
+	case MODEM_STATE_ENABLE:
+		priv->modem_state = MODEM_STATE_CONNECT;
+		dbus_g_proxy_begin_call (proxy, "Connect", state_machine_cdma,
+							modem, NULL,
+							G_TYPE_STRING, setting->number,
+							G_TYPE_STRING, "",
+							G_TYPE_INVALID);
+		break;
+	case MODEM_STATE_CONNECT:
+		nm_device_activate_schedule_stage2_device_config (NM_DEVICE (modem));
+		break;
+	default:
+		nm_warning ("Invalid modem state %d", priv->modem_state);
+		nm_device_state_changed (NM_DEVICE (modem), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NONE);
+		break;
+	}
+}
+
+static void
+state_machine_gsm (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
+{
+	NMModemDevice *modem = NM_MODEM_DEVICE (user_data);
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (modem);
+	NMSettingGsm *setting;
+	const char *secret = NULL;
+	const char *secret_name = NULL;
+	gboolean retry_secret = FALSE;
+	GError *error = NULL;
+
+	setting = NM_SETTING_GSM (modem_device_get_setting (modem, NM_TYPE_SETTING_GSM));
+
+	if (call_id)
+		dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID);
+
+	if (error) {
+		if (dbus_g_error_has_name (error, MM_MODEM_ERROR_PIN_NEEDED)) {
+			secret = setting->pin;
+			secret_name = NM_SETTING_GSM_PIN;
+			priv->modem_state = MODEM_STATE_SET_PIN;
+		} else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_PUK_NEEDED)) {
+			secret = setting->puk;
+			secret_name = NM_SETTING_GSM_PUK;
+			priv->modem_state = MODEM_STATE_SET_PIN;
+		} else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_INVALID_SECRET)) {
+			g_free (setting->pin);
+			setting->pin = NULL;
+			secret_name = NM_SETTING_GSM_PIN;
+			retry_secret = TRUE;
+			priv->modem_state = MODEM_STATE_SET_PIN;
+		} else {
+			nm_warning ("GSM device connection failed: %s", error->message);
+			nm_device_state_changed (NM_DEVICE (modem), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NONE);
+			return;
+		}
+	}
+
+	switch (priv->modem_state) {
+	case MODEM_STATE_BEGIN:
+		priv->modem_state = MODEM_STATE_ENABLE;
+		dbus_g_proxy_begin_call (proxy, "Enable", state_machine_gsm,
+							modem, NULL,
+							G_TYPE_BOOLEAN, TRUE,
+							G_TYPE_INVALID);
+		break;
+	case MODEM_STATE_ENABLE:
+		priv->modem_state = MODEM_STATE_REGISTER;
+		dbus_g_proxy_begin_call (proxy, "Register", state_machine_gsm,
+							modem, NULL,
+							G_TYPE_STRING, setting->network_id ? setting->network_id : "",
+							G_TYPE_INVALID);
+		break;
+	case MODEM_STATE_SET_PIN:
+		if (secret) {
+			priv->modem_state = MODEM_STATE_ENABLE;
+			dbus_g_proxy_begin_call (proxy, "SetPin", state_machine_gsm,
+								modem, NULL,
+								G_TYPE_STRING, secret,
+								G_TYPE_INVALID);
+		} else {
+			nm_device_state_changed (NM_DEVICE (modem), NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
+			nm_act_request_request_connection_secrets (nm_device_get_act_request (NM_DEVICE (modem)),
+											   NM_SETTING_GSM_SETTING_NAME,
+											   retry_secret,
+											   SECRETS_CALLER_GSM,
+											   secret_name,
+											   NULL);
+
+		}
+		break;
+	case MODEM_STATE_REGISTER:
+		priv->modem_state = MODEM_STATE_CONNECT;
+		dbus_g_proxy_begin_call (proxy, "Connect", state_machine_gsm,
+							modem, NULL,
+							G_TYPE_STRING, setting->number,
+							G_TYPE_STRING, setting->apn ? setting->apn : "",
+							G_TYPE_INVALID);
+		break;
+	case MODEM_STATE_CONNECT:
+		nm_device_activate_schedule_stage2_device_config (NM_DEVICE (modem));
+		break;
+	default:
+		nm_warning ("Invalid modem state %d", priv->modem_state);
+		nm_device_state_changed (NM_DEVICE (modem), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NONE);
+		break;
+	}
+}
+
+static NMActStageReturn
+real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (device);
+
+	priv->modem_state = MODEM_STATE_BEGIN;
+
+	if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_GSM)
+		state_machine_gsm (priv->proxy, NULL, device);
+	else
+		state_machine_cdma (priv->proxy, NULL, device);
+ 
+	return NM_ACT_STAGE_RETURN_POSTPONE;
+}
+
+static void
+ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data)
+{
+	NMDevice *device = NM_DEVICE (user_data);
+
+	switch (status) {
+	case NM_PPP_STATUS_NETWORK:
+		nm_device_state_changed (device, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE);
+		break;
+	case NM_PPP_STATUS_DISCONNECT:
+		nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_DISCONNECT);
+		break;
+	default:
+		break;
+	}
+}
+
+static void
+ppp_ip4_config (NMPPPManager *ppp_manager,
+			 const char *iface,
+			 NMIP4Config *config,
+			 gpointer user_data)
+{
+	NMDevice *device = NM_DEVICE (user_data);
+
+	nm_device_set_ip_iface (device, iface);
+	NM_MODEM_DEVICE_GET_PRIVATE (device)->pending_ip4_config = g_object_ref (config);
+	nm_device_activate_schedule_stage4_ip_config_get (device);
+}
+
+static void
+ppp_stats (NMPPPManager *ppp_manager,
+		 guint32 in_bytes,
+		 guint32 out_bytes,
+		 gpointer user_data)
+{
+	NMModemDevice *device = NM_MODEM_DEVICE (user_data);
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (device);
+
+	if (priv->in_bytes != in_bytes || priv->out_bytes != out_bytes) {
+		priv->in_bytes = in_bytes;
+		priv->out_bytes = out_bytes;
+
+		g_signal_emit (device, signals[PPP_STATS], 0, in_bytes, out_bytes);
+	}
+}
+
+static NMConnection *
+real_get_best_auto_connection (NMDevice *dev,
+                               GSList *connections,
+                               char **specific_object)
+{
+	GSList *iter;
+
+	for (iter = connections; iter; iter = g_slist_next (iter)) {
+		NMConnection *connection = NM_CONNECTION (iter->data);
+		NMSettingConnection *s_con;
+
+		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+		g_assert (s_con);
+
+		if (!s_con->autoconnect)
+			continue;
+
+		if (strcmp (s_con->type, NM_SETTING_GSM_SETTING_NAME))
+			continue;
+
+		return connection;
+	}
+	return NULL;
+}
+
+static NMActStageReturn
+real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (device);
+	NMActRequest *req;
+	GError *err = NULL;
+	NMActStageReturn ret;
+
+	req = nm_device_get_act_request (device);
+	g_assert (req);
+
+	priv->ppp_manager = nm_ppp_manager_new ();
+
+	if (nm_ppp_manager_start (priv->ppp_manager,
+						 nm_device_get_iface (device),
+						 req,
+						 &err)) {
+		g_signal_connect (priv->ppp_manager, "state-changed",
+					   G_CALLBACK (ppp_state_changed),
+					   device);
+		g_signal_connect (priv->ppp_manager, "ip4-config",
+					   G_CALLBACK (ppp_ip4_config),
+					   device);
+		g_signal_connect (priv->ppp_manager, "stats",
+					   G_CALLBACK (ppp_stats),
+					   device);
+
+		ret = NM_ACT_STAGE_RETURN_POSTPONE;
+	} else {
+		nm_warning ("%s", err->message);
+		g_error_free (err);
+
+		g_object_unref (priv->ppp_manager);
+		priv->ppp_manager = NULL;
+
+		*reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED;
+		ret = NM_ACT_STAGE_RETURN_FAILURE;
+	}
+
+	return ret;
+}
+
+static NMActStageReturn
+real_act_stage4_get_ip4_config (NMDevice *device,
+                                NMIP4Config **config,
+                                NMDeviceStateReason *reason)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (device);
+
+	*config = priv->pending_ip4_config;
+	priv->pending_ip4_config = NULL;
+
+	return NM_ACT_STAGE_RETURN_SUCCESS;
+}
+
+static void
+real_connection_secrets_updated (NMDevice *dev,
+                                 NMConnection *connection,
+                                 GSList *updated_settings,
+                                 RequestSecretsCaller caller)
+{
+	NMActRequest *req;
+	gboolean found = FALSE;
+	GSList *iter;
+
+	if (caller == SECRETS_CALLER_PPP) {
+		NMPPPManager *ppp_manager;
+		NMSettingGsm *s_gsm = NULL;
+
+		ppp_manager = nm_modem_device_get_ppp_manager (NM_MODEM_DEVICE (dev));
+		g_return_if_fail (ppp_manager != NULL);
+
+		s_gsm = (NMSettingGsm *) nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM);
+		if (!s_gsm) {
+			/* Shouldn't ever happen */
+			nm_ppp_manager_update_secrets (ppp_manager,
+			                               nm_device_get_iface (dev),
+			                               NULL,
+			                               NULL,
+			                               "missing GSM setting; no secrets could be found.");
+		} else {
+			nm_ppp_manager_update_secrets (ppp_manager,
+			                               nm_device_get_iface (dev),
+			                               s_gsm->username ? s_gsm->username : "",
+			                               s_gsm->password ? s_gsm->password : "",
+			                               NULL);
+		}
+		return;
+	}
+
+	g_return_if_fail (caller == SECRETS_CALLER_GSM);
+	g_return_if_fail (nm_device_get_state (dev) == NM_DEVICE_STATE_NEED_AUTH);
+
+	for (iter = updated_settings; iter; iter = g_slist_next (iter)) {
+		const char *setting_name = (const char *) iter->data;
+
+		if (!strcmp (setting_name, NM_SETTING_GSM_SETTING_NAME))
+			found = TRUE;
+		else
+			nm_warning ("Ignoring updated secrets for setting '%s'.", setting_name);
+	}
+
+	if (!found)
+		return;
+
+	req = nm_device_get_act_request (dev);
+	g_assert (req);
+
+	g_return_if_fail (nm_act_request_get_connection (req) == connection);
+
+	nm_device_activate_schedule_stage1_device_prepare (dev);
+}
+
+static void
+real_deactivate_quickly (NMDevice *device)
+{
+	//NMModemDevice *self = NM_MODEM_DEVICE (device);
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (device);
+
+	nm_device_set_ip_iface (device, NULL);
+
+	if (priv->pending_ip4_config) {
+		g_object_unref (priv->pending_ip4_config);
+		priv->pending_ip4_config = NULL;
+	}
+
+	priv->in_bytes = priv->out_bytes = 0;
+
+	if (priv->ppp_manager) {
+		g_object_unref (priv->ppp_manager);
+		priv->ppp_manager = NULL;
+	}
+
+	//nm_modem_device_close (self);
+}
+
+static guint32
+real_get_generic_capabilities (NMDevice *dev)
+{
+	return NM_DEVICE_CAP_NM_SUPPORTED;
+}
+
+static gboolean
+unavailable_to_disconnected (gpointer user_data)
+{
+	nm_device_state_changed (NM_DEVICE (user_data),
+	                         NM_DEVICE_STATE_DISCONNECTED,
+	                         NM_DEVICE_STATE_REASON_NONE);
+	return FALSE;
+}
+
+static void
+device_state_changed (NMDeviceInterface *device,
+                      NMDeviceState new_state,
+                      NMDeviceState old_state,
+                      NMDeviceStateReason reason,
+                      gpointer user_data)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (user_data);
+
+	/* Remove any previous delayed transition to disconnected */
+	if (priv->state_to_disconnected_id) {
+		g_source_remove (priv->state_to_disconnected_id);
+		priv->state_to_disconnected_id = 0;
+	}
+
+	/* If transitioning to UNAVAILBLE and we have a carrier, transition to
+	 * DISCONNECTED because the device is ready to use.  Otherwise the carrier-on
+	 * handler will handle the transition to DISCONNECTED when the carrier is detected.
+	 */
+	if (new_state == NM_DEVICE_STATE_UNAVAILABLE)
+		priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, user_data);
+
+	/* Make sure we don't leave the serial device open */
+	switch (new_state) {
+	case NM_DEVICE_STATE_NEED_AUTH:
+	case NM_DEVICE_STATE_UNMANAGED:
+	case NM_DEVICE_STATE_UNAVAILABLE:
+	case NM_DEVICE_STATE_FAILED:
+	case NM_DEVICE_STATE_DISCONNECTED:
+		dbus_g_proxy_call_no_reply (priv->proxy, "Disconnect", G_TYPE_INVALID);
+		break;
+	default:
+		break;
+	}
+}
+
+static void
+signal_quality_proxy (DBusGProxy *proxy, guint32 quality, gpointer user_data)
+{
+	g_signal_emit (NM_MODEM_DEVICE (user_data), signals[SIGNAL_QUALITY], 0, quality);
+}
+
+/*****************************************************************************/
+
+static void
+nm_modem_device_init (NMModemDevice *self)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (self);
+
+	priv->dbus_mgr = nm_dbus_manager_get ();
+}
+
+static GObject*
+constructor (GType type,
+		   guint n_construct_params,
+		   GObjectConstructParam *construct_params)
+{
+	GObject *object;
+	NMModemDevicePrivate *priv;
+
+	object = G_OBJECT_CLASS (nm_modem_device_parent_class)->constructor (type,
+														    n_construct_params,
+														    construct_params);
+	if (!object)
+		return NULL;
+
+	priv = NM_MODEM_DEVICE_GET_PRIVATE (object);
+
+	if (!priv->path) {
+		g_warning ("DBus path not provided");
+		goto err;
+	}
+
+	if (nm_device_get_device_type (NM_DEVICE (object)) != NM_DEVICE_TYPE_GSM &&
+	    nm_device_get_device_type (NM_DEVICE (object)) != NM_DEVICE_TYPE_CDMA) {
+		g_warning ("Invalid modem type");
+		goto err;
+	}
+
+	priv->proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_mgr),
+									 MM_DBUS_SERVICE, priv->path, MM_DBUS_INTERFACE_MODEM);
+
+	dbus_g_proxy_add_signal (priv->proxy, "SignalQuality", G_TYPE_UINT, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal (priv->proxy, "SignalQuality",
+						    G_CALLBACK (signal_quality_proxy),
+						    object,
+						    NULL);
+
+	g_signal_connect (object, "state-changed", G_CALLBACK (device_state_changed), object);
+
+	return object;
+
+ err:
+	g_object_unref (object);
+	return NULL;
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+		    GValue *value, GParamSpec *pspec)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (object);
+
+	switch (prop_id) {
+	case PROP_PATH:
+		g_value_set_string (value, priv->path);
+		break;
+	case PROP_TYPE:
+		g_value_set_uint (value, nm_device_get_device_type (NM_DEVICE (object)));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+		    const GValue *value, GParamSpec *pspec)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (object);
+
+	switch (prop_id) {
+	case PROP_PATH:
+		/* Construct only */
+		priv->path = g_value_dup_string (value);
+		break;
+	case PROP_TYPE:
+		nm_device_set_device_type (NM_DEVICE (object), g_value_get_uint (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+finalize (GObject *object)
+{
+	NMModemDevicePrivate *priv = NM_MODEM_DEVICE_GET_PRIVATE (object);
+
+	if (priv->state_to_disconnected_id) {
+		g_source_remove (priv->state_to_disconnected_id);
+		priv->state_to_disconnected_id = 0;
+	}
+
+	if (priv->proxy)
+		g_object_unref (priv->proxy);
+
+	g_object_unref (priv->dbus_mgr);
+
+	G_OBJECT_CLASS (nm_modem_device_parent_class)->finalize (object);
+}
+
+static void
+nm_modem_device_class_init (NMModemDeviceClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
+
+	g_type_class_add_private (object_class, sizeof (NMModemDevicePrivate));
+
+	/* Virtual methods */
+	object_class->constructor = constructor;
+	object_class->set_property = set_property;
+	object_class->get_property = get_property;
+	object_class->finalize = finalize;
+
+	device_class->get_best_auto_connection = real_get_best_auto_connection;
+	device_class->get_generic_capabilities = real_get_generic_capabilities;
+	device_class->connection_secrets_updated = real_connection_secrets_updated;
+	device_class->act_stage1_prepare = real_act_stage1_prepare;
+	device_class->act_stage2_config = real_act_stage2_config;
+	device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
+	device_class->deactivate_quickly = real_deactivate_quickly;
+
+	/* Properties */
+	g_object_class_install_property
+		(object_class, PROP_PATH,
+		 g_param_spec_string (NM_MODEM_DEVICE_PATH,
+						  "DBus path",
+						  "DBus path",
+						  NULL,
+						  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property
+		(object_class, PROP_TYPE,
+		 g_param_spec_uint (NM_MODEM_DEVICE_TYPE,
+						"Type",
+						"NMDeviceType",
+						NM_DEVICE_TYPE_UNKNOWN, NM_DEVICE_TYPE_CDMA, NM_DEVICE_TYPE_UNKNOWN,
+						G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+	/* Signals */
+	signals[SIGNAL_QUALITY] =
+		g_signal_new ("signal-quality",
+				    G_OBJECT_CLASS_TYPE (object_class),
+				    G_SIGNAL_RUN_FIRST,
+				    G_STRUCT_OFFSET (NMModemDeviceClass, signal_quality),
+				    NULL, NULL,
+				    g_cclosure_marshal_VOID__UINT,
+				    G_TYPE_NONE, 1,
+				    G_TYPE_UINT);
+
+	signals[PPP_STATS] =
+		g_signal_new ("ppp-stats",
+				    G_OBJECT_CLASS_TYPE (object_class),
+				    G_SIGNAL_RUN_FIRST,
+				    G_STRUCT_OFFSET (NMModemDeviceClass, ppp_stats),
+				    NULL, NULL,
+				    nm_marshal_VOID__UINT_UINT,
+				    G_TYPE_NONE, 2,
+				    G_TYPE_UINT, G_TYPE_UINT);
+
+	signals[PROPERTIES_CHANGED] = 
+		nm_properties_changed_signal_new (object_class,
+								    G_STRUCT_OFFSET (NMModemDeviceClass, properties_changed));
+
+	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
+							   &dbus_glib_nm_gsm_device_object_info);
+}

Added: branches/modem-manager/src/modem-manager/nm-modem-device.h
==============================================================================
--- (empty file)
+++ branches/modem-manager/src/modem-manager/nm-modem-device.h	Thu Jul 31 14:27:33 2008
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
+#ifndef NM_MODEM_DEVICE_H
+#define NM_MODEM_DEVICE_H
+
+#include <nm-device.h>
+#include "ppp-manager/nm-ppp-manager.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_MODEM_DEVICE			(nm_modem_device_get_type ())
+#define NM_MODEM_DEVICE(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_DEVICE, NMModemDevice))
+#define NM_MODEM_DEVICE_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass),  NM_TYPE_MODEM_DEVICE, NMModemDeviceClass))
+#define NM_IS_MODEM_DEVICE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_DEVICE))
+#define NM_IS_MODEM_DEVICE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass),  NM_TYPE_MODEM_DEVICE))
+#define NM_MODEM_DEVICE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj),  NM_TYPE_MODEM_DEVICE, NMModemDeviceClass))
+
+#define NM_MODEM_DEVICE_PATH "path"
+#define NM_MODEM_DEVICE_TYPE "type"
+
+typedef struct {
+	NMDevice parent;
+} NMModemDevice;
+
+typedef struct {
+	NMDeviceClass parent;
+
+	/* Signals */
+	void (*signal_quality) (NMModemDevice *device, guint32 quality);
+	void (*ppp_stats) (NMModemDevice *device, guint32 in_bytes, guint32 out_bytes);
+	void (*properties_changed) (NMModemDevice *device, GHashTable *properties);
+} NMModemDeviceClass;
+
+GType nm_modem_device_get_type (void);
+
+NMModemDevice *nm_modem_device_new (const char *path,
+							 const char *data_device,
+							 const char *driver,
+							 int device_type);
+
+NMPPPManager *nm_modem_device_get_ppp_manager (NMModemDevice *device);
+
+G_END_DECLS
+
+#endif /* NM_MODEM_DEVICE_H */

Added: branches/modem-manager/src/modem-manager/nm-modem-manager.c
==============================================================================
--- (empty file)
+++ branches/modem-manager/src/modem-manager/nm-modem-manager.c	Thu Jul 31 14:27:33 2008
@@ -0,0 +1,381 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
+#include <string.h>
+#include "nm-modem-manager.h"
+#include "nm-modem-device.h"
+#include "nm-dbus-manager.h"
+#include "nm-utils.h"
+#include "nm-modem-types.h"
+
+#define MODEM_POKE_INTERVAL 120000
+
+G_DEFINE_TYPE (NMModemManager, nm_modem_manager, G_TYPE_OBJECT)
+
+#define NM_MODEM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MODEM_MANAGER, NMModemManagerPrivate))
+
+typedef struct {
+	NMDBusManager *dbus_mgr;
+	DBusGProxy *proxy;
+	GHashTable *modems;
+	gboolean disposed;
+	guint poke_id;
+} NMModemManagerPrivate;
+
+enum {
+	DEVICE_ADDED,
+	DEVICE_REMOVED,
+
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+NMModemManager *
+nm_modem_manager_get (void)
+{
+	static NMModemManager *singleton = NULL;
+
+	if (!singleton)
+		singleton = NM_MODEM_MANAGER (g_object_new (NM_TYPE_MODEM_MANAGER, NULL));
+	else
+		g_object_ref (singleton);
+
+	g_assert (singleton);
+	return singleton;
+}
+
+static gboolean
+get_modem_properties (DBusGConnection *connection,
+				  const char *path,
+				  char **data_device,
+				  char **driver,
+				  guint32 *type)
+{
+	DBusGProxy *proxy;
+	GValue value = { 0 };
+	GError *err = NULL;
+
+	proxy = dbus_g_proxy_new_for_name (connection,
+								MM_DBUS_SERVICE,
+								path,
+								"org.freedesktop.DBus.Properties");
+
+	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
+								 G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
+								 G_TYPE_STRING, "Type",
+								 G_TYPE_INVALID,
+								 G_TYPE_VALUE, &value,
+								 G_TYPE_INVALID)) {
+		*type = g_value_get_uint (&value);
+		g_value_unset (&value);
+	} else {
+		g_warning ("Could not get modem data device: %s", err->message);
+		goto out;
+	}
+
+	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
+								 G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
+								 G_TYPE_STRING, "DataDevice",
+								 G_TYPE_INVALID,
+								 G_TYPE_VALUE, &value,
+								 G_TYPE_INVALID)) {
+		*data_device = g_value_dup_string (&value);
+		g_value_unset (&value);
+	} else {
+		g_warning ("Could not get modem data device: %s", err->message);
+		goto out;
+	}
+
+	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
+								 G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
+								 G_TYPE_STRING, "Driver",
+								 G_TYPE_INVALID,
+								 G_TYPE_VALUE, &value,
+								 G_TYPE_INVALID)) {
+		*driver = g_value_dup_string (&value);
+		g_value_unset (&value);
+	} else {
+		g_warning ("Could not get modem driver: %s", err->message);
+		goto out;
+	}
+
+ out:
+	if (err)
+		g_error_free (err);
+
+	g_object_unref (proxy);
+
+	return *data_device && *driver;
+}
+
+static void
+create_modem (NMModemManager *manager, const char *path)
+{
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (manager);
+	NMModemDevice *modem;
+	char *data_device;
+	char *driver;
+	uint modem_type;
+
+	if (g_hash_table_lookup (priv->modems, path)) {
+		nm_warning ("Modem with path %s already exists, ignoring", path);
+		return;
+	}
+
+	if (!get_modem_properties (nm_dbus_manager_get_connection (priv->dbus_mgr), path,
+						  &data_device, &driver, &modem_type))
+		return;
+
+	modem = nm_modem_device_new (path,
+						    data_device,
+						    driver,
+						    modem_type == MM_MODEM_TYPE_GSM ? DEVICE_TYPE_GSM : DEVICE_TYPE_CDMA);
+
+	g_free (data_device);
+	g_free (driver);
+
+	if (modem) {
+		g_hash_table_insert (priv->modems, g_strdup (path), g_object_ref (modem));
+		g_signal_emit (manager, signals[DEVICE_ADDED], 0, modem);
+	}
+}
+
+static void
+modem_added (DBusGProxy *proxy, const char *path, gpointer user_data)
+{
+	g_print ("Modem added %s\n", path);
+	create_modem (NM_MODEM_MANAGER (user_data), path);
+}
+
+static void
+modem_removed (DBusGProxy *proxy, const char *path, gpointer user_data)
+{
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (user_data);
+	NMModemDevice *modem;
+
+	g_print ("Modem removed %s\n", path);
+
+	modem = (NMModemDevice *) g_hash_table_lookup (priv->modems, path);
+	if (modem) {
+		g_signal_emit (user_data, signals[DEVICE_REMOVED], 0, modem);
+		g_hash_table_remove (priv->modems, path);
+	}
+}
+
+static void
+get_modems_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer data)
+{
+	NMModemManager *manager = NM_MODEM_MANAGER (data);
+	GPtrArray *modems;
+	GError *error = NULL;
+
+	if (!dbus_g_proxy_end_call (proxy, call_id, &error,
+						   dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &modems,
+						   G_TYPE_INVALID)) {
+		nm_warning ("Could not get modem list: %s", error->message);
+		g_error_free (error);
+	} else {
+		int i;
+
+		for (i = 0; i < modems->len; i++) {
+			char *path = (char *) g_ptr_array_index (modems, i);
+
+			g_print ("Got modem: %s\n", path);
+			create_modem (manager, path);
+			g_free (path);
+		}
+
+		g_ptr_array_free (modems, TRUE);
+	}
+}
+
+static gboolean
+get_modems (gpointer data)
+{
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (data);
+
+	priv->proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_mgr),
+									 MM_DBUS_SERVICE, MM_DBUS_PATH, MM_DBUS_INTERFACE);
+
+	dbus_g_proxy_add_signal (priv->proxy, "DeviceAdded", G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal (priv->proxy, "DeviceAdded",
+						    G_CALLBACK (modem_added),
+						    data,
+						    NULL);
+
+	dbus_g_proxy_add_signal (priv->proxy, "DeviceRemoved", G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal (priv->proxy, "DeviceRemoved",
+						    G_CALLBACK (modem_removed),
+						    data,
+						    NULL);
+
+	dbus_g_proxy_begin_call (priv->proxy, "EnumerateDevices", get_modems_cb, data, NULL, G_TYPE_INVALID);
+
+	return FALSE;
+}
+
+static gboolean
+nm_modem_manager_startup (NMModemManager *self)
+{
+	gboolean running;
+
+	running = nm_dbus_manager_name_has_owner (NM_MODEM_MANAGER_GET_PRIVATE (self)->dbus_mgr, MM_DBUS_SERVICE);
+	if (running) {
+		g_idle_add (get_modems, self);
+	}
+
+	return running;
+}
+
+static gboolean
+poke_modem_cb (gpointer user_data)
+{
+	NMModemManager *self = NM_MODEM_MANAGER (user_data);
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (self);
+	DBusGConnection *g_connection;
+	DBusGProxy *proxy;
+
+	g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
+	proxy = dbus_g_proxy_new_for_name (g_connection,
+	                                   MM_DBUS_SERVICE,
+	                                   MM_DBUS_PATH,
+	                                   MM_DBUS_INTERFACE);
+	if (!proxy) {
+		nm_warning ("Error: could not init wpa_modem proxy");
+		goto out;
+	}
+
+	nm_info ("Trying to start the modem-manager...");
+	dbus_g_proxy_call_no_reply (proxy, "EnumerateDevices", G_TYPE_INVALID);
+	g_object_unref (proxy);
+
+out:
+	/* Reschedule the poke */	
+	priv->poke_id = g_timeout_add (MODEM_POKE_INTERVAL, poke_modem_cb, self);
+
+	return FALSE;
+}
+
+static void
+nm_modem_manager_name_owner_changed (NMDBusManager *dbus_mgr,
+							  const char *name,
+							  const char *old_owner,
+							  const char *new_owner,
+							  gpointer user_data)
+{
+	NMModemManager * self = (NMModemManager *) user_data;
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (self);
+	gboolean old_owner_good = (old_owner && strlen (old_owner));
+	gboolean new_owner_good = (new_owner && strlen (new_owner));
+
+	/* Can't handle the signal if its not from the modem service */
+	if (strcmp (MM_DBUS_SERVICE, name) != 0)
+		return;
+
+	if (!old_owner_good && new_owner_good) {
+		gboolean running;
+
+		running = nm_modem_manager_startup (self);
+
+		if (running && priv->poke_id) {
+			g_source_remove (priv->poke_id);
+			priv->poke_id = 0;
+		}
+	} else if (old_owner_good && !new_owner_good) {
+		if (priv->proxy) {
+			g_object_unref (priv->proxy);
+			priv->proxy = NULL;
+		}
+
+		/* Poke the modem so that it gets activated by dbus system bus
+		 * activation.
+		 */
+		if (!priv->poke_id)
+			priv->poke_id = g_idle_add (poke_modem_cb, (gpointer) self);
+	}
+}
+
+static void
+nm_modem_manager_init (NMModemManager *self)
+{
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (self);
+	gboolean running;
+
+	priv->modems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+	priv->dbus_mgr = nm_dbus_manager_get ();
+
+	running = nm_modem_manager_startup (self);
+
+	g_signal_connect (priv->dbus_mgr,
+	                  "name-owner-changed",
+	                  G_CALLBACK (nm_modem_manager_name_owner_changed),
+	                  self);
+
+	if (!running) {
+		/* Try to activate the modem-manager */
+		priv->poke_id = g_idle_add (poke_modem_cb, (gpointer) self);
+	}
+}
+
+static void
+dispose (GObject *object)
+{
+	NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE (object);
+
+	if (priv->disposed)
+		return;
+
+	priv->disposed = TRUE;
+
+	if (priv->poke_id) {
+		g_source_remove (priv->poke_id);
+		priv->poke_id = 0;
+	}
+
+	g_hash_table_destroy (priv->modems);
+
+	if (priv->proxy) {
+		g_object_unref (priv->proxy);
+		priv->proxy = NULL;
+	}
+
+	if (priv->dbus_mgr) {
+		g_object_unref (priv->dbus_mgr);
+		priv->dbus_mgr = NULL;
+	}
+
+	/* Chain up to the parent class */
+	G_OBJECT_CLASS (nm_modem_manager_parent_class)->dispose (object);
+}
+
+static void
+nm_modem_manager_class_init (NMModemManagerClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (object_class, sizeof (NMModemManagerPrivate));
+
+	object_class->dispose = dispose;
+
+	/* signals */
+	signals[DEVICE_ADDED] =
+		g_signal_new ("device-added",
+				    G_OBJECT_CLASS_TYPE (object_class),
+				    G_SIGNAL_RUN_FIRST,
+				    G_STRUCT_OFFSET (NMModemManagerClass, device_added),
+				    NULL, NULL,
+				    g_cclosure_marshal_VOID__OBJECT,
+				    G_TYPE_NONE, 1,
+				    G_TYPE_OBJECT);
+
+	signals[DEVICE_REMOVED] =
+		g_signal_new ("device-removed",
+				    G_OBJECT_CLASS_TYPE (object_class),
+				    G_SIGNAL_RUN_FIRST,
+				    G_STRUCT_OFFSET (NMModemManagerClass, device_removed),
+				    NULL, NULL,
+				    g_cclosure_marshal_VOID__OBJECT,
+				    G_TYPE_NONE, 1,
+				    G_TYPE_OBJECT);
+}

Added: branches/modem-manager/src/modem-manager/nm-modem-manager.h
==============================================================================
--- (empty file)
+++ branches/modem-manager/src/modem-manager/nm-modem-manager.h	Thu Jul 31 14:27:33 2008
@@ -0,0 +1,35 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
+#ifndef NM_MODEM_MANAGER_H
+#define NM_MODEM_MANAGER_H
+
+#include <glib-object.h>
+#include "nm-device.h"
+
+#define NM_TYPE_MODEM_MANAGER				(nm_modem_manager_get_type ())
+#define NM_MODEM_MANAGER(obj)				(G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_MANAGER, NMModemManager))
+#define NM_MODEM_MANAGER_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass),  NM_TYPE_MODEM_MANAGER, NMModemManagerClass))
+#define NM_IS_MODEM_MANAGER(obj)			(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_MANAGER))
+#define NM_IS_MODEM_MANAGER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass),  NM_TYPE_MODEM_MANAGER))
+#define NM_MODEM_MANAGER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj),  NM_TYPE_MODEM_MANAGER, NMModemManagerClass))
+
+typedef struct {
+	GObject parent;
+} NMModemManager;
+
+typedef struct {
+	GObjectClass parent;
+
+	/* Signals */
+	void (*device_added) (NMModemManager *manager,
+					  NMDevice *device);
+
+	void (*device_removed) (NMModemManager *manager,
+					    NMDevice *device);
+} NMModemManagerClass;
+
+GType nm_modem_manager_get_type (void);
+
+NMModemManager *nm_modem_manager_get (void);
+
+#endif /* NM_MODEM_MANAGER_H */

Added: branches/modem-manager/src/modem-manager/nm-modem-types.h
==============================================================================
--- (empty file)
+++ branches/modem-manager/src/modem-manager/nm-modem-types.h	Thu Jul 31 14:27:33 2008
@@ -0,0 +1,19 @@
+/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+
+#ifndef NM_MODEM_TYPES_H
+#define NM_MODEM_TYPES_H
+
+#define MM_DBUS_SERVICE         "org.freedesktop.ModemManager"
+#define MM_DBUS_PATH            "/org/freedesktop/ModemManager"
+#define MM_DBUS_INTERFACE       "org.freedesktop.ModemManager"
+#define MM_DBUS_INTERFACE_MODEM "org.freedesktop.ModemManager.Modem"
+
+#define MM_MODEM_TYPE_GSM  1
+#define MM_MODEM_TYPE_CDMA 2
+
+#define MM_MODEM_ERROR_GENERAL        MM_DBUS_INTERFACE_MODEM ".GeneralError"
+#define MM_MODEM_ERROR_PIN_NEEDED     MM_DBUS_INTERFACE_MODEM ".PINNeeded"
+#define MM_MODEM_ERROR_PUK_NEEDED     MM_DBUS_INTERFACE_MODEM ".PUKNeeded"
+#define MM_MODEM_ERROR_INVALID_SECRET MM_DBUS_INTERFACE_MODEM ".InvalidSecret"
+
+#endif /* NM_MODEM_TYPES_H */

Modified: branches/modem-manager/src/nm-hal-manager.c
==============================================================================
--- branches/modem-manager/src/nm-hal-manager.c	(original)
+++ branches/modem-manager/src/nm-hal-manager.c	Thu Jul 31 14:27:33 2008
@@ -13,8 +13,6 @@
 #include "nm-utils.h"
 #include "nm-device-wifi.h"
 #include "nm-device-ethernet.h"
-#include "nm-gsm-device.h"
-#include "nm-cdma-device.h"
 
 /* Killswitch poll frequency in seconds */
 #define RFKILL_POLL_FREQUENCY 6
@@ -199,93 +197,6 @@
 	return device;
 }
 
-/* Modem device creator */
-
-static gboolean
-is_modem_device (NMHalManager *self, const char *udi)
-{
-	NMHalManagerPrivate *priv = NM_HAL_MANAGER_GET_PRIVATE (self);
-	gboolean is_modem = FALSE;
-
-	if (libhal_device_property_exists (priv->hal_ctx, udi, "info.category", NULL)) {
-		char *category;
-
-		category = libhal_device_get_property_string (priv->hal_ctx, udi, "info.category", NULL);
-		if (category) {
-			is_modem = strcmp (category, "serial") == 0;
-			libhal_free_string (category);
-		}
-	}
-
-	return is_modem;
-}
-
-static GObject *
-modem_device_creator (NMHalManager *self, const char *udi, gboolean managed)
-{
-	NMHalManagerPrivate *priv = NM_HAL_MANAGER_GET_PRIVATE (self);
-	char *serial_device;
-	char *parent_udi;
-	char *driver_name = NULL;
-	GObject *device = NULL;
-	char **capabilities, **iter;
-	gboolean type_gsm = FALSE;
-	gboolean type_cdma = FALSE;
-
-	serial_device = libhal_device_get_property_string (priv->hal_ctx, udi, "serial.device", NULL);
-
-	/* Get the driver */
-	parent_udi = libhal_device_get_property_string (priv->hal_ctx, udi, "info.parent", NULL);
-	if (parent_udi) {
-		driver_name = libhal_device_get_property_string (priv->hal_ctx, parent_udi, "info.linux.driver", NULL);
-		libhal_free_string (parent_udi);
-	}
-
-	if (!serial_device || !driver_name)
-		goto out;
-
-	capabilities = libhal_device_get_property_strlist (priv->hal_ctx, udi, "modem.command_sets", NULL);
-	/* 'capabilites' may be NULL */
-	for (iter = capabilities; iter && *iter; iter++) {
-		if (!strcmp (*iter, "GSM-07.07")) {
-			type_gsm = TRUE;
-			break;
-		}
-		if (!strcmp (*iter, "IS-707-A")) {
-			type_cdma = TRUE;
-			break;
-		}
-	}
-	g_strfreev (capabilities);
-
-	/* Compatiblity with the pre-specification bits */
-	if (!type_gsm && !type_cdma) {
-		capabilities = libhal_device_get_property_strlist (priv->hal_ctx, udi, "info.capabilities", NULL);
-		for (iter = capabilities; *iter; iter++) {
-			if (!strcmp (*iter, "gsm")) {
-				type_gsm = TRUE;
-				break;
-			}
-			if (!strcmp (*iter, "cdma")) {
-				type_cdma = TRUE;
-				break;
-			}
-		}
-		g_strfreev (capabilities);
-	}
-
-	if (type_gsm)
-		device = (GObject *) nm_gsm_device_new (udi, serial_device + strlen ("/dev/"), NULL, driver_name, managed);
-	else if (type_cdma)
-		device = (GObject *) nm_cdma_device_new (udi, serial_device + strlen ("/dev/"), NULL, driver_name, managed);
-
-out:
-	libhal_free_string (serial_device);
-	libhal_free_string (driver_name);
-
-	return device;
-}
-
 static void
 register_built_in_creators (NMHalManager *self)
 {
@@ -307,14 +218,6 @@
 	creator->is_device_fn = is_wireless_device;
 	creator->creator_fn = wireless_device_creator;
 	priv->device_creators = g_slist_append (priv->device_creators, creator);
-
-	/* Modem */
-	creator = g_slice_new0 (DeviceCreator);
-	creator->device_type_name = g_strdup ("Modem");
-	creator->capability_str = g_strdup ("modem");
-	creator->is_device_fn = is_modem_device;
-	creator->creator_fn = modem_device_creator;
-	priv->device_creators = g_slist_append (priv->device_creators, creator);
 }
 
 static void

Modified: branches/modem-manager/src/nm-manager.c
==============================================================================
--- branches/modem-manager/src/nm-manager.c	(original)
+++ branches/modem-manager/src/nm-manager.c	Thu Jul 31 14:27:33 2008
@@ -7,6 +7,7 @@
 #include "nm-utils.h"
 #include "nm-dbus-manager.h"
 #include "nm-vpn-manager.h"
+#include "nm-modem-manager.h"
 #include "nm-device-interface.h"
 #include "nm-device-private.h"
 #include "nm-device-wifi.h"
@@ -70,6 +71,10 @@
 static void hal_manager_hal_reappeared_cb (NMHalManager *hal_mgr,
                                            gpointer user_data);
 
+static void add_device (NMManager *self, NMDevice *device, const char *type_name);
+static void remove_one_device (NMManager *manager, NMDevice *device);
+
+
 #define SSD_POKE_INTERVAL 120000
 
 typedef struct {
@@ -107,6 +112,10 @@
 	NMVPNManager *vpn_manager;
 	guint vpn_manager_id;
 
+	NMModemManager *modem_manager;
+	guint modem_added_id;
+	guint modem_removed_id;
+
 	DBusGProxy *aipd_proxy;
 
 	gboolean disposed;
@@ -212,6 +221,33 @@
 }
 
 static void
+modem_added (NMModemManager *modem_manager,
+		   NMDevice *modem,
+		   gpointer user_data)
+{
+	NMDeviceType type;
+	const char *type_name;
+
+	type = nm_device_get_device_type (NM_DEVICE (modem));
+	if (type == NM_DEVICE_TYPE_GSM)
+		type_name = "GSM modem";
+	else if (type == NM_DEVICE_TYPE_CDMA)
+		type_name = "CDMA modem";
+	else
+		type_name = "Unknown modem";
+
+	add_device (NM_MANAGER (user_data), modem, type_name);
+}
+
+static void
+modem_removed (NMModemManager *modem_manager,
+			NMDevice *modem,
+			gpointer user_data)
+{
+	remove_one_device (NM_MANAGER (user_data), modem);
+}
+
+static void
 aipd_handle_event (DBusGProxy *proxy,
                    const char *event,
                    const char *iface,
@@ -274,6 +310,12 @@
 	                                                g_free,
 	                                                g_object_unref);
 
+	priv->modem_manager = nm_modem_manager_get ();
+	priv->modem_added_id = g_signal_connect (priv->modem_manager, "device-added",
+									 G_CALLBACK (modem_added), manager);
+	priv->modem_removed_id = g_signal_connect (priv->modem_manager, "device-removed",
+									   G_CALLBACK (modem_removed), manager);
+
 	priv->vpn_manager = nm_vpn_manager_get ();
 	id = g_signal_connect (G_OBJECT (priv->vpn_manager), "connection-deactivated",
 	                       G_CALLBACK (vpn_manager_connection_deactivated_cb), manager);
@@ -452,6 +494,16 @@
 	}
 	g_object_unref (priv->vpn_manager);
 
+	if (priv->modem_added_id) {
+		g_source_remove (priv->modem_added_id);
+		priv->modem_added_id = 0;
+	}
+	if (priv->modem_removed_id) {
+		g_source_remove (priv->modem_removed_id);
+		priv->modem_removed_id = 0;
+	}
+	g_object_unref (priv->modem_manager);
+
 	g_object_unref (priv->dbus_mgr);
 	g_object_unref (priv->hal_mgr);
 
@@ -1523,58 +1575,66 @@
 }
 
 static void
-hal_manager_udi_added_cb (NMHalManager *hal_mgr,
-                          const char *udi,
-                          const char *type_name,
-                          NMDeviceCreatorFn creator_fn,
-                          gpointer user_data)
+add_device (NMManager *self, NMDevice *device, const char *type_name)
 {
-	NMManager *self = NM_MANAGER (user_data);
 	NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
-	GObject *device;
 	const char *iface;
 
-	if (priv->sleeping)
-		return;
-
-	/* Make sure the device is not already in the device list */
-	if (nm_manager_get_device_by_udi (self, udi))
-		return;
-
-	device = creator_fn (hal_mgr, udi, nm_manager_udi_is_managed (self, udi));
-	if (!device)
-		return;
-
 	priv->devices = g_slist_append (priv->devices, device);
 
 	g_signal_connect (device, "state-changed",
-					  G_CALLBACK (manager_device_state_changed),
-					  self);
+				   G_CALLBACK (manager_device_state_changed),
+				   self);
 
 	/* Attach to the access-point-added signal so that the manager can fill
 	 * non-SSID-broadcasting APs with an SSID.
 	 */
 	if (NM_IS_DEVICE_WIFI (device)) {
 		g_signal_connect (device, "hidden-ap-found",
-						  G_CALLBACK (manager_hidden_ap_found),
-						  self);
+					   G_CALLBACK (manager_hidden_ap_found),
+					   self);
 
 		/* Set initial rfkill state */
 		nm_device_wifi_set_enabled (NM_DEVICE_WIFI (device), priv->wireless_enabled);
 	}
 
-	iface = nm_device_get_iface (NM_DEVICE (device));
+	iface = nm_device_get_iface (device);
 	nm_info ("Found new %s device '%s'.", type_name, iface);
 
 	dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (priv->dbus_mgr),
 								  nm_device_get_udi (NM_DEVICE (device)),
-								  device);
-	nm_info ("(%s): exported as %s", iface, udi);
+								  G_OBJECT (device));
+	nm_info ("(%s): exported as %s", iface, nm_device_get_udi (device));
 
 	g_signal_emit (self, signals[DEVICE_ADDED], 0, device);
 }
 
 static void
+hal_manager_udi_added_cb (NMHalManager *hal_mgr,
+                          const char *udi,
+                          const char *type_name,
+                          NMDeviceCreatorFn creator_fn,
+                          gpointer user_data)
+{
+	NMManager *self = NM_MANAGER (user_data);
+	NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+	GObject *device;
+
+	if (priv->sleeping)
+		return;
+
+	/* Make sure the device is not already in the device list */
+	if (nm_manager_get_device_by_udi (self, udi))
+		return;
+
+	device = creator_fn (hal_mgr, udi, nm_manager_udi_is_managed (self, udi));
+	if (!device)
+		return;
+
+	add_device (self, NM_DEVICE (device), type_name);
+}
+
+static void
 hal_manager_udi_removed_cb (NMHalManager *manager,
                             const char *udi,
                             gpointer user_data)



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