summary refs log tree commit diff
path: root/src/nm-device-modem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nm-device-modem.c')
-rw-r--r--src/nm-device-modem.c192
1 files changed, 75 insertions, 117 deletions
diff --git a/src/nm-device-modem.c b/src/nm-device-modem.c
index 076bfa49..441f92ce 100644
--- a/src/nm-device-modem.c
+++ b/src/nm-device-modem.c
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2009 - 2011 Red Hat, Inc.
+ * Copyright (C) 2009 - 2010 Red Hat, Inc.
  */
 
 #include <glib.h>
@@ -23,38 +23,29 @@
 #include "nm-device-modem.h"
 #include "nm-device-interface.h"
 #include "nm-modem.h"
-#include "nm-modem-cdma.h"
-#include "nm-modem-gsm.h"
 #include "nm-device-private.h"
 #include "nm-properties-changed-signal.h"
-#include "nm-rfkill.h"
 #include "nm-marshal.h"
 #include "nm-logging.h"
 
 static void device_interface_init (NMDeviceInterface *iface_class);
 
-G_DEFINE_TYPE_EXTENDED (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE, 0,
+G_DEFINE_TYPE_EXTENDED (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE, G_TYPE_FLAG_ABSTRACT,
                         G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_INTERFACE, device_interface_init))
 
 #define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate))
 
-#include "nm-device-modem-glue.h"
-
 typedef struct {
 	NMModem *modem;
-	NMDeviceModemCapabilities caps;
-	NMDeviceModemCapabilities current_caps;
 } NMDeviceModemPrivate;
 
 enum {
 	PROP_0,
-	PROP_MODEM,
-	PROP_CAPABILITIES,
-	PROP_CURRENT_CAPABILITIES,
+	PROP_MODEM
 };
 
 enum {
-	PROPERTIES_CHANGED,
+	PPP_STATS,
 	ENABLE_CHANGED,
 	LAST_SIGNAL
 };
@@ -65,6 +56,15 @@ static void real_set_enabled (NMDeviceInterface *device, gboolean enabled);
 /*****************************************************************************/
 
 static void
+ppp_stats (NMModem *modem,
+		   guint32 in_bytes,
+		   guint32 out_bytes,
+		   gpointer user_data)
+{
+	g_signal_emit (G_OBJECT (user_data), signals[PPP_STATS], 0, in_bytes, out_bytes);
+}
+
+static void
 ppp_failed (NMModem *modem, NMDeviceStateReason reason, gpointer user_data)
 {
 	NMDevice *device = NM_DEVICE (user_data);
@@ -73,8 +73,6 @@ ppp_failed (NMModem *modem, NMDeviceStateReason reason, gpointer user_data)
 	case NM_DEVICE_STATE_PREPARE:
 	case NM_DEVICE_STATE_CONFIG:
 	case NM_DEVICE_STATE_NEED_AUTH:
-	case NM_DEVICE_STATE_IP_CHECK:
-	case NM_DEVICE_STATE_SECONDARIES:
 	case NM_DEVICE_STATE_ACTIVATED:
 		nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, reason);
 		break;
@@ -109,27 +107,22 @@ modem_prepare_result (NMModem *modem,
 }
 
 static void
-modem_auth_requested (NMModem *modem, gpointer user_data)
+modem_need_auth (NMModem *modem,
+	             const char *setting_name,
+	             gboolean retry,
+	             RequestSecretsCaller caller,
+	             const char *hint1,
+	             const char *hint2,
+	             gpointer user_data)
 {
-	nm_device_state_changed (NM_DEVICE (user_data),
-	                         NM_DEVICE_STATE_NEED_AUTH,
-	                         NM_DEVICE_STATE_REASON_NONE);
-}
+	NMDeviceModem *self = NM_DEVICE_MODEM (user_data);
+	NMActRequest *req;
 
-static void
-modem_auth_result (NMModem *modem, GError *error, gpointer user_data)
-{
-	NMDevice *device = NM_DEVICE (user_data);
+	req = nm_device_get_act_request (NM_DEVICE (self));
+	g_assert (req);
 
-	if (error) {
-		nm_device_state_changed (device,
-		                         NM_DEVICE_STATE_FAILED,
-		                         NM_DEVICE_STATE_REASON_NO_SECRETS);
-	} else {
-		/* Otherwise, on success for modem secrets we need to schedule stage1 again */
-		g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_NEED_AUTH);
-		nm_device_activate_schedule_stage1_device_prepare (device);
-	}
+	nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
+	nm_act_request_get_secrets (req, setting_name, retry, caller, hint1, hint2);
 }
 
 static void
@@ -212,26 +205,46 @@ real_get_best_auto_connection (NMDevice *device,
 	return nm_modem_get_best_auto_connection (priv->modem, connections, specific_object);
 }
 
-static gboolean
-real_check_connection_compatible (NMDevice *device,
-                                  NMConnection *connection,
-                                  GError **error)
+static void
+real_connection_secrets_updated (NMDevice *device,
+								 NMConnection *connection,
+								 GSList *updated_settings,
+								 RequestSecretsCaller caller)
 {
 	NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
+	NMActRequest *req;
 
-	return nm_modem_check_connection_compatible (priv->modem, connection, error);
+	g_return_if_fail (IS_ACTIVATING_STATE (nm_device_get_state (device)));
+
+	req = nm_device_get_act_request (device);
+	g_assert (req);
+
+	if (!nm_modem_connection_secrets_updated (priv->modem,
+                                              req,
+                                              connection,
+                                              updated_settings,
+                                              caller)) {
+		nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NO_SECRETS);
+		return;
+	}
+
+	/* PPP handles stuff itself... */
+	if (caller == SECRETS_CALLER_PPP)
+		return;
+
+	/* Otherwise, on success for modem secrets we need to schedule stage1 again */
+	g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_NEED_AUTH);
+	nm_device_activate_schedule_stage1_device_prepare (device);
 }
 
 static gboolean
-real_complete_connection (NMDevice *device,
-                          NMConnection *connection,
-                          const char *specific_object,
-                          const GSList *existing_connections,
-                          GError **error)
+real_check_connection_compatible (NMDevice *device,
+                                  NMConnection *connection,
+                                  GError **error)
 {
 	NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
 
-	return nm_modem_complete_connection (priv->modem, connection, existing_connections, error);
+	return nm_modem_check_connection_compatible (priv->modem, connection, error);
 }
 
 static gboolean
@@ -247,9 +260,9 @@ real_hw_bring_up (NMDevice *device, gboolean *no_firmware)
 }
 
 static void
-real_deactivate (NMDevice *device)
+real_deactivate_quickly (NMDevice *device)
 {
-	nm_modem_deactivate (NM_DEVICE_MODEM_GET_PRIVATE (device)->modem, device);
+	nm_modem_deactivate_quickly (NM_DEVICE_MODEM_GET_PRIVATE (device)->modem, device);
 }
 
 static NMActStageReturn
@@ -326,40 +339,6 @@ real_set_enabled (NMDeviceInterface *device, gboolean enabled)
 
 /*****************************************************************************/
 
-NMDevice *
-nm_device_modem_new (NMModem *modem, const char *driver)
-{
-	NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE;
-	const char *type_desc = NULL;
-
-	g_return_val_if_fail (modem != NULL, NULL);
-	g_return_val_if_fail (NM_IS_MODEM (modem), NULL);
-	g_return_val_if_fail (driver != NULL, NULL);
-
-	if (NM_IS_MODEM_CDMA (modem)) {
-		caps = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
-		type_desc = "CDMA/EVDO";
-	} else if (NM_IS_MODEM_GSM (modem)) {
-		caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
-		type_desc = "GSM/UMTS";
-	} else {
-		nm_log_warn (LOGD_MB, "unhandled modem type %s", G_OBJECT_TYPE_NAME (modem));
-		return NULL;
-	}
-
-	return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MODEM,
-	                                  NM_DEVICE_INTERFACE_UDI, nm_modem_get_path (modem),
-	                                  NM_DEVICE_INTERFACE_IFACE, nm_modem_get_iface (modem),
-	                                  NM_DEVICE_INTERFACE_DRIVER, driver,
-	                                  NM_DEVICE_INTERFACE_TYPE_DESC, type_desc,
-	                                  NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_MODEM,
-	                                  NM_DEVICE_INTERFACE_RFKILL_TYPE, RFKILL_TYPE_WWAN,
-	                                  NM_DEVICE_MODEM_MODEM, modem,
-	                                  NM_DEVICE_MODEM_CAPABILITIES, caps,
-	                                  NM_DEVICE_MODEM_CURRENT_CAPABILITIES, caps,
-	                                  NULL);
-}
-
 static void
 device_interface_init (NMDeviceInterface *iface_class)
 {
@@ -382,11 +361,11 @@ set_modem (NMDeviceModem *self, NMModem *modem)
 
 	priv->modem = g_object_ref (modem);
 
+	g_signal_connect (modem, NM_MODEM_PPP_STATS, G_CALLBACK (ppp_stats), self);
 	g_signal_connect (modem, NM_MODEM_PPP_FAILED, G_CALLBACK (ppp_failed), self);
 	g_signal_connect (modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK (modem_prepare_result), self);
 	g_signal_connect (modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK (modem_ip4_config_result), self);
-	g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self);
-	g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self);
+	g_signal_connect (modem, NM_MODEM_NEED_AUTH, G_CALLBACK (modem_need_auth), self);
 	g_signal_connect (modem, "notify::" NM_MODEM_ENABLED, G_CALLBACK (modem_enabled_cb), self);
 }
 
@@ -394,19 +373,11 @@ static void
 set_property (GObject *object, guint prop_id,
 			  const GValue *value, GParamSpec *pspec)
 {
-	NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
-
 	switch (prop_id) {
 	case PROP_MODEM:
 		/* construct-only */
 		set_modem (NM_DEVICE_MODEM (object), g_value_get_object (value));
 		break;
-	case PROP_CAPABILITIES:
-		priv->caps = g_value_get_uint (value);
-		break;
-	case PROP_CURRENT_CAPABILITIES:
-		priv->current_caps = g_value_get_uint (value);
-		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -423,12 +394,6 @@ get_property (GObject *object, guint prop_id,
 	case PROP_MODEM:
 		g_value_set_object (value, priv->modem);
 		break;
-	case PROP_CAPABILITIES:
-		g_value_set_uint (value, priv->caps);
-		break;
-	case PROP_CURRENT_CAPABILITIES:
-		g_value_set_uint (value, priv->current_caps);
-		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -461,11 +426,11 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
 
 	device_class->get_generic_capabilities = real_get_generic_capabilities;
 	device_class->get_best_auto_connection = real_get_best_auto_connection;
+	device_class->connection_secrets_updated = real_connection_secrets_updated;
 	device_class->check_connection_compatible = real_check_connection_compatible;
-	device_class->complete_connection = real_complete_connection;
 	device_class->hw_is_up = real_hw_is_up;
 	device_class->hw_bring_up = real_hw_bring_up;
-	device_class->deactivate = real_deactivate;
+	device_class->deactivate_quickly = real_deactivate_quickly;
 	device_class->act_stage1_prepare = real_act_stage1_prepare;
 	device_class->act_stage2_config = real_act_stage2_config;
 	device_class->act_stage3_ip4_config_start = real_act_stage3_ip4_config_start;
@@ -480,34 +445,27 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
 		                      NM_TYPE_MODEM,
 		                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
 
-	g_object_class_install_property (object_class, PROP_CAPABILITIES,
-		g_param_spec_uint (NM_DEVICE_MODEM_CAPABILITIES,
-		                   "Modem Capabilities",
-		                   "Modem Capabilities",
-		                   0, G_MAXUINT32, NM_DEVICE_MODEM_CAPABILITY_NONE,
-		                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
-	g_object_class_install_property (object_class, PROP_CURRENT_CAPABILITIES,
-		g_param_spec_uint (NM_DEVICE_MODEM_CURRENT_CAPABILITIES,
-		                   "Current modem Capabilities",
-		                   "Current modem Capabilities",
-		                   0, G_MAXUINT32, NM_DEVICE_MODEM_CAPABILITY_NONE,
-		                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
 	/* Signals */
-	signals[PROPERTIES_CHANGED] = 
-		nm_properties_changed_signal_new (object_class,
-		                                  G_STRUCT_OFFSET (NMDeviceModemClass, properties_changed));
+	signals[PPP_STATS] =
+		g_signal_new ("ppp-stats",
+					  G_OBJECT_CLASS_TYPE (object_class),
+					  G_SIGNAL_RUN_FIRST,
+					  G_STRUCT_OFFSET (NMDeviceModemClass, ppp_stats),
+					  NULL, NULL,
+					  _nm_marshal_VOID__UINT_UINT,
+					  G_TYPE_NONE, 2,
+					  G_TYPE_UINT, G_TYPE_UINT);
 
 	signals[ENABLE_CHANGED] =
 		g_signal_new (NM_DEVICE_MODEM_ENABLE_CHANGED,
 					  G_OBJECT_CLASS_TYPE (object_class),
 					  G_SIGNAL_RUN_FIRST,
-					  0, NULL, NULL,
+					  0,
+					  NULL, NULL,
 					  g_cclosure_marshal_VOID__VOID,
 					  G_TYPE_NONE, 0);
 
 	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (mclass),
-	                                 &dbus_glib_nm_device_modem_object_info);
+	                                 nm_modem_get_serial_dbus_info ());
 }