NetworkManager r3261 - in trunk: . include libnm-glib libnm-util src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r3261 - in trunk: . include libnm-glib libnm-util src
- Date: Mon, 21 Jan 2008 19:14:19 +0000 (GMT)
Author: dcbw
Date: Mon Jan 21 19:14:18 2008
New Revision: 3261
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3261&view=rev
Log:
2008-01-21 Dan Williams <dcbw redhat com>
* include/NetworkManager.h
- Add CDMA mobile broadband card device type
* src/nm-hal-manager.c
- (modem_device_creator): handle both CDMA and GSM modems; the device
must now be tagged with 'cdma' or 'gsm' capability
* src/nm-cdma-device.c
src/nm-cdma-device.h
src/Makefile.am
- Add the CDMA mobile broadband card device class
* libnm-util/nm-connection.c
- (register_default_settings): add NMSettingCdma
* libnm-util/nm-setting-cdma.c
libnm-util/nm-setting-cdma.h
libnm-util/Makefile.am
- Add the CDMA mobile broadband card setting class
* libnm-glib/nm-cdma-device.c
libnm-glib/nm-cdma-device.h
libnm-glib/Makefile.am
- Add the CDMA mobile broadband card GLib proxy class
* libnm-glib/nm-client.c
- (get_device): handle CDMA devices too
Added:
trunk/libnm-glib/nm-cdma-device.c
trunk/libnm-glib/nm-cdma-device.h
trunk/libnm-util/nm-setting-cdma.c
trunk/libnm-util/nm-setting-cdma.h
trunk/src/nm-cdma-device.c
trunk/src/nm-cdma-device.h
Modified:
trunk/ChangeLog
trunk/include/NetworkManager.h
trunk/libnm-glib/Makefile.am
trunk/libnm-glib/nm-client.c
trunk/libnm-util/Makefile.am
trunk/libnm-util/nm-connection.c
trunk/src/Makefile.am
trunk/src/nm-hal-manager.c
Modified: trunk/include/NetworkManager.h
==============================================================================
--- trunk/include/NetworkManager.h (original)
+++ trunk/include/NetworkManager.h Mon Jan 21 19:14:18 2008
@@ -35,6 +35,7 @@
#define NM_DBUS_PATH_ACCESS_POINT "/org/freedesktop/NetworkManager/AccessPoint"
#define NM_DBUS_INTERFACE_ACCESS_POINT "org.freedesktop.NetworkManager.AccessPoint"
#define NM_DBUS_INTERFACE_GSM_DEVICE "org.freedesktop.NetworkManager.Device.Gsm"
+#define NM_DBUS_INTERFACE_CDMA_DEVICE "org.freedesktop.NetworkManager.Device.Cdma"
#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings"
#define NM_DBUS_SERVICE_SYSTEM_SETTINGS "org.freedesktop.NetworkManagerSystemSettings"
@@ -69,7 +70,8 @@
DEVICE_TYPE_UNKNOWN = 0,
DEVICE_TYPE_802_3_ETHERNET,
DEVICE_TYPE_802_11_WIRELESS,
- DEVICE_TYPE_GSM
+ DEVICE_TYPE_GSM,
+ DEVICE_TYPE_CDMA
} NMDeviceType;
Modified: trunk/libnm-glib/Makefile.am
==============================================================================
--- trunk/libnm-glib/Makefile.am (original)
+++ trunk/libnm-glib/Makefile.am Mon Jan 21 19:14:18 2008
@@ -36,6 +36,7 @@
nm-ip4-config.h \
nm-settings.h \
nm-gsm-device.h \
+ nm-cdma-device.h \
nm-vpn-connection.h \
nm-vpn-manager.h \
nm-vpn-plugin.h
@@ -54,6 +55,7 @@
nm-ip4-config.c \
nm-settings.c \
nm-gsm-device.c \
+ nm-cdma-device.c \
nm-vpn-connection.c \
nm-vpn-manager.c \
nm-marshal-main.c
Added: trunk/libnm-glib/nm-cdma-device.c
==============================================================================
--- (empty file)
+++ trunk/libnm-glib/nm-cdma-device.c Mon Jan 21 19:14:18 2008
@@ -0,0 +1,82 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#include "nm-cdma-device.h"
+
+G_DEFINE_TYPE (NMCdmaDevice, nm_cdma_device, NM_TYPE_DEVICE)
+
+#define NM_CDMA_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CDMA_DEVICE, NMCdmaDevicePrivate))
+
+typedef struct {
+ DBusGProxy *cdma_proxy;
+
+ gboolean disposed;
+} NMCdmaDevicePrivate;
+
+static void
+nm_cdma_device_init (NMCdmaDevice *device)
+{
+}
+
+static GObject*
+constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+ NMCdmaDevicePrivate *priv;
+
+ object = G_OBJECT_CLASS (nm_cdma_device_parent_class)->constructor (type,
+ n_construct_params,
+ construct_params);
+ if (!object)
+ return NULL;
+
+ priv = NM_CDMA_DEVICE_GET_PRIVATE (object);
+
+ priv->cdma_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_CDMA_DEVICE);
+ return object;
+}
+
+static void
+dispose (GObject *object)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (object);
+
+ if (priv->disposed) {
+ G_OBJECT_CLASS (nm_cdma_device_parent_class)->dispose (object);
+ return;
+ }
+
+ priv->disposed = TRUE;
+
+ g_object_unref (priv->cdma_proxy);
+
+ G_OBJECT_CLASS (nm_cdma_device_parent_class)->dispose (object);
+}
+
+static void
+nm_cdma_device_class_init (NMCdmaDeviceClass *device_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (device_class);
+
+ g_type_class_add_private (device_class, sizeof (NMCdmaDevicePrivate));
+
+ /* virtual methods */
+ object_class->constructor = constructor;
+ object_class->dispose = dispose;
+}
+
+NMCdmaDevice *
+nm_cdma_device_new (DBusGConnection *connection, const char *path)
+{
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ return (NMCdmaDevice *) g_object_new (NM_TYPE_CDMA_DEVICE,
+ NM_OBJECT_CONNECTION, connection,
+ NM_OBJECT_PATH, path,
+ NULL);
+}
Added: trunk/libnm-glib/nm-cdma-device.h
==============================================================================
--- (empty file)
+++ trunk/libnm-glib/nm-cdma-device.h Mon Jan 21 19:14:18 2008
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#ifndef NM_CDMA_DEVICE_H
+#define NM_CDMA_DEVICE_H
+
+#include "nm-device.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_CDMA_DEVICE (nm_cdma_device_get_type ())
+#define NM_CDMA_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CDMA_DEVICE, NMCdmaDevice))
+#define NM_CDMA_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CDMA_DEVICE, NMCdmaDeviceClass))
+#define NM_IS_CDMA_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CDMA_DEVICE))
+#define NM_IS_CDMA_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_CDMA_DEVICE))
+#define NM_CDMA_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CDMA_DEVICE, NMCdmaDeviceClass))
+
+typedef struct {
+ NMDevice parent;
+} NMCdmaDevice;
+
+typedef struct {
+ NMDeviceClass parent;
+} NMCdmaDeviceClass;
+
+GType nm_cdma_device_get_type (void);
+
+NMCdmaDevice *nm_cdma_device_new (DBusGConnection *connection,
+ const char *path);
+
+G_END_DECLS
+
+#endif /* NM_CDMA_DEVICE_H */
Modified: trunk/libnm-glib/nm-client.c
==============================================================================
--- trunk/libnm-glib/nm-client.c (original)
+++ trunk/libnm-glib/nm-client.c Mon Jan 21 19:14:18 2008
@@ -6,6 +6,7 @@
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "nm-gsm-device.h"
+#include "nm-cdma-device.h"
#include "nm-device-private.h"
#include "nm-marshal.h"
#include <nm-utils.h>
@@ -392,6 +393,9 @@
case DEVICE_TYPE_GSM:
device = NM_DEVICE (nm_gsm_device_new (connection, path));
break;
+ case DEVICE_TYPE_CDMA:
+ device = NM_DEVICE (nm_cdma_device_new (connection, path));
+ break;
default:
device = nm_device_new (connection, path);
}
Modified: trunk/libnm-util/Makefile.am
==============================================================================
--- trunk/libnm-util/Makefile.am (original)
+++ trunk/libnm-util/Makefile.am Mon Jan 21 19:14:18 2008
@@ -20,6 +20,7 @@
nm-setting-ppp.h \
nm-setting-serial.h \
nm-setting-gsm.h \
+ nm-setting-cdma.h \
nm-setting-wired.h \
nm-setting-wireless.h \
nm-setting-wireless-security.h \
@@ -36,6 +37,7 @@
nm-setting-ppp.c \
nm-setting-serial.c \
nm-setting-gsm.c \
+ nm-setting-cdma.c \
nm-setting-wired.c \
nm-setting-wireless.c \
nm-setting-wireless-security.c \
Modified: trunk/libnm-util/nm-connection.c
==============================================================================
--- trunk/libnm-util/nm-connection.c (original)
+++ trunk/libnm-util/nm-connection.c Mon Jan 21 19:14:18 2008
@@ -17,6 +17,7 @@
#include "nm-setting-serial.h"
#include "nm-setting-gsm.h"
+#include "nm-setting-cdma.h"
typedef struct {
GHashTable *settings;
@@ -51,6 +52,7 @@
{ NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_TYPE_SETTING_WIRELESS_SECURITY },
{ NM_SETTING_SERIAL_SETTING_NAME, NM_TYPE_SETTING_SERIAL },
{ NM_SETTING_GSM_SETTING_NAME, NM_TYPE_SETTING_GSM },
+ { NM_SETTING_CDMA_SETTING_NAME, NM_TYPE_SETTING_CDMA },
{ NM_SETTING_PPP_SETTING_NAME, NM_TYPE_SETTING_PPP },
{ NM_SETTING_VPN_SETTING_NAME, NM_TYPE_SETTING_VPN },
{ NM_SETTING_VPN_PROPERTIES_SETTING_NAME, NM_TYPE_SETTING_VPN_PROPERTIES },
Added: trunk/libnm-util/nm-setting-cdma.c
==============================================================================
--- (empty file)
+++ trunk/libnm-util/nm-setting-cdma.c Mon Jan 21 19:14:18 2008
@@ -0,0 +1,155 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#include <string.h>
+#include "nm-setting-cdma.h"
+#include "nm-setting-serial.h"
+#include "nm-utils.h"
+
+G_DEFINE_TYPE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING)
+
+enum {
+ PROP_0,
+ PROP_NUMBER,
+ PROP_USERNAME,
+ PROP_PASSWORD,
+
+ LAST_PROP
+};
+
+NMSetting *
+nm_setting_cdma_new (void)
+{
+ return (NMSetting *) g_object_new (NM_TYPE_SETTING_CDMA, NULL);
+}
+
+static gint
+find_setting_by_name (gconstpointer a, gconstpointer b)
+{
+ NMSetting *setting = NM_SETTING (a);
+ const char *str = (const char *) b;
+
+ return strcmp (nm_setting_get_name (setting), str);
+}
+
+static gboolean
+verify (NMSetting *setting, GSList *all_settings)
+{
+ NMSettingCdma *self = NM_SETTING_CDMA (setting);
+
+ /* Serial connections require a PPP setting */
+ if (all_settings &&
+ !g_slist_find_custom (all_settings, NM_SETTING_SERIAL_SETTING_NAME, find_setting_by_name)) {
+ g_warning ("Missing serial setting");
+ return FALSE;
+ }
+
+ if (!self->number || strlen (self->number) < 1) {
+ nm_warning ("Missing phone number");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+nm_setting_cdma_init (NMSettingCdma *setting)
+{
+ ((NMSetting *) setting)->name = g_strdup (NM_SETTING_CDMA_SETTING_NAME);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMSettingCdma *self = NM_SETTING_CDMA (object);
+
+ g_free (self->number);
+ g_free (self->username);
+ g_free (self->password);
+
+ G_OBJECT_CLASS (nm_setting_cdma_parent_class)->finalize (object);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ NMSettingCdma *setting = NM_SETTING_CDMA (object);
+
+ switch (prop_id) {
+ case PROP_NUMBER:
+ g_free (setting->number);
+ setting->number = g_value_dup_string (value);
+ break;
+ case PROP_USERNAME:
+ g_free (setting->username);
+ setting->username = g_value_dup_string (value);
+ break;
+ case PROP_PASSWORD:
+ g_free (setting->password);
+ setting->password = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ NMSettingCdma *setting = NM_SETTING_CDMA (object);
+
+ switch (prop_id) {
+ case PROP_NUMBER:
+ g_value_set_string (value, setting->number);
+ break;
+ case PROP_USERNAME:
+ g_value_set_string (value, setting->username);
+ break;
+ case PROP_PASSWORD:
+ g_value_set_string (value, setting->password);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_setting_cdma_class_init (NMSettingCdmaClass *setting_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
+ NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
+
+ /* virtual methods */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+ parent_class->verify = verify;
+
+ /* Properties */
+ g_object_class_install_property
+ (object_class, PROP_NUMBER,
+ g_param_spec_string (NM_SETTING_CDMA_NUMBER,
+ "Number",
+ "Number",
+ NULL,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_USERNAME,
+ g_param_spec_string (NM_SETTING_CDMA_USERNAME,
+ "Username",
+ "Username",
+ NULL,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PASSWORD,
+ g_param_spec_string (NM_SETTING_CDMA_PASSWORD,
+ "Password",
+ "Password",
+ NULL,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
+}
Added: trunk/libnm-util/nm-setting-cdma.h
==============================================================================
--- (empty file)
+++ trunk/libnm-util/nm-setting-cdma.h Mon Jan 21 19:14:18 2008
@@ -0,0 +1,41 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#ifndef NM_SETTING_CDMA_H
+#define NM_SETTING_CDMA_H
+
+#include <nm-setting.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_SETTING_CDMA (nm_setting_cdma_get_type ())
+#define NM_SETTING_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_CDMA, NMSettingCdma))
+#define NM_SETTING_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_CDMA, NMSettingCdmaClass))
+#define NM_IS_SETTING_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_CDMA))
+#define NM_IS_SETTING_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTING_CDMA))
+#define NM_SETTING_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_CDMA, NMSettingCdmaClass))
+
+#define NM_SETTING_CDMA_SETTING_NAME "cdma"
+
+#define NM_SETTING_CDMA_NUMBER "number"
+#define NM_SETTING_CDMA_USERNAME "username"
+#define NM_SETTING_CDMA_PASSWORD "password"
+
+typedef struct {
+ NMSetting parent;
+
+ char *number; /* For dialing, duh */
+ char *username;
+ char *password;
+} NMSettingCdma;
+
+typedef struct {
+ NMSettingClass parent;
+} NMSettingCdmaClass;
+
+GType nm_setting_cdma_get_type (void);
+
+NMSetting *nm_setting_cdma_new (void);
+
+G_END_DECLS
+
+#endif /* NM_SETTING_CDMA_H */
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Mon Jan 21 19:14:18 2008
@@ -60,6 +60,8 @@
nm-serial-device.h \
nm-gsm-device.c \
nm-gsm-device.h \
+ nm-cdma-device.c \
+ nm-cdma-device.h \
autoip.c \
autoip.h \
kernel-types.h \
Added: trunk/src/nm-cdma-device.c
==============================================================================
--- (empty file)
+++ trunk/src/nm-cdma-device.c Mon Jan 21 19:14:18 2008
@@ -0,0 +1,402 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#include <stdio.h>
+#include <string.h>
+#include "nm-cdma-device.h"
+#include "nm-device-interface.h"
+#include "nm-device-private.h"
+#include "nm-setting-cdma.h"
+#include "nm-utils.h"
+
+G_DEFINE_TYPE (NMCdmaDevice, nm_cdma_device, NM_TYPE_SERIAL_DEVICE)
+
+enum {
+ PROP_0,
+ PROP_MONITOR_IFACE,
+
+ LAST_PROP
+};
+
+#define NM_CDMA_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CDMA_DEVICE, NMCdmaDevicePrivate))
+
+typedef struct {
+ char *monitor_iface;
+ NMSerialDevice *monitor_device;
+
+ guint pending_id;
+} NMCdmaDevicePrivate;
+
+NMCdmaDevice *
+nm_cdma_device_new (const char *udi,
+ const char *data_iface,
+ const char *monitor_iface,
+ const char *driver)
+{
+ g_return_val_if_fail (udi != NULL, NULL);
+ g_return_val_if_fail (data_iface != NULL, NULL);
+ g_return_val_if_fail (driver != NULL, NULL);
+
+ return (NMCdmaDevice *) g_object_new (NM_TYPE_CDMA_DEVICE,
+ NM_DEVICE_INTERFACE_UDI, udi,
+ NM_DEVICE_INTERFACE_IFACE, data_iface,
+ NM_DEVICE_INTERFACE_DRIVER, driver,
+ NM_CDMA_DEVICE_MONITOR_IFACE, monitor_iface,
+ NULL);
+}
+
+static inline void
+cdma_device_set_pending (NMCdmaDevice *device, guint pending_id)
+{
+ NM_CDMA_DEVICE_GET_PRIVATE (device)->pending_id = pending_id;
+}
+
+static NMSetting *
+cdma_device_get_setting (NMCdmaDevice *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
+dial_done (NMSerialDevice *device,
+ int reply_index,
+ gpointer user_data)
+{
+ gboolean success = FALSE;
+
+ cdma_device_set_pending (NM_CDMA_DEVICE (device), 0);
+
+ switch (reply_index) {
+ case 0:
+ nm_info ("Connected, Woo!");
+ success = TRUE;
+ break;
+ case 1:
+ nm_info ("Busy");
+ break;
+ case 2:
+ nm_warning ("No dial tone");
+ break;
+ case 3:
+ nm_warning ("No carrier");
+ break;
+ case -1:
+ nm_warning ("Dialing timed out");
+ break;
+ default:
+ nm_warning ("Dialing failed");
+ break;
+ }
+
+ if (success)
+ nm_device_activate_schedule_stage2_device_config (NM_DEVICE (device));
+ else
+ nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED);
+}
+
+static void
+do_dial (NMSerialDevice *device)
+{
+ NMSettingCdma *setting;
+ char *command;
+ guint id;
+ char *responses[] = { "CONNECT", "BUSY", "NO DIAL TONE", "NO CARRIER", NULL };
+
+ setting = NM_SETTING_CDMA (cdma_device_get_setting (NM_CDMA_DEVICE (device), NM_TYPE_SETTING_CDMA));
+
+ command = g_strconcat ("ATDT", setting->number, NULL);
+ nm_serial_device_send_command_string (device, command);
+ g_free (command);
+
+ id = nm_serial_device_wait_for_reply (device, 60, responses, dial_done, NULL);
+ if (id)
+ cdma_device_set_pending (NM_CDMA_DEVICE (device), id);
+ else
+ nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED);
+}
+
+static void
+init_done (NMSerialDevice *device,
+ int reply_index,
+ gpointer user_data)
+{
+ cdma_device_set_pending (NM_CDMA_DEVICE (device), 0);
+
+ switch (reply_index) {
+ case 0:
+ do_dial (device);
+ break;
+ case -1:
+ nm_warning ("Modem initialization timed out");
+ nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED);
+ break;
+ default:
+ nm_warning ("Modem initialization failed");
+ nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED);
+ return;
+ }
+}
+
+static void
+init_modem (NMSerialDevice *device, gpointer user_data)
+{
+ guint id;
+ char *responses[] = { "OK", "ERR", NULL };
+
+ nm_serial_device_send_command_string (device, "ATZ E0");
+ id = nm_serial_device_wait_for_reply (device, 10, responses, init_done, NULL);
+
+ if (id)
+ cdma_device_set_pending (NM_CDMA_DEVICE (device), id);
+ else
+ nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED);
+}
+
+static NMActStageReturn
+real_act_stage1_prepare (NMDevice *device)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (device);
+ NMSerialDevice *serial_device = NM_SERIAL_DEVICE (device);
+ NMSettingSerial *setting;
+
+ setting = NM_SETTING_SERIAL (cdma_device_get_setting (NM_CDMA_DEVICE (device), NM_TYPE_SETTING_SERIAL));
+
+ if (!nm_serial_device_open (serial_device, setting))
+ return NM_ACT_STAGE_RETURN_FAILURE;
+
+ priv->pending_id = nm_serial_device_flash (serial_device, 100, init_modem, NULL);
+
+ return priv->pending_id ? NM_ACT_STAGE_RETURN_POSTPONE : NM_ACT_STAGE_RETURN_FAILURE;
+}
+
+static guint32
+real_get_generic_capabilities (NMDevice *dev)
+{
+ return NM_DEVICE_CAP_NM_SUPPORTED;
+}
+
+static void
+real_connection_secrets_updated (NMDevice *dev,
+ NMConnection *connection,
+ const char *setting_name)
+{
+ NMActRequest *req;
+
+ if (nm_device_get_state (dev) != NM_DEVICE_STATE_NEED_AUTH)
+ return;
+
+ if (strcmp (setting_name, NM_SETTING_CDMA_SETTING_NAME) != 0) {
+ nm_warning ("Ignoring updated secrets for setting '%s'.", setting_name);
+ 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)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (device);
+
+ if (priv->pending_id) {
+ g_source_remove (priv->pending_id);
+ priv->pending_id = 0;
+ }
+
+ NM_DEVICE_CLASS (nm_cdma_device_parent_class)->deactivate_quickly (device);
+}
+
+/*****************************************************************************/
+/* Monitor device handling */
+
+static gboolean
+monitor_device_got_data (GIOChannel *source,
+ GIOCondition condition,
+ gpointer data)
+{
+ gsize bytes_read;
+ char buf[4096];
+ GIOStatus status;
+
+ if (condition & G_IO_IN) {
+ do {
+ status = g_io_channel_read_chars (source, buf, 4096, &bytes_read, NULL);
+
+ if (bytes_read) {
+ buf[bytes_read] = '\0';
+ /* Do nothing with the data for now */
+ nm_debug ("Monitor got unhandled data: '%s'", buf);
+ }
+ } while (bytes_read == 4096 || status == G_IO_STATUS_AGAIN);
+ }
+
+ if (condition & G_IO_HUP || condition & G_IO_ERR) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+setup_monitor_device (NMCdmaDevice *device)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (device);
+ GIOChannel *channel;
+ NMSettingSerial *setting;
+
+ if (!priv->monitor_iface) {
+ nm_debug ("No monitoring udi provided");
+ return FALSE;
+ }
+
+ priv->monitor_device = g_object_new (NM_TYPE_SERIAL_DEVICE,
+ NM_DEVICE_INTERFACE_UDI, nm_device_get_udi (NM_DEVICE (device)),
+ NM_DEVICE_INTERFACE_IFACE, priv->monitor_iface,
+ NULL);
+
+ if (!priv->monitor_device) {
+ nm_warning ("Creation of the monitoring device failed");
+ return FALSE;
+ }
+
+ setting = NM_SETTING_SERIAL (nm_setting_serial_new ());
+ if (!nm_serial_device_open (priv->monitor_device, setting)) {
+ nm_warning ("Monitoring device open failed");
+ g_object_unref (setting);
+ g_object_unref (priv->monitor_device);
+ return FALSE;
+ }
+
+ g_object_unref (setting);
+
+ channel = nm_serial_device_get_io_channel (priv->monitor_device);
+ g_io_add_watch (channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
+ monitor_device_got_data, device);
+
+ g_io_channel_unref (channel);
+
+ return TRUE;
+}
+
+/*****************************************************************************/
+
+static void
+nm_cdma_device_init (NMCdmaDevice *self)
+{
+ nm_device_set_device_type (NM_DEVICE (self), DEVICE_TYPE_CDMA);
+}
+
+static GObject*
+constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+
+ object = G_OBJECT_CLASS (nm_cdma_device_parent_class)->constructor (type,
+ n_construct_params,
+ construct_params);
+ if (!object)
+ return NULL;
+
+ /* FIXME: Make the monitor device not required for now */
+ setup_monitor_device (NM_CDMA_DEVICE (object));
+#if 0
+ if (!setup_monitor_device (NM_CDMA_DEVICE (object))) {
+ g_object_unref (object);
+ object = NULL;
+ }
+#endif
+
+ return object;
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (object);
+
+ switch (prop_id) {
+ case PROP_MONITOR_IFACE:
+ /* Construct only */
+ priv->monitor_iface = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (object);
+
+ switch (prop_id) {
+ case PROP_MONITOR_IFACE:
+ g_value_set_string (value, priv->monitor_iface);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+finalize (GObject *object)
+{
+ NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_GET_PRIVATE (object);
+
+ if (priv->monitor_device)
+ g_object_unref (priv->monitor_device);
+
+ g_free (priv->monitor_iface);
+
+ G_OBJECT_CLASS (nm_cdma_device_parent_class)->finalize (object);
+}
+
+static void
+nm_cdma_device_class_init (NMCdmaDeviceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (NMCdmaDevicePrivate));
+
+ object_class->constructor = constructor;
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+ object_class->finalize = finalize;
+
+ device_class->get_generic_capabilities = real_get_generic_capabilities;
+ device_class->act_stage1_prepare = real_act_stage1_prepare;
+ device_class->connection_secrets_updated = real_connection_secrets_updated;
+ device_class->deactivate_quickly = real_deactivate_quickly;
+
+ /* Properties */
+ g_object_class_install_property
+ (object_class, PROP_MONITOR_IFACE,
+ g_param_spec_string (NM_CDMA_DEVICE_MONITOR_IFACE,
+ "Monitoring interface",
+ "Monitoring interface",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
Added: trunk/src/nm-cdma-device.h
==============================================================================
--- (empty file)
+++ trunk/src/nm-cdma-device.h Mon Jan 21 19:14:18 2008
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#ifndef NM_CDMA_DEVICE_H
+#define NM_CDMA_DEVICE_H
+
+#include <nm-serial-device.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_CDMA_DEVICE (nm_cdma_device_get_type ())
+#define NM_CDMA_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CDMA_DEVICE, NMCdmaDevice))
+#define NM_CDMA_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CDMA_DEVICE, NMCdmaDeviceClass))
+#define NM_IS_CDMA_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CDMA_DEVICE))
+#define NM_IS_CDMA_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CDMA_DEVICE))
+#define NM_CDMA_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CDMA_DEVICE, NMCdmaDeviceClass))
+
+#define NM_CDMA_DEVICE_MONITOR_IFACE "monitor-iface"
+
+typedef struct {
+ NMSerialDevice parent;
+} NMCdmaDevice;
+
+typedef struct {
+ NMSerialDeviceClass parent;
+} NMCdmaDeviceClass;
+
+GType nm_cdma_device_get_type (void);
+
+NMCdmaDevice *nm_cdma_device_new (const char *udi,
+ const char *data_iface,
+ const char *monitor_iface,
+ const char *driver);
+
+G_END_DECLS
+
+#endif /* NM_CDMA_DEVICE_H */
Modified: trunk/src/nm-hal-manager.c
==============================================================================
--- trunk/src/nm-hal-manager.c (original)
+++ trunk/src/nm-hal-manager.c Mon Jan 21 19:14:18 2008
@@ -13,6 +13,7 @@
#include "nm-device-802-11-wireless.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-gsm-device.h"
+#include "nm-cdma-device.h"
/* Killswitch poll frequency in seconds */
#define NM_HAL_MANAGER_KILLSWITCH_POLL_FREQUENCY 6
@@ -194,6 +195,9 @@
char *parent_udi;
char *driver_name = NULL;
NMDevice *device = NULL;
+ char **capabilities, **iter;
+ gboolean type_gsm = FALSE;
+ gboolean type_cdma = FALSE;
serial_device = libhal_device_get_property_string (manager->hal_ctx, udi, "serial.device", NULL);
@@ -204,9 +208,28 @@
libhal_free_string (parent_udi);
}
- if (serial_device && driver_name)
+ if (!serial_device || !driver_name)
+ goto out;
+
+ capabilities = libhal_device_get_property_strlist (manager->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 = (NMDevice *) nm_gsm_device_new (udi, serial_device + strlen ("/dev/"), NULL, driver_name);
+ else if (type_cdma)
+ device = (NMDevice *) nm_cdma_device_new (udi, serial_device + strlen ("/dev/"), NULL, driver_name);
+out:
libhal_free_string (serial_device);
libhal_free_string (driver_name);
@@ -234,9 +257,9 @@
creator->creator_fn = wireless_device_creator;
manager->device_creators = g_slist_append (manager->device_creators, creator);
- /* GSM Modem */
+ /* Modem */
creator = g_slice_new0 (DeviceCreator);
- creator->device_type_name = g_strdup ("GSM modem");
+ 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]