Remove HSO and MBM modem implementations and replace them with generic code.

This commit is contained in:
Tambet Ingo
2009-02-06 09:41:12 +02:00
parent 10784dd1b6
commit eaa93b0387
12 changed files with 316 additions and 668 deletions

View File

@@ -40,7 +40,7 @@
#include "NetworkManagerSystem.h"
#include "nm-named-manager.h"
#include "nm-vpn-manager.h"
#include "nm-modem-gsm-hso.h"
#include "nm-modem.h"
typedef struct LookupThread LookupThread;
@@ -232,8 +232,7 @@ get_best_device (NMManager *manager, NMActRequest **out_req)
}
}
/* 'hso' devices never get a gateway from the remote end */
if (!can_default && !NM_IS_MODEM_GSM_HSO (dev))
if (!can_default && !NM_IS_MODEM (dev))
continue;
/* 'never-default' devices can't ever be the default */

View File

@@ -11,10 +11,6 @@ libmodem_manager_la_SOURCES = \
nm-modem-cdma.h \
nm-modem-gsm.c \
nm-modem-gsm.h \
nm-modem-gsm-hso.c \
nm-modem-gsm-hso.h \
nm-modem-gsm-mbm.c \
nm-modem-gsm-mbm.h \
nm-modem.c \
nm-modem.h \
nm-modem-manager.h \

View File

@@ -1,283 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#include "nm-modem-gsm-hso.h"
#include "nm-device-private.h"
#include "nm-device-interface.h"
#include "NetworkManagerSystem.h"
#include "nm-setting-connection.h"
#include "nm-setting-gsm.h"
#include "nm-modem-types.h"
#include "nm-utils.h"
G_DEFINE_TYPE (NMModemGsmHso, nm_modem_gsm_hso, NM_TYPE_MODEM_GSM)
#define NM_MODEM_GSM_HSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MODEM_GSM_HSO, NMModemGsmHsoPrivate))
typedef struct {
char *netdev_iface;
NMIP4Config *pending_ip4_config;
} NMModemGsmHsoPrivate;
#define HSO_SECRETS_TRIES "gsm-secrets-tries"
static char *
get_network_device (NMDevice *device)
{
char *result = NULL;
GError *error = NULL;
GValue value = { 0, };
if (!dbus_g_proxy_call (nm_modem_get_proxy (NM_MODEM (device), "org.freedesktop.DBus.Properties"),
"Get", &error,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM_GSM_HSO,
G_TYPE_STRING, "NetworkDevice",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
nm_warning ("Could not get HSO device's network interface: %s", error->message);
g_error_free (error);
} else {
if (G_VALUE_HOLDS_STRING (&value))
result = g_value_dup_string (&value);
else
nm_warning ("Could not get HSO device's network interface: wrong type '%s'",
G_VALUE_TYPE_NAME (&value));
g_value_unset (&value);
}
return result;
}
NMDevice *
nm_modem_gsm_hso_new (const char *path,
const char *data_device,
const char *driver)
{
NMDevice *device;
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);
device = (NMDevice *) g_object_new (NM_TYPE_MODEM_GSM_HSO,
NM_DEVICE_INTERFACE_UDI, path,
NM_DEVICE_INTERFACE_IFACE, data_device,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_INTERFACE_MANAGED, TRUE,
NM_MODEM_PATH, path,
NULL);
if (device) {
NMModemGsmHsoPrivate *priv;
priv = NM_MODEM_GSM_HSO_GET_PRIVATE (device);
priv->netdev_iface = get_network_device (device);
if (!priv->netdev_iface) {
g_object_unref (device);
device = NULL;
}
}
return device;
}
/*****************************************************************************/
static NMActStageReturn
real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
{
NMActRequest *req;
NMConnection *connection;
const char *setting_name;
GPtrArray *hints = NULL;
const char *hint1 = NULL, *hint2 = NULL;
guint32 tries;
req = nm_device_get_act_request (device);
g_assert (req);
connection = nm_act_request_get_connection (req);
g_assert (connection);
setting_name = nm_connection_need_secrets (connection, &hints);
if (!setting_name)
return NM_DEVICE_CLASS (nm_modem_gsm_hso_parent_class)->act_stage1_prepare (device, reason);
if (hints) {
if (hints->len > 0)
hint1 = g_ptr_array_index (hints, 0);
if (hints->len > 1)
hint2 = g_ptr_array_index (hints, 1);
}
nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), HSO_SECRETS_TRIES));
nm_act_request_request_connection_secrets (req,
setting_name,
tries ? TRUE : FALSE,
SECRETS_CALLER_HSO_GSM,
hint1,
hint2);
g_object_set_data (G_OBJECT (connection), HSO_SECRETS_TRIES, GUINT_TO_POINTER (++tries));
if (hints)
g_ptr_array_free (hints, TRUE);
return NM_ACT_STAGE_RETURN_POSTPONE;
}
static void
get_ip4_config_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
{
NMDevice *device = NM_DEVICE (user_data);
guint32 ip4_address;
GArray *dns_array;
GError *error = NULL;
if (dbus_g_proxy_end_call (proxy, call_id, &error,
G_TYPE_UINT, &ip4_address,
DBUS_TYPE_G_UINT_ARRAY, &dns_array,
G_TYPE_INVALID)) {
NMModemGsmHsoPrivate *priv = NM_MODEM_GSM_HSO_GET_PRIVATE (device);
NMIP4Address *addr;
int i;
addr = nm_ip4_address_new ();
nm_ip4_address_set_address (addr, ip4_address);
nm_ip4_address_set_prefix (addr, 32);
priv->pending_ip4_config = nm_ip4_config_new ();
nm_ip4_config_take_address (priv->pending_ip4_config, addr);
for (i = 0; i < dns_array->len; i++)
nm_ip4_config_add_nameserver (priv->pending_ip4_config,
g_array_index (dns_array, guint32, i));
nm_device_activate_schedule_stage4_ip_config_get (device);
} else {
nm_warning ("Retrieving IP4 configuration failed: %s", error->message);
g_error_free (error);
nm_device_state_changed (device,
NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
}
}
static NMActStageReturn
real_act_stage3_ip_config_start (NMDevice *device, NMDeviceStateReason *reason)
{
dbus_g_proxy_begin_call (nm_modem_get_proxy (NM_MODEM (device), MM_DBUS_INTERFACE_MODEM_GSM_HSO),
"GetIP4Config", get_ip4_config_done,
device, NULL,
G_TYPE_INVALID);
return NM_ACT_STAGE_RETURN_POSTPONE;
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
NMModemGsmHso *self = NM_MODEM_GSM_HSO (device);
NMModemGsmHsoPrivate *priv = NM_MODEM_GSM_HSO_GET_PRIVATE (self);
gboolean no_firmware = FALSE;
nm_device_set_ip_iface (device, priv->netdev_iface);
if (!nm_device_hw_bring_up (device, TRUE, &no_firmware)) {
if (no_firmware)
*reason = NM_DEVICE_STATE_REASON_FIRMWARE_MISSING;
else
*reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
return NM_ACT_STAGE_RETURN_FAILURE;
}
*config = priv->pending_ip4_config;
priv->pending_ip4_config = NULL;
return NM_ACT_STAGE_RETURN_SUCCESS;
}
static void
real_deactivate (NMDevice *device)
{
NMModemGsmHsoPrivate *priv = NM_MODEM_GSM_HSO_GET_PRIVATE (device);
if (priv->pending_ip4_config) {
g_object_unref (priv->pending_ip4_config);
priv->pending_ip4_config = NULL;
}
if (priv->netdev_iface) {
nm_system_device_flush_ip4_routes_with_iface (priv->netdev_iface);
nm_system_device_flush_ip4_addresses_with_iface (priv->netdev_iface);
nm_system_device_set_up_down_with_iface (priv->netdev_iface, FALSE, NULL);
}
nm_device_set_ip_iface (device, NULL);
if (NM_DEVICE_CLASS (nm_modem_gsm_hso_parent_class)->deactivate)
NM_DEVICE_CLASS (nm_modem_gsm_hso_parent_class)->deactivate (device);
}
static gboolean
real_hw_is_up (NMDevice *device)
{
NMModemGsmHsoPrivate *priv = NM_MODEM_GSM_HSO_GET_PRIVATE (device);
NMDeviceState state;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
if (priv->pending_ip4_config || state == NM_DEVICE_STATE_IP_CONFIG || state == NM_DEVICE_STATE_ACTIVATED)
return nm_system_device_is_up_with_iface (priv->netdev_iface);
return TRUE;
}
static gboolean
real_hw_bring_up (NMDevice *device, gboolean *no_firmware)
{
NMModemGsmHsoPrivate *priv = NM_MODEM_GSM_HSO_GET_PRIVATE (device);
NMDeviceState state;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
if (priv->pending_ip4_config || state == NM_DEVICE_STATE_IP_CONFIG || state == NM_DEVICE_STATE_ACTIVATED)
return nm_system_device_set_up_down_with_iface (priv->netdev_iface, TRUE, no_firmware);
return TRUE;
}
/*****************************************************************************/
static void
nm_modem_gsm_hso_init (NMModemGsmHso *self)
{
}
static void
finalize (GObject *object)
{
NMModemGsmHsoPrivate *priv = NM_MODEM_GSM_HSO_GET_PRIVATE (object);
g_free (priv->netdev_iface);
G_OBJECT_CLASS (nm_modem_gsm_hso_parent_class)->finalize (object);
}
static void
nm_modem_gsm_hso_class_init (NMModemGsmHsoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMModemGsmHsoPrivate));
object_class->finalize = finalize;
device_class->act_stage1_prepare = real_act_stage1_prepare;
device_class->act_stage3_ip_config_start = real_act_stage3_ip_config_start;
device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
device_class->deactivate = real_deactivate;
device_class->hw_is_up = real_hw_is_up;
device_class->hw_bring_up = real_hw_bring_up;
}

View File

@@ -1,33 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#ifndef NM_MODEM_GSM_HSO_H
#define NM_MODEM_GSM_HSO_H
#include <nm-modem-gsm.h>
G_BEGIN_DECLS
#define NM_TYPE_MODEM_GSM_HSO (nm_modem_gsm_hso_get_type ())
#define NM_MODEM_GSM_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_GSM_HSO, NMModemGsmHso))
#define NM_MODEM_GSM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MODEM_GSM_HSO, NMModemGsmHsoClass))
#define NM_IS_MODEM_GSM_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_GSM_HSO))
#define NM_IS_MODEM_GSM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_GSM_HSO))
#define NM_MODEM_GSM_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_GSM_HSO, NMModemGsmHsoClass))
typedef struct {
NMModemGsm parent;
} NMModemGsmHso;
typedef struct {
NMModemGsmClass parent;
} NMModemGsmHsoClass;
GType nm_modem_gsm_hso_get_type (void);
NMDevice *nm_modem_gsm_hso_new (const char *path,
const char *data_device,
const char *driver);
G_END_DECLS
#endif /* NM_MODEM_GSM_HSO_H */

View File

@@ -1,252 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
Additions to NetworkManager, network-manager-applet and modemmanager
for supporting Ericsson modules like F3507g.
Author: Per Hallsmark <per@hallsmark.se>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "nm-modem-gsm-mbm.h"
#include "nm-device-private.h"
#include "nm-device-interface.h"
#include "NetworkManagerSystem.h"
#include "nm-setting-connection.h"
#include "nm-setting-gsm.h"
#include "nm-modem-types.h"
#include "nm-utils.h"
G_DEFINE_TYPE (NMModemGsmMbm, nm_modem_gsm_mbm, NM_TYPE_MODEM_GSM)
#define NM_MODEM_GSM_MBM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MODEM_GSM_MBM, NMModemGsmMbmPrivate))
typedef struct {
char *netdev_iface;
NMIP4Config *pending_ip4_config;
} NMModemGsmMbmPrivate;
#define MBM_SECRETS_TRIES "gsm-secrets-tries"
static char *
get_network_device (NMDevice *device)
{
char *result = NULL;
GError *error = NULL;
GValue value = { 0, };
if (!dbus_g_proxy_call (nm_modem_get_proxy (NM_MODEM (device), "org.freedesktop.DBus.Properties"),
"Get", &error,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM_GSM_MBM,
G_TYPE_STRING, "NetworkDevice",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
nm_warning ("Could not get MBM device's network interface: %s", error->message);
g_error_free (error);
} else {
if (G_VALUE_HOLDS_STRING (&value))
result = g_value_dup_string (&value);
else
nm_warning ("Could not get MBM device's network interface: wrong type '%s'",
G_VALUE_TYPE_NAME (&value));
g_value_unset (&value);
}
return result;
}
NMDevice *
nm_modem_gsm_mbm_new (const char *path,
const char *data_device,
const char *driver)
{
NMDevice *device;
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);
device = (NMDevice *) g_object_new (NM_TYPE_MODEM_GSM_MBM,
NM_DEVICE_INTERFACE_UDI, path,
NM_DEVICE_INTERFACE_IFACE, data_device,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_INTERFACE_MANAGED, TRUE,
NM_MODEM_PATH, path,
NULL);
if (device) {
NMModemGsmMbmPrivate *priv;
priv = NM_MODEM_GSM_MBM_GET_PRIVATE (device);
priv->netdev_iface = get_network_device (device);
if (!priv->netdev_iface) {
g_object_unref (device);
device = NULL;
}
}
return device;
}
/*****************************************************************************/
#if 0
static NMSetting *
get_setting (NMModemGsmMbm *modem, GType setting_type)
{
NMActRequest *req;
NMSetting *setting = NULL;
req = nm_device_get_act_request (NM_DEVICE (modem));
if (req) {
NMConnection *connection;
connection = nm_act_request_get_connection (req);
if (connection)
setting = nm_connection_get_setting (connection, setting_type);
}
return setting;
}
#endif
#if 0
static NMActStageReturn
real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
{
NMActRequest *req;
NMConnection *connection;
const char *setting_name;
GPtrArray *hints = NULL;
const char *hint1 = NULL, *hint2 = NULL;
guint32 tries;
req = nm_device_get_act_request (device);
g_assert (req);
connection = nm_act_request_get_connection (req);
g_assert (connection);
setting_name = nm_connection_need_secrets (connection, &hints);
if (!setting_name) {
// do_mbm_auth (NM_MODEM_GSM_MBM (device));
return NM_ACT_STAGE_RETURN_POSTPONE;
}
if (hints) {
if (hints->len > 0)
hint1 = g_ptr_array_index (hints, 0);
if (hints->len > 1)
hint2 = g_ptr_array_index (hints, 1);
}
nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), MBM_SECRETS_TRIES));
nm_act_request_request_connection_secrets (req,
setting_name,
tries ? TRUE : FALSE,
SECRETS_CALLER_MBM_GSM,
hint1,
hint2);
g_object_set_data (G_OBJECT (connection), MBM_SECRETS_TRIES, GUINT_TO_POINTER (++tries));
if (hints)
g_ptr_array_free (hints, TRUE);
return NM_ACT_STAGE_RETURN_POSTPONE;
}
#endif
static void
real_deactivate (NMDevice *device)
{
NMModemGsmMbmPrivate *priv = NM_MODEM_GSM_MBM_GET_PRIVATE (device);
if (priv->pending_ip4_config) {
g_object_unref (priv->pending_ip4_config);
priv->pending_ip4_config = NULL;
}
if (priv->netdev_iface) {
nm_system_device_flush_ip4_routes_with_iface (priv->netdev_iface);
nm_system_device_flush_ip4_addresses_with_iface (priv->netdev_iface);
nm_system_device_set_up_down_with_iface (priv->netdev_iface, FALSE, NULL);
}
nm_device_set_ip_iface (device, NULL);
if (NM_DEVICE_CLASS (nm_modem_gsm_mbm_parent_class)->deactivate)
NM_DEVICE_CLASS (nm_modem_gsm_mbm_parent_class)->deactivate (device);
}
static gboolean
real_hw_is_up (NMDevice *device)
{
NMModemGsmMbmPrivate *priv = NM_MODEM_GSM_MBM_GET_PRIVATE (device);
if (priv->netdev_iface)
return nm_system_device_is_up_with_iface (priv->netdev_iface);
return TRUE;
}
static gboolean
real_hw_bring_up (NMDevice *device, gboolean *no_firmware)
{
NMModemGsmMbmPrivate *priv = NM_MODEM_GSM_MBM_GET_PRIVATE (device);
if (priv->netdev_iface)
return nm_system_device_set_up_down_with_iface (priv->netdev_iface, TRUE, no_firmware);
return TRUE;
}
/*****************************************************************************/
static void
nm_modem_gsm_mbm_init (NMModemGsmMbm *self)
{
}
static void
finalize (GObject *object)
{
NMModemGsmMbmPrivate *priv = NM_MODEM_GSM_MBM_GET_PRIVATE (object);
g_free (priv->netdev_iface);
G_OBJECT_CLASS (nm_modem_gsm_mbm_parent_class)->finalize (object);
}
static void
nm_modem_gsm_mbm_class_init (NMModemGsmMbmClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMModemGsmMbmPrivate));
object_class->finalize = finalize;
#if 0
device_class->act_stage2_config = real_act_stage2_config;
#endif
device_class->deactivate = real_deactivate;
device_class->hw_is_up = real_hw_is_up;
device_class->hw_bring_up = real_hw_bring_up;
}

View File

@@ -1,55 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
Additions to NetworkManager, network-manager-applet and modemmanager
for supporting Ericsson modules like F3507g.
Author: Per Hallsmark <per@hallsmark.se>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef NM_MODEM_GSM_MBM_H
#define NM_MODEM_GSM_MBM_H
#include <nm-modem-gsm.h>
G_BEGIN_DECLS
#define NM_TYPE_MODEM_GSM_MBM (nm_modem_gsm_mbm_get_type ())
#define NM_MODEM_GSM_MBM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_GSM_MBM, NMModemGsmMbm))
#define NM_MODEM_GSM_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MODEM_GSM_MBM, NMModemGsmMbmClass))
#define NM_IS_MODEM_GSM_MBM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_GSM_MBM))
#define NM_IS_MODEM_GSM_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_GSM_MBM))
#define NM_MODEM_GSM_MBM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_GSM_MBM, NMModemGsmMbmClass))
typedef struct {
NMModemGsm parent;
} NMModemGsmMbm;
typedef struct {
NMModemGsmClass parent;
} NMModemGsmMbmClass;
GType nm_modem_gsm_mbm_get_type (void);
NMDevice *nm_modem_gsm_mbm_new (const char *path,
const char *data_device,
const char *driver);
G_END_DECLS
#endif /* NM_MODEM_GSM_MBM_H */

View File

@@ -12,12 +12,15 @@
#include "nm-device-gsm-glue.h"
#define GSM_SECRETS_TRIES "gsm-secrets-tries"
G_DEFINE_TYPE (NMModemGsm, nm_modem_gsm, NM_TYPE_MODEM)
NMDevice *
nm_modem_gsm_new (const char *path,
const char *data_device,
const char *driver)
const char *driver,
guint32 ip_method)
{
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (data_device != NULL, NULL);
@@ -29,6 +32,7 @@ nm_modem_gsm_new (const char *path,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_INTERFACE_MANAGED, TRUE,
NM_MODEM_PATH, path,
NM_MODEM_IP_METHOD, ip_method,
NULL);
}
@@ -113,12 +117,22 @@ create_connect_properties (NMConnection *connection)
static NMActStageReturn
real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
{
NMActRequest *req;
NMConnection *connection;
GHashTable *properties;
const char *setting_name;
GPtrArray *hints = NULL;
const char *hint1 = NULL, *hint2 = NULL;
guint32 tries;
connection = nm_act_request_get_connection (nm_device_get_act_request (device));
req = nm_device_get_act_request (device);
g_assert (req);
connection = nm_act_request_get_connection (req);
g_assert (connection);
setting_name = nm_connection_need_secrets (connection, &hints);
if (!setting_name) {
GHashTable *properties;
properties = create_connect_properties (connection);
dbus_g_proxy_begin_call_with_timeout (nm_modem_get_proxy (NM_MODEM (device), MM_DBUS_INTERFACE_MODEM_SIMPLE),
"Connect", stage1_prepare_done,
@@ -130,6 +144,30 @@ real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
return NM_ACT_STAGE_RETURN_POSTPONE;
}
if (hints) {
if (hints->len > 0)
hint1 = g_ptr_array_index (hints, 0);
if (hints->len > 1)
hint2 = g_ptr_array_index (hints, 1);
}
nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), GSM_SECRETS_TRIES));
nm_act_request_request_connection_secrets (req,
setting_name,
tries ? TRUE : FALSE,
SECRETS_CALLER_HSO_GSM,
hint1,
hint2);
g_object_set_data (G_OBJECT (connection), GSM_SECRETS_TRIES, GUINT_TO_POINTER (++tries));
if (hints)
g_ptr_array_free (hints, TRUE);
return NM_ACT_STAGE_RETURN_POSTPONE;
}
static NMConnection *
real_get_best_auto_connection (NMDevice *dev,
GSList *connections,

View File

@@ -29,7 +29,8 @@ GType nm_modem_gsm_get_type (void);
NMDevice *nm_modem_gsm_new (const char *path,
const char *data_device,
const char *driver);
const char *driver,
guint32 ip_method);
G_END_DECLS

View File

@@ -4,8 +4,6 @@
#include "nm-modem-manager.h"
#include "nm-modem.h"
#include "nm-modem-gsm.h"
#include "nm-modem-gsm-hso.h"
#include "nm-modem-gsm-mbm.h"
#include "nm-modem-cdma.h"
#include "nm-dbus-manager.h"
#include "nm-utils.h"
@@ -54,7 +52,8 @@ get_modem_properties (DBusGConnection *connection,
const char *path,
char **data_device,
char **driver,
guint32 *type)
guint32 *type,
guint32 *ip_method)
{
DBusGProxy *proxy;
GValue value = { 0 };
@@ -80,7 +79,20 @@ get_modem_properties (DBusGConnection *connection,
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_STRING, "DataDevice",
G_TYPE_STRING, "IpMethod",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
*ip_method = g_value_get_uint (&value);
g_value_unset (&value);
} else {
g_warning ("Could not get IP method: %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, "Device",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
@@ -121,6 +133,7 @@ create_modem (NMModemManager *manager, const char *path)
char *data_device = NULL;
char *driver = NULL;
uint modem_type = MM_MODEM_TYPE_UNKNOWN;
uint ip_method = MM_MODEM_IP_METHOD_PPP;
if (g_hash_table_lookup (priv->modems, path)) {
nm_warning ("Modem with path %s already exists, ignoring", path);
@@ -128,7 +141,7 @@ create_modem (NMModemManager *manager, const char *path)
}
if (!get_modem_properties (nm_dbus_manager_get_connection (priv->dbus_mgr), path,
&data_device, &driver, &modem_type))
&data_device, &driver, &modem_type, &ip_method))
return;
if (modem_type == MM_MODEM_TYPE_UNKNOWN) {
@@ -146,14 +159,9 @@ create_modem (NMModemManager *manager, const char *path)
return;
}
if (modem_type == MM_MODEM_TYPE_GSM) {
if (!strcmp (driver, "hso"))
device = nm_modem_gsm_hso_new (path, data_device, driver);
else if (!strcmp (driver, "mbm"))
device = nm_modem_gsm_mbm_new (path, data_device, driver);
else
device = nm_modem_gsm_new (path, data_device, driver);
} else if (modem_type == MM_MODEM_TYPE_CDMA)
if (modem_type == MM_MODEM_TYPE_GSM)
device = nm_modem_gsm_new (path, data_device, driver, ip_method);
else if (modem_type == MM_MODEM_TYPE_CDMA)
device = nm_modem_cdma_new (path, data_device, driver);
else
g_error ("Invalid modem type");

View File

@@ -12,13 +12,15 @@
#define MM_DBUS_INTERFACE_MODEM_GSM_CARD "org.freedesktop.ModemManager.Modem.Gsm.Card"
#define MM_DBUS_INTERFACE_MODEM_GSM_NETWORK "org.freedesktop.ModemManager.Modem.Gsm.Network"
#define MM_DBUS_INTERFACE_MODEM_GSM_HSO "org.freedesktop.ModemManager.Modem.Gsm.Hso"
#define MM_DBUS_INTERFACE_MODEM_GSM_MBM "org.freedesktop.ModemManager.Modem.Gsm.Mbm"
#define MM_MODEM_TYPE_UNKNOWN 0
#define MM_MODEM_TYPE_GSM 1
#define MM_MODEM_TYPE_CDMA 2
#define MM_MODEM_IP_METHOD_PPP 0
#define MM_MODEM_IP_METHOD_STATIC 1
#define MM_MODEM_IP_METHOD_DHCP 2
/* Errors */
#define MM_SERIAL_OPEN_FAILED MM_DBUS_INTERFACE_MODEM ".SerialOpenFailed"

View File

@@ -3,6 +3,7 @@
#include <string.h>
#include "nm-modem.h"
#include "nm-device-private.h"
#include "NetworkManagerSystem.h"
#include "nm-device-interface.h"
#include "nm-dbus-manager.h"
#include "nm-setting-connection.h"
@@ -21,6 +22,7 @@ G_DEFINE_TYPE (NMModem, nm_modem, NM_TYPE_DEVICE)
enum {
PROP_0,
PROP_PATH,
PROP_IP_METHOD,
LAST_PROP
};
@@ -31,6 +33,7 @@ typedef struct {
DBusGProxy *proxy;
NMPPPManager *ppp_manager;
NMIP4Config *pending_ip4_config;
guint32 ip_method;
guint state_to_disconnected_id;
@@ -90,6 +93,9 @@ nm_modem_get_ppp_name (NMModem *self,
return NULL;
}
/*****************************************************************************/
/* IP method PPP */
static void
ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data)
{
@@ -144,7 +150,7 @@ ppp_stats (NMPPPManager *ppp_manager,
}
static NMActStageReturn
real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
ppp_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
NMActRequest *req;
@@ -186,10 +192,9 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
ppp_stage4 (NMDevice *device, NMIP4Config **config, NMDeviceStateReason *reason)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
*config = priv->pending_ip4_config;
@@ -198,12 +203,162 @@ real_act_stage4_get_ip4_config (NMDevice *device,
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/*****************************************************************************/
/* IP method static */
static void
static_stage3_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
{
NMDevice *device = NM_DEVICE (user_data);
GValueArray *ret_array = NULL;
GError *error = NULL;
if (dbus_g_proxy_end_call (proxy, call_id, &error,
G_TYPE_VALUE_ARRAY, &ret_array,
G_TYPE_INVALID)) {
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
NMIP4Address *addr;
int i;
addr = nm_ip4_address_new ();
nm_ip4_address_set_address (addr, g_value_get_uint (g_value_array_get_nth (ret_array, 0)));
nm_ip4_address_set_prefix (addr, 32);
priv->pending_ip4_config = nm_ip4_config_new ();
nm_ip4_config_take_address (priv->pending_ip4_config, addr);
for (i = 1; i < ret_array->n_values; i++)
nm_ip4_config_add_nameserver (priv->pending_ip4_config,
g_value_get_uint (g_value_array_get_nth (ret_array, i)));
g_value_array_free (ret_array);
nm_device_activate_schedule_stage4_ip_config_get (device);
} else {
nm_warning ("Retrieving IP4 configuration failed: %s", error->message);
g_error_free (error);
nm_device_state_changed (device,
NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
}
}
static NMActStageReturn
static_stage3_config (NMDevice *device, NMDeviceStateReason *reason)
{
dbus_g_proxy_begin_call (nm_modem_get_proxy (NM_MODEM (device), MM_DBUS_INTERFACE_MODEM),
"GetIP4Config", static_stage3_done,
device, NULL,
G_TYPE_INVALID);
return NM_ACT_STAGE_RETURN_POSTPONE;
}
static NMActStageReturn
static_stage4 (NMDevice *device, NMIP4Config **config, NMDeviceStateReason *reason)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
gboolean no_firmware = FALSE;
if (!nm_device_hw_bring_up (device, TRUE, &no_firmware)) {
if (no_firmware)
*reason = NM_DEVICE_STATE_REASON_FIRMWARE_MISSING;
else
*reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
return NM_ACT_STAGE_RETURN_FAILURE;
}
*config = priv->pending_ip4_config;
priv->pending_ip4_config = NULL;
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/*****************************************************************************/
/* IP method DHCP */
/*****************************************************************************/
static NMActStageReturn
real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
{
NMActStageReturn ret;
switch (NM_MODEM_GET_PRIVATE (device)->ip_method) {
case MM_MODEM_IP_METHOD_PPP:
ret = ppp_stage2_config (device, reason);
break;
case MM_MODEM_IP_METHOD_STATIC:
ret = NM_ACT_STAGE_RETURN_SUCCESS;
break;
case MM_MODEM_IP_METHOD_DHCP:
ret = NM_ACT_STAGE_RETURN_SUCCESS;
break;
default:
g_warning ("Invalid IP method");
ret = NM_ACT_STAGE_RETURN_FAILURE;
break;
}
return ret;
}
static NMActStageReturn
real_act_stage3_ip_config_start (NMDevice *device, NMDeviceStateReason *reason)
{
NMActStageReturn ret;
switch (NM_MODEM_GET_PRIVATE (device)->ip_method) {
case MM_MODEM_IP_METHOD_PPP:
ret = NM_ACT_STAGE_RETURN_SUCCESS;
break;
case MM_MODEM_IP_METHOD_STATIC:
ret = static_stage3_config (device, reason);
break;
case MM_MODEM_IP_METHOD_DHCP:
ret = NM_DEVICE_CLASS (nm_modem_parent_class)->act_stage3_ip_config_start (device, reason);
break;
default:
g_warning ("Invalid IP method");
ret = NM_ACT_STAGE_RETURN_FAILURE;
break;
}
return ret;
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
NMActStageReturn ret;
switch (NM_MODEM_GET_PRIVATE (device)->ip_method) {
case MM_MODEM_IP_METHOD_PPP:
ret = ppp_stage4 (device, config, reason);
break;
case MM_MODEM_IP_METHOD_STATIC:
ret = static_stage4 (device, config, reason);
break;
case MM_MODEM_IP_METHOD_DHCP:
ret = NM_DEVICE_CLASS (nm_modem_parent_class)->act_stage4_get_ip4_config (device, config, reason);
break;
default:
g_warning ("Invalid IP method");
ret = NM_ACT_STAGE_RETURN_FAILURE;
break;
}
return ret;
}
static void
real_deactivate_quickly (NMDevice *device)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
nm_device_set_ip_iface (device, NULL);
const char *iface;
if (priv->pending_ip4_config) {
g_object_unref (priv->pending_ip4_config);
@@ -212,13 +367,31 @@ real_deactivate_quickly (NMDevice *device)
priv->in_bytes = priv->out_bytes = 0;
switch (NM_MODEM_GET_PRIVATE (device)->ip_method) {
case MM_MODEM_IP_METHOD_PPP:
if (priv->ppp_manager) {
g_object_unref (priv->ppp_manager);
priv->ppp_manager = NULL;
}
break;
case MM_MODEM_IP_METHOD_STATIC:
case MM_MODEM_IP_METHOD_DHCP:
iface = nm_device_get_iface (device);
dbus_g_proxy_call_no_reply (nm_modem_get_proxy (NM_MODEM (device), NULL),
"Enable", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID);
nm_system_device_flush_ip4_routes_with_iface (iface);
nm_system_device_flush_ip4_addresses_with_iface (iface);
nm_system_device_set_up_down_with_iface (iface, FALSE, NULL);
break;
default:
g_warning ("Invalid IP method");
break;
}
/* FIXME: This shouldn't be needed */
dbus_g_proxy_call_no_reply (nm_modem_get_proxy (NM_MODEM (device), NULL), "Disconnect", G_TYPE_INVALID);
if (NM_DEVICE_CLASS (nm_modem_parent_class)->deactivate)
NM_DEVICE_CLASS (nm_modem_parent_class)->deactivate (device);
}
static guint32
@@ -277,6 +450,40 @@ device_state_changed (NMDeviceInterface *device,
}
}
static gboolean
real_hw_is_up (NMDevice *device)
{
guint32 ip_method = NM_MODEM_GET_PRIVATE (device)->ip_method;
if (ip_method == MM_MODEM_IP_METHOD_STATIC || ip_method == MM_MODEM_IP_METHOD_DHCP) {
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
NMDeviceState state;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
if (priv->pending_ip4_config || state == NM_DEVICE_STATE_IP_CONFIG || state == NM_DEVICE_STATE_ACTIVATED)
return nm_system_device_is_up (device);
}
return TRUE;
}
static gboolean
real_hw_bring_up (NMDevice *device, gboolean *no_firmware)
{
guint32 ip_method = NM_MODEM_GET_PRIVATE (device)->ip_method;
if (ip_method == MM_MODEM_IP_METHOD_STATIC || ip_method == MM_MODEM_IP_METHOD_DHCP) {
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (device);
NMDeviceState state;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
if (priv->pending_ip4_config || state == NM_DEVICE_STATE_IP_CONFIG || state == NM_DEVICE_STATE_ACTIVATED)
return nm_system_device_set_up_down (device, TRUE, no_firmware);
}
return TRUE;
}
/*****************************************************************************/
static void
@@ -330,6 +537,9 @@ get_property (GObject *object, guint prop_id,
case PROP_PATH:
g_value_set_string (value, priv->path);
break;
case PROP_IP_METHOD:
g_value_set_uint (value, priv->ip_method);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -348,6 +558,9 @@ set_property (GObject *object, guint prop_id,
/* Construct only */
priv->path = g_value_dup_string (value);
break;
case PROP_IP_METHOD:
priv->ip_method = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -388,8 +601,11 @@ nm_modem_class_init (NMModemClass *klass)
device_class->get_generic_capabilities = real_get_generic_capabilities;
device_class->act_stage2_config = real_act_stage2_config;
device_class->act_stage3_ip_config_start = real_act_stage3_ip_config_start;
device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
device_class->deactivate_quickly = real_deactivate_quickly;
device_class->hw_is_up = real_hw_is_up;
device_class->hw_bring_up = real_hw_bring_up;
/* Properties */
g_object_class_install_property
@@ -400,6 +616,16 @@ nm_modem_class_init (NMModemClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_IP_METHOD,
g_param_spec_uint (NM_MODEM_IP_METHOD,
"IP method",
"IP method",
MM_MODEM_IP_METHOD_PPP,
MM_MODEM_IP_METHOD_DHCP,
MM_MODEM_IP_METHOD_PPP,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* Signals */
signals[PPP_STATS] =
g_signal_new ("ppp-stats",

View File

@@ -17,6 +17,7 @@ G_BEGIN_DECLS
#define NM_MODEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM, NMModemClass))
#define NM_MODEM_PATH "path"
#define NM_MODEM_IP_METHOD "ip-method"
typedef struct {
NMDevice parent;