mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 01:20:12 +01:00
mobile: merge NMModemCdma into NMModemOld
GSM is next...
This commit is contained in:
parent
06499b1e1b
commit
27acebe862
8 changed files with 320 additions and 408 deletions
|
|
@ -41,9 +41,9 @@ src/dhcp-manager/nm-dhcp-manager.c
|
|||
src/dns-manager/nm-dns-manager.c
|
||||
src/logging/nm-logging.c
|
||||
src/config/nm-config.c
|
||||
src/modem-manager/nm-modem-cdma.c
|
||||
src/modem-manager/nm-modem-gsm.c
|
||||
src/modem-manager/nm-modem-broadband.c
|
||||
src/modem-manager/nm-modem-old.c
|
||||
src/devices/nm-device-bond.c
|
||||
src/devices/nm-device-adsl.c
|
||||
src/devices/nm-device-bridge.c
|
||||
|
|
|
|||
|
|
@ -122,8 +122,6 @@ nm_sources = \
|
|||
logging/nm-logging.c \
|
||||
logging/nm-logging.h \
|
||||
\
|
||||
modem-manager/nm-modem-cdma.c \
|
||||
modem-manager/nm-modem-cdma.h \
|
||||
modem-manager/nm-modem-old.c \
|
||||
modem-manager/nm-modem-old.h \
|
||||
modem-manager/nm-modem-old-types.h \
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "nm-device-modem.h"
|
||||
#include "nm-modem.h"
|
||||
#include "nm-modem-cdma.h"
|
||||
#include "nm-modem-gsm.h"
|
||||
#include "nm-device-private.h"
|
||||
#include "nm-rfkill.h"
|
||||
|
|
@ -344,16 +343,15 @@ nm_device_modem_new (NMModem *modem, const char *driver)
|
|||
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;
|
||||
current_caps = caps;
|
||||
type_desc = "CDMA/EVDO";
|
||||
ip_iface = nm_modem_get_data_port (modem);
|
||||
} else if (NM_IS_MODEM_GSM (modem)) {
|
||||
if (NM_IS_MODEM_GSM (modem)) {
|
||||
caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
|
||||
current_caps = caps;
|
||||
type_desc = "GSM/UMTS";
|
||||
ip_iface = nm_modem_get_data_port (modem);
|
||||
} else if (NM_IS_MODEM_OLD (modem)) {
|
||||
nm_modem_old_get_capabilities (NM_MODEM_OLD (modem), &caps, ¤t_caps);
|
||||
type_desc = "Broadband";
|
||||
ip_iface = nm_modem_get_data_port (modem);
|
||||
}
|
||||
#if WITH_MODEM_MANAGER_1
|
||||
else if (NM_IS_MODEM_BROADBAND (modem)) {
|
||||
|
|
|
|||
|
|
@ -1,334 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2009 - 2011 Red Hat, Inc.
|
||||
* Copyright (C) 2009 Novell, Inc.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-modem-cdma.h"
|
||||
#include "nm-modem-old-types.h"
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-device.h"
|
||||
#include "nm-device-private.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-setting-cdma.h"
|
||||
#include "nm-setting-ppp.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
G_DEFINE_TYPE (NMModemCdma, nm_modem_cdma, NM_TYPE_MODEM_OLD)
|
||||
|
||||
#define NM_MODEM_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MODEM_CDMA, NMModemCdmaPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGProxyCall *call;
|
||||
|
||||
GHashTable *connect_properties;
|
||||
} NMModemCdmaPrivate;
|
||||
|
||||
|
||||
#define NM_CDMA_ERROR (nm_cdma_error_quark ())
|
||||
|
||||
static GQuark
|
||||
nm_cdma_error_quark (void)
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string ("nm-cdma-error");
|
||||
return quark;
|
||||
}
|
||||
|
||||
|
||||
NMModem *
|
||||
nm_modem_cdma_new (const char *path,
|
||||
const char *data_device,
|
||||
guint32 ip_method,
|
||||
MMOldModemState state)
|
||||
{
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (data_device != NULL, NULL);
|
||||
|
||||
return (NMModem *) g_object_new (NM_TYPE_MODEM_CDMA,
|
||||
NM_MODEM_PATH, path,
|
||||
NM_MODEM_UID, data_device,
|
||||
NM_MODEM_CONTROL_PORT, NULL,
|
||||
NM_MODEM_DATA_PORT, data_device,
|
||||
NM_MODEM_IP_METHOD, ip_method,
|
||||
NM_MODEM_CONNECTED, (state == MM_OLD_MODEM_STATE_CONNECTED),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
stage1_prepare_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
|
||||
{
|
||||
NMModemCdma *self = NM_MODEM_CDMA (user_data);
|
||||
NMModemCdmaPrivate *priv = NM_MODEM_CDMA_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
|
||||
priv->call = NULL;
|
||||
|
||||
if (priv->connect_properties) {
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = NULL;
|
||||
}
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID))
|
||||
g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, TRUE, NM_DEVICE_STATE_REASON_NONE);
|
||||
else {
|
||||
nm_log_warn (LOGD_MB, "CDMA connection failed: (%d) %s",
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
g_error_free (error);
|
||||
g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_connect (NMModemCdma *self)
|
||||
{
|
||||
NMModemCdmaPrivate *priv = NM_MODEM_CDMA_GET_PRIVATE (self);
|
||||
DBusGProxy *proxy;
|
||||
|
||||
proxy = nm_modem_old_get_proxy (NM_MODEM_OLD (self), MM_OLD_DBUS_INTERFACE_MODEM_SIMPLE);
|
||||
priv->call = dbus_g_proxy_begin_call_with_timeout (proxy,
|
||||
"Connect", stage1_prepare_done,
|
||||
self, NULL, 120000,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT, priv->connect_properties,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
|
||||
static void
|
||||
stage1_enable_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
|
||||
{
|
||||
NMModemCdma *self = NM_MODEM_CDMA (user_data);
|
||||
GError *error = NULL;
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID))
|
||||
do_connect (self);
|
||||
else {
|
||||
nm_log_warn (LOGD_MB, "CDMA modem enable failed: (%d) %s",
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
g_error_free (error);
|
||||
g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
create_connect_properties (NMConnection *connection)
|
||||
{
|
||||
NMSettingCdma *setting;
|
||||
GHashTable *properties;
|
||||
const char *str;
|
||||
|
||||
setting = nm_connection_get_setting_cdma (connection);
|
||||
properties = value_hash_create ();
|
||||
|
||||
str = nm_setting_cdma_get_number (setting);
|
||||
if (str)
|
||||
value_hash_add_str (properties, "number", str);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
static NMActStageReturn
|
||||
act_stage1_prepare (NMModem *modem,
|
||||
NMActRequest *req,
|
||||
GPtrArray **out_hints,
|
||||
const char **out_setting_name,
|
||||
NMDeviceStateReason *reason)
|
||||
{
|
||||
NMModemCdma *self = NM_MODEM_CDMA (modem);
|
||||
NMModemCdmaPrivate *priv = NM_MODEM_CDMA_GET_PRIVATE (self);
|
||||
NMConnection *connection;
|
||||
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
|
||||
*out_setting_name = nm_connection_need_secrets (connection, out_hints);
|
||||
if (!*out_setting_name) {
|
||||
gboolean enabled = nm_modem_get_mm_enabled (modem);
|
||||
DBusGProxy *proxy;
|
||||
|
||||
if (priv->connect_properties)
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = create_connect_properties (connection);
|
||||
|
||||
if (enabled)
|
||||
do_connect (self);
|
||||
else {
|
||||
proxy = nm_modem_old_get_proxy (NM_MODEM_OLD (modem), MM_OLD_DBUS_INTERFACE_MODEM);
|
||||
dbus_g_proxy_begin_call_with_timeout (proxy,
|
||||
"Enable", stage1_enable_done,
|
||||
modem, NULL, 20000,
|
||||
G_TYPE_BOOLEAN, TRUE,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
} else {
|
||||
/* NMModem will handle requesting secrets... */
|
||||
}
|
||||
|
||||
return NM_ACT_STAGE_RETURN_POSTPONE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMModem *modem,
|
||||
NMConnection *connection,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingCdma *s_cdma;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
g_assert (s_con);
|
||||
|
||||
if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_CDMA_SETTING_NAME)) {
|
||||
g_set_error (error,
|
||||
NM_CDMA_ERROR, NM_CDMA_ERROR_CONNECTION_NOT_CDMA,
|
||||
"The connection was not a CDMA connection.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
s_cdma = nm_connection_get_setting_cdma (connection);
|
||||
if (!s_cdma) {
|
||||
g_set_error (error,
|
||||
NM_CDMA_ERROR, NM_CDMA_ERROR_CONNECTION_INVALID,
|
||||
"The connection was not a valid CDMA connection.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
complete_connection (NMModem *modem,
|
||||
NMConnection *connection,
|
||||
const GSList *existing_connections,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingCdma *s_cdma;
|
||||
NMSettingPPP *s_ppp;
|
||||
|
||||
s_cdma = nm_connection_get_setting_cdma (connection);
|
||||
if (!s_cdma) {
|
||||
s_cdma = (NMSettingCdma *) nm_setting_cdma_new ();
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_cdma));
|
||||
}
|
||||
|
||||
if (!nm_setting_cdma_get_number (s_cdma))
|
||||
g_object_set (G_OBJECT (s_cdma), NM_SETTING_CDMA_NUMBER, "#777", NULL);
|
||||
|
||||
s_ppp = nm_connection_get_setting_ppp (connection);
|
||||
if (!s_ppp) {
|
||||
s_ppp = (NMSettingPPP *) nm_setting_ppp_new ();
|
||||
g_object_set (G_OBJECT (s_ppp),
|
||||
NM_SETTING_PPP_LCP_ECHO_FAILURE, 5,
|
||||
NM_SETTING_PPP_LCP_ECHO_INTERVAL, 30,
|
||||
NULL);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ppp));
|
||||
}
|
||||
|
||||
nm_utils_complete_generic (connection,
|
||||
NM_SETTING_CDMA_SETTING_NAME,
|
||||
existing_connections,
|
||||
_("CDMA connection %d"),
|
||||
NULL,
|
||||
FALSE); /* No IPv6 yet by default */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_user_pass (NMModem *modem,
|
||||
NMConnection *connection,
|
||||
const char **user,
|
||||
const char **pass)
|
||||
{
|
||||
NMSettingCdma *s_cdma;
|
||||
|
||||
s_cdma = nm_connection_get_setting_cdma (connection);
|
||||
if (!s_cdma)
|
||||
return FALSE;
|
||||
|
||||
if (user)
|
||||
*user = nm_setting_cdma_get_username (s_cdma);
|
||||
if (pass)
|
||||
*pass = nm_setting_cdma_get_password (s_cdma);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
deactivate (NMModem *modem, NMDevice *device)
|
||||
{
|
||||
NMModemCdmaPrivate *priv = NM_MODEM_CDMA_GET_PRIVATE (modem);
|
||||
|
||||
if (priv->call) {
|
||||
DBusGProxy *proxy;
|
||||
|
||||
proxy = nm_modem_old_get_proxy (NM_MODEM_OLD (modem), MM_OLD_DBUS_INTERFACE_MODEM_SIMPLE);
|
||||
dbus_g_proxy_cancel_call (proxy, priv->call);
|
||||
priv->call = NULL;
|
||||
}
|
||||
|
||||
NM_MODEM_CLASS (nm_modem_cdma_parent_class)->deactivate (modem, device);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nm_modem_cdma_init (NMModemCdma *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMModemCdma *self = NM_MODEM_CDMA (object);
|
||||
NMModemCdmaPrivate *priv = NM_MODEM_CDMA_GET_PRIVATE (self);
|
||||
|
||||
if (priv->connect_properties)
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
|
||||
G_OBJECT_CLASS (nm_modem_cdma_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_modem_cdma_class_init (NMModemCdmaClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
NMModemClass *modem_class = NM_MODEM_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMModemCdmaPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->dispose = dispose;
|
||||
modem_class->get_user_pass = get_user_pass;
|
||||
modem_class->check_connection_compatible = check_connection_compatible;
|
||||
modem_class->complete_connection = complete_connection;
|
||||
modem_class->act_stage1_prepare = act_stage1_prepare;
|
||||
modem_class->deactivate = deactivate;
|
||||
|
||||
dbus_g_error_domain_register (NM_CDMA_ERROR, NULL, NM_TYPE_CDMA_ERROR);
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2009 Red Hat, Inc.
|
||||
* Copyright (C) 2009 Novell, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_MODEM_CDMA_H
|
||||
#define NM_MODEM_CDMA_H
|
||||
|
||||
#include "nm-modem-old.h"
|
||||
#include "nm-modem-old-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_MODEM_CDMA (nm_modem_cdma_get_type ())
|
||||
#define NM_MODEM_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_CDMA, NMModemCdma))
|
||||
#define NM_MODEM_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MODEM_CDMA, NMModemCdmaClass))
|
||||
#define NM_IS_MODEM_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_CDMA))
|
||||
#define NM_IS_MODEM_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_CDMA))
|
||||
#define NM_MODEM_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_CDMA, NMModemCdmaClass))
|
||||
|
||||
typedef enum {
|
||||
NM_CDMA_ERROR_CONNECTION_NOT_CDMA = 0, /*< nick=ConnectionNotCdma >*/
|
||||
NM_CDMA_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/
|
||||
NM_CDMA_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/
|
||||
} NMCdmaError;
|
||||
|
||||
typedef struct {
|
||||
NMModemOld parent;
|
||||
} NMModemCdma;
|
||||
|
||||
typedef struct {
|
||||
NMModemOldClass parent;
|
||||
} NMModemCdmaClass;
|
||||
|
||||
GType nm_modem_cdma_get_type (void);
|
||||
|
||||
NMModem *nm_modem_cdma_new (const char *path,
|
||||
const char *data_device,
|
||||
guint32 ip_method,
|
||||
MMOldModemState state);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_MODEM_CDMA_H */
|
||||
|
|
@ -26,7 +26,6 @@
|
|||
#include "nm-logging.h"
|
||||
#include "nm-modem.h"
|
||||
#include "nm-modem-gsm.h"
|
||||
#include "nm-modem-cdma.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-modem-old-types.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
|
|
@ -211,7 +210,7 @@ create_modem (NMModemManager *self, const char *path)
|
|||
if (modem_type == MM_OLD_MODEM_TYPE_GSM)
|
||||
modem = nm_modem_gsm_new (path, data_device, ip_method, state);
|
||||
else if (modem_type == MM_OLD_MODEM_TYPE_CDMA)
|
||||
modem = nm_modem_cdma_new (path, data_device, ip_method, state);
|
||||
modem = nm_modem_old_new (path, data_device, ip_method, MM_OLD_MODEM_TYPE_CDMA, state);
|
||||
else
|
||||
nm_log_warn (LOGD_MB, "unknown modem type '%d'", modem_type);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "nm-modem-old.h"
|
||||
#include "nm-system.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
|
|
@ -40,9 +42,11 @@ typedef struct {
|
|||
DBusGProxy *proxy;
|
||||
DBusGProxy *props_proxy;
|
||||
|
||||
DBusGProxyCall *call;
|
||||
|
||||
MMOldModemState state;
|
||||
NMDeviceModemCapabilities caps;
|
||||
|
||||
DBusGProxyCall *call;
|
||||
GHashTable *connect_properties;
|
||||
} NMModemOldPrivate;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -152,6 +156,125 @@ set_mm_enabled (NMModem *self, gboolean enabled)
|
|||
update_mm_enabled (self, enabled);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
stage1_prepare_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
|
||||
{
|
||||
NMModemOld *self = NM_MODEM_OLD (user_data);
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
|
||||
priv->call = NULL;
|
||||
|
||||
if (priv->connect_properties) {
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = NULL;
|
||||
}
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID))
|
||||
g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, TRUE, NM_DEVICE_STATE_REASON_NONE);
|
||||
else {
|
||||
nm_log_warn (LOGD_MB, "Modem connection failed: (%d) %s",
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
g_error_free (error);
|
||||
g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_connect (NMModemOld *self)
|
||||
{
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (self);
|
||||
DBusGProxy *proxy;
|
||||
|
||||
proxy = nm_modem_old_get_proxy (NM_MODEM_OLD (self), MM_OLD_DBUS_INTERFACE_MODEM_SIMPLE);
|
||||
priv->call = dbus_g_proxy_begin_call_with_timeout (proxy,
|
||||
"Connect", stage1_prepare_done,
|
||||
self, NULL, 120000,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT, priv->connect_properties,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
|
||||
static void
|
||||
stage1_enable_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
|
||||
{
|
||||
NMModemOld *self = NM_MODEM_OLD (user_data);
|
||||
GError *error = NULL;
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID))
|
||||
do_connect (self);
|
||||
else {
|
||||
nm_log_warn (LOGD_MB, "Modem enable failed: (%d) %s",
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
g_error_free (error);
|
||||
g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
create_connect_properties (NMConnection *connection)
|
||||
{
|
||||
NMSettingCdma *s_cdma;
|
||||
GHashTable *properties;
|
||||
const char *str;
|
||||
|
||||
properties = value_hash_create ();
|
||||
|
||||
s_cdma = nm_connection_get_setting_cdma (connection);
|
||||
if (s_cdma) {
|
||||
str = nm_setting_cdma_get_number (s_cdma);
|
||||
if (str)
|
||||
value_hash_add_str (properties, "number", str);
|
||||
return properties;
|
||||
}
|
||||
|
||||
g_hash_table_destroy (properties);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static NMActStageReturn
|
||||
act_stage1_prepare (NMModem *modem,
|
||||
NMActRequest *req,
|
||||
GPtrArray **out_hints,
|
||||
const char **out_setting_name,
|
||||
NMDeviceStateReason *reason)
|
||||
{
|
||||
NMModemOld *self = NM_MODEM_OLD (modem);
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (self);
|
||||
NMConnection *connection;
|
||||
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
|
||||
*out_setting_name = nm_connection_need_secrets (connection, out_hints);
|
||||
if (!*out_setting_name) {
|
||||
gboolean enabled = nm_modem_get_mm_enabled (modem);
|
||||
DBusGProxy *proxy;
|
||||
|
||||
if (priv->connect_properties)
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = create_connect_properties (connection);
|
||||
|
||||
if (enabled)
|
||||
do_connect (self);
|
||||
else {
|
||||
proxy = nm_modem_old_get_proxy (NM_MODEM_OLD (modem), MM_OLD_DBUS_INTERFACE_MODEM);
|
||||
dbus_g_proxy_begin_call_with_timeout (proxy,
|
||||
"Enable", stage1_enable_done,
|
||||
modem, NULL, 20000,
|
||||
G_TYPE_BOOLEAN, TRUE,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
} else {
|
||||
/* NMModem will handle requesting secrets... */
|
||||
}
|
||||
|
||||
return NM_ACT_STAGE_RETURN_POSTPONE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* IP method static */
|
||||
|
||||
|
|
@ -349,6 +472,174 @@ modem_properties_changed (DBusGProxy *proxy,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMModem *modem,
|
||||
NMConnection *connection,
|
||||
GError **error)
|
||||
{
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (modem);
|
||||
NMSettingConnection *s_con;
|
||||
gboolean valid_cdma = FALSE;
|
||||
const char *ctype;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
g_assert (s_con);
|
||||
ctype = nm_setting_connection_get_connection_type (s_con);
|
||||
g_assert (ctype);
|
||||
|
||||
/* Check for valid CDMA first */
|
||||
if (strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME) == 0)
|
||||
valid_cdma = !!nm_connection_get_setting_cdma (connection);
|
||||
|
||||
/* Validate CDMA */
|
||||
if (priv->caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
|
||||
if (valid_cdma)
|
||||
return TRUE;
|
||||
|
||||
/* If the modem is only CDMA and the connection is not CDMA, error */
|
||||
if ((priv->caps ^ NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) == 0) {
|
||||
g_set_error (error, NM_MODEM_ERROR, NM_MODEM_ERROR_CONNECTION_NOT_CDMA,
|
||||
"The connection was not a CDMA connection.");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
g_set_error (error, NM_MODEM_ERROR, NM_MODEM_ERROR_CONNECTION_INCOMPATIBLE,
|
||||
"The connection was not not compatible with this modem (caps 0x%X)",
|
||||
priv->caps);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
complete_ppp_setting (NMConnection *connection)
|
||||
{
|
||||
NMSettingPPP *s_ppp;
|
||||
|
||||
s_ppp = nm_connection_get_setting_ppp (connection);
|
||||
if (!s_ppp) {
|
||||
s_ppp = (NMSettingPPP *) nm_setting_ppp_new ();
|
||||
g_object_set (G_OBJECT (s_ppp),
|
||||
NM_SETTING_PPP_LCP_ECHO_FAILURE, 5,
|
||||
NM_SETTING_PPP_LCP_ECHO_INTERVAL, 30,
|
||||
NULL);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ppp));
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
complete_connection_cdma (NMConnection *connection,
|
||||
const GSList *existing_connections,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingCdma *s_cdma;
|
||||
|
||||
s_cdma = nm_connection_get_setting_cdma (connection);
|
||||
if (!s_cdma) {
|
||||
s_cdma = (NMSettingCdma *) nm_setting_cdma_new ();
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_cdma));
|
||||
}
|
||||
|
||||
if (!nm_setting_cdma_get_number (s_cdma))
|
||||
g_object_set (G_OBJECT (s_cdma), NM_SETTING_CDMA_NUMBER, "#777", NULL);
|
||||
|
||||
complete_ppp_setting (connection);
|
||||
|
||||
nm_utils_complete_generic (connection,
|
||||
NM_SETTING_CDMA_SETTING_NAME,
|
||||
existing_connections,
|
||||
_("CDMA connection %d"),
|
||||
NULL,
|
||||
FALSE); /* No IPv6 yet by default */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
complete_connection (NMModem *modem,
|
||||
NMConnection *connection,
|
||||
const GSList *existing_connections,
|
||||
GError **error)
|
||||
{
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (modem);
|
||||
|
||||
if (priv->caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
|
||||
return complete_connection_cdma (connection, existing_connections, error);
|
||||
|
||||
g_set_error_literal (error, NM_MODEM_ERROR, NM_MODEM_ERROR_CONNECTION_INCOMPATIBLE,
|
||||
"Modem had no WWAN capabilities.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
get_user_pass (NMModem *modem,
|
||||
NMConnection *connection,
|
||||
const char **user,
|
||||
const char **pass)
|
||||
{
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (modem);
|
||||
NMSettingCdma *s_cdma;
|
||||
|
||||
if (priv->caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
|
||||
s_cdma = nm_connection_get_setting_cdma (connection);
|
||||
if (s_cdma) {
|
||||
if (user)
|
||||
*user = nm_setting_cdma_get_username (s_cdma);
|
||||
if (pass)
|
||||
*pass = nm_setting_cdma_get_password (s_cdma);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
nm_modem_old_get_capabilities (NMModemOld *self,
|
||||
NMDeviceModemCapabilities *modem_caps,
|
||||
NMDeviceModemCapabilities *current_caps)
|
||||
{
|
||||
*current_caps = *modem_caps = NM_MODEM_OLD_GET_PRIVATE (self)->caps;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMModem *
|
||||
nm_modem_old_new (const char *path,
|
||||
const char *data_device,
|
||||
guint32 ip_method,
|
||||
guint32 modem_type,
|
||||
MMOldModemState state)
|
||||
{
|
||||
NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE;
|
||||
NMModemOld *self;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (data_device != NULL, NULL);
|
||||
g_return_val_if_fail (modem_type != MM_OLD_MODEM_TYPE_UNKNOWN, NULL);
|
||||
|
||||
self = (NMModemOld *) g_object_new (NM_TYPE_MODEM_OLD,
|
||||
NM_MODEM_PATH, path,
|
||||
NM_MODEM_UID, data_device,
|
||||
NM_MODEM_CONTROL_PORT, NULL,
|
||||
NM_MODEM_DATA_PORT, data_device,
|
||||
NM_MODEM_IP_METHOD, ip_method,
|
||||
NM_MODEM_CONNECTED, (state == MM_OLD_MODEM_STATE_CONNECTED),
|
||||
NULL);
|
||||
if (self) {
|
||||
if (modem_type == MM_OLD_MODEM_TYPE_CDMA)
|
||||
caps |= NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
|
||||
|
||||
NM_MODEM_OLD_GET_PRIVATE (self)->caps = caps;
|
||||
}
|
||||
|
||||
return (NMModem *) self;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_modem_old_init (NMModemOld *self)
|
||||
{
|
||||
|
|
@ -411,6 +702,11 @@ dispose (GObject *object)
|
|||
priv->props_proxy = NULL;
|
||||
}
|
||||
|
||||
if (priv->connect_properties) {
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (nm_modem_old_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
|
|
@ -426,6 +722,10 @@ nm_modem_old_class_init (NMModemOldClass *klass)
|
|||
object_class->constructor = constructor;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
modem_class->get_user_pass = get_user_pass;
|
||||
modem_class->complete_connection = complete_connection;
|
||||
modem_class->check_connection_compatible = check_connection_compatible;
|
||||
modem_class->act_stage1_prepare = act_stage1_prepare;
|
||||
modem_class->static_stage3_ip4_config_start = static_stage3_ip4_config_start;
|
||||
modem_class->disconnect = disconnect;
|
||||
modem_class->deactivate = deactivate;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <dbus/dbus-glib.h>
|
||||
#include <glib-object.h>
|
||||
#include "nm-modem.h"
|
||||
#include "nm-modem-old-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -45,6 +46,16 @@ typedef struct {
|
|||
|
||||
GType nm_modem_old_get_type (void);
|
||||
|
||||
NMModem *nm_modem_old_new (const char *path,
|
||||
const char *data_device,
|
||||
guint32 ip_method,
|
||||
guint32 modem_type,
|
||||
MMOldModemState state);
|
||||
|
||||
void nm_modem_old_get_capabilities (NMModemOld *self,
|
||||
NMDeviceModemCapabilities *modem_caps,
|
||||
NMDeviceModemCapabilities *current_caps);
|
||||
|
||||
/* Protected */
|
||||
DBusGProxy *nm_modem_old_get_proxy (NMModemOld *modem, const gchar *interface);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue