wwan: add support for using oFono as a modem manager

This patch adds core wwan support for ofono, as used by Ubuntu Touch.

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>

https://mail.gnome.org/archives/networkmanager-list/2016-June/msg00089.html
This commit is contained in:
Mathieu Trudel-Lapierre 2016-06-10 17:56:25 -04:00 committed by Thomas Haller
parent 13b2253df6
commit a6e81af87f
8 changed files with 1756 additions and 22 deletions

View file

@ -734,6 +734,15 @@ else
fi
AM_CONDITIONAL(WITH_BLUEZ5_DUN, test "${enable_bluez5_dun}" = "yes")
# OFONO
AC_ARG_WITH(ofono, AS_HELP_STRING([--with-ofono], [Enable oFono support]),,[with_ofono=yes])
if (test "${with_ofono}" = "yes"); then
AC_DEFINE(WITH_OFONO, 1, [Define if you have oFono support])
else
AC_DEFINE(WITH_OFONO, 0, [Define if you have oFono support])
fi
AM_CONDITIONAL(WITH_OFONO, test "${with_ofono}" = "yes")
# DHCP client support
AC_ARG_WITH([dhclient], AS_HELP_STRING([--with-dhclient=yes|no|path], [Enable dhclient 4.x support]))
AC_ARG_WITH([dhcpcd], AS_HELP_STRING([--with-dhcpcd=yes|no|path], [Enable dhcpcd 4.x support]))

View file

@ -42,6 +42,13 @@ libnm_wwan_la_SOURCES = \
\
$(GLIB_GENERATED)
if WITH_OFONO
libnm_wwan_la_SOURCES += \
nm-modem-ofono.c \
nm-modem-ofono.h \
$(NULL)
endif
WWAN_SYMBOL_VIS_FILE=$(srcdir)/wwan-exports.ver
libnm_wwan_la_LDFLAGS = \

View file

@ -112,6 +112,7 @@ modem_prepare_result (NMModem *modem,
if (success)
nm_device_activate_schedule_stage2_device_config (device);
else {
if (reason == NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT) {
/* If the connect failed because the SIM PIN was wrong don't allow
* the device to be auto-activated anymore, which would risk locking
@ -562,6 +563,7 @@ get_ip_iface_identifier (NMDevice *device, NMUtilsIPv6IfaceId *out_iid)
g_return_val_if_fail (priv->modem, FALSE);
success = nm_modem_get_iid (priv->modem, out_iid);
if (!success)
success = NM_DEVICE_CLASS (nm_device_modem_parent_class)->get_ip_iface_identifier (device, out_iid);
return success;

View file

@ -17,7 +17,7 @@
*
* Copyright (C) 2009 - 2014 Red Hat, Inc.
* Copyright (C) 2009 Novell, Inc.
* Copyright (C) 2009 Canonical Ltd.
* Copyright (C) 2009 - 2013 Canonical Ltd.
*/
#include "nm-default.h"
@ -37,6 +37,10 @@
#define sd_booted() FALSE
#endif
#if WITH_OFONO
#include "nm-modem-ofono.h"
#endif
#define MODEM_POKE_INTERVAL 120
G_DEFINE_TYPE (NMModemManager, nm_modem_manager, G_TYPE_OBJECT)
@ -49,6 +53,12 @@ struct _NMModemManagerPrivate {
gulong mm_object_added_id;
gulong mm_object_removed_id;
#if WITH_OFONO
GDBusProxy *ofono_proxy;
guint ofono_name_owner_changed_id;
#endif
/* Common */
GHashTable *modems;
};
@ -206,6 +216,178 @@ modem_manager_name_owner_changed (MMManager *modem_manager,
* modem_manager_available (self);
*/
}
#if WITH_OFONO
static void
ofono_clear_signals (NMModemManager *self)
{
if (!self->priv->ofono_proxy)
return;
if (self->priv->ofono_name_owner_changed_id) {
if (g_signal_handler_is_connected (self->priv->ofono_proxy,
self->priv->ofono_name_owner_changed_id))
g_signal_handler_disconnect (self->priv->ofono_proxy,
self->priv->ofono_name_owner_changed_id);
self->priv->ofono_name_owner_changed_id = 0;
}
}
static void
ofono_create_modem (NMModemManager *self, const char *path)
{
NMModem *modem = NULL;
if (g_hash_table_lookup (self->priv->modems, path)) {
nm_log_warn (LOGD_MB, "modem with path %s already exists, ignoring", path);
return;
}
/* Create modem instance */
modem = nm_modem_ofono_new (path);
if (modem)
handle_new_modem (self, modem);
else
nm_log_warn (LOGD_MB, "Failed to create oFono modem for %s", path);
}
static void
ofono_signal_cb (GDBusProxy *proxy,
gchar *sender_name,
gchar *signal_name,
GVariant *parameters,
gpointer user_data)
{
NMModemManager *self = NM_MODEM_MANAGER (user_data);
gchar *object_path;
NMModem *modem;
if (g_strcmp0 (signal_name, "ModemAdded") == 0) {
g_variant_get (parameters, "(oa{sv})", &object_path, NULL);
nm_log_info (LOGD_MB, "oFono modem appeared: %s", object_path);
ofono_create_modem (NM_MODEM_MANAGER (user_data), object_path);
g_free (object_path);
} else if (g_strcmp0 (signal_name, "ModemRemoved") == 0) {
g_variant_get (parameters, "(o)", &object_path);
nm_log_info (LOGD_MB, "oFono modem removed: %s", object_path);
modem = (NMModem *) g_hash_table_lookup (self->priv->modems, object_path);
if (modem) {
nm_modem_emit_removed (modem);
g_hash_table_remove (self->priv->modems, object_path);
} else {
nm_log_warn (LOGD_MB, "could not remove modem %s, not found in table",
object_path);
}
g_free (object_path);
}
}
#define OFONO_DBUS_MODEM_ENTRY (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_OBJECT_PATH, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID))
#define OFONO_DBUS_MODEM_ENTRIES (dbus_g_type_get_collection ("GPtrArray", OFONO_DBUS_MODEM_ENTRY))
static void
ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
{
NMModemManager *manager = NM_MODEM_MANAGER (user_data);
GError *error = NULL;
GVariant *results;
GVariantIter *iter;
const char *path;
results = g_dbus_proxy_call_finish (proxy, res, &error);
if (results) {
g_variant_get (results, "(a(oa{sv}))", &iter);
while (g_variant_iter_loop (iter, "(&oa{sv})", &path, NULL)) {
ofono_create_modem (manager, path);
}
g_variant_iter_free (iter);
g_variant_unref (results);
}
if (error)
nm_log_warn (LOGD_MB, "failed to enumerate oFono devices: %s",
error->message ? error->message : "(unknown)");
}
static void ofono_appeared (NMModemManager *self);
static void
ofono_check_name_owner (NMModemManager *self)
{
gchar *name_owner;
name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (self->priv->ofono_proxy));
if (name_owner) {
/* Available! */
ofono_appeared (self);
goto free;
}
nm_log_info (LOGD_MB, "oFono disappeared from bus");
ofono_clear_signals (self);
g_clear_object (&self->priv->ofono_proxy);
ensure_client (self);
free:
g_free (name_owner);
return;
}
static void
ofono_name_owner_changed (GDBusProxy *ofono_proxy,
GParamSpec *pspec,
NMModemManager *self)
{
ofono_check_name_owner (self);
}
static void
ofono_appeared (NMModemManager *self)
{
nm_log_info (LOGD_MB, "ofono is now available");
self->priv->ofono_name_owner_changed_id =
g_signal_connect (self->priv->ofono_proxy,
"notify::name-owner",
G_CALLBACK (ofono_name_owner_changed),
self);
g_dbus_proxy_call (self->priv->ofono_proxy,
"GetModems",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) ofono_enumerate_devices_done,
g_object_ref (self));
g_signal_connect (self->priv->ofono_proxy,
"g-signal",
G_CALLBACK (ofono_signal_cb),
self);
}
static void
ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
NMModemManager *self = NM_MODEM_MANAGER (user_data);
GError *error = NULL;
self->priv->ofono_proxy = g_dbus_proxy_new_finish (res, &error);
if (error) {
//FIXME: do stuff if there's an error.
return;
}
ofono_appeared (self);
/* Balance refcount */
g_object_unref (self);
}
#endif
static void
modem_manager_poke_cb (GDBusConnection *connection,
@ -217,19 +399,18 @@ modem_manager_poke_cb (GDBusConnection *connection,
result = g_dbus_connection_call_finish (connection, res, &error);
if (error) {
/* Ignore common errors when MM is not installed and such */
if ( !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_EXEC_FAILED)
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FORK_FAILED)
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FAILED)
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMEOUT)
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) {
nm_log_dbg (LOGD_MB, "error poking ModemManager: %s", error->message);
}
g_error_free (error);
nm_log_warn (LOGD_MB, "error poking ModemManager: %s",
error ? error->message : "");
/* Setup timeout to relaunch */
schedule_modem_manager_relaunch (self, MODEM_POKE_INTERVAL);
/* Don't reschedule poke is MM service doesn't exist. */
if (!g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) {
/* Setup timeout to relaunch */
schedule_modem_manager_relaunch (self, MODEM_POKE_INTERVAL);
}
g_error_free (error);
} else
g_variant_unref (result);
@ -321,22 +502,44 @@ manager_new_ready (GObject *source,
static void
ensure_client (NMModemManager *self)
{
g_assert (self->priv->dbus_connection);
NMModemManagerPrivate *priv = self->priv;
gboolean created = FALSE;
g_assert (priv->dbus_connection);
/* Create the GDBusObjectManagerClient. We do not request to autostart, as
* we don't really want the MMManager creation to fail. We can always poke
* later on if we want to request the autostart */
if (!self->priv->modem_manager) {
mm_manager_new (self->priv->dbus_connection,
if (!priv->modem_manager) {
mm_manager_new (priv->dbus_connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
NULL,
(GAsyncReadyCallback)manager_new_ready,
g_object_ref (self));
return;
created = TRUE;
}
#if WITH_OFONO
if (!priv->ofono_proxy) {
g_dbus_proxy_new (priv->dbus_connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
NULL,
OFONO_DBUS_SERVICE,
OFONO_DBUS_PATH,
OFONO_DBUS_INTERFACE,
NULL,
(GAsyncReadyCallback) ofono_proxy_new_cb,
g_object_ref (self));
created = TRUE;
}
#endif /* WITH_OFONO */
if (created)
return;
/* If already available, recheck name owner! */
modem_manager_check_name_owner (self);
ofono_check_name_owner (self);
}
static void
@ -414,6 +617,12 @@ dispose (GObject *object)
nm_clear_g_source (&self->priv->mm_launch_id);
clear_modem_manager (self);
#if WITH_OFONO
ofono_clear_signals (self);
g_clear_object (&self->priv->ofono_proxy);
#endif
g_clear_object (&self->priv->dbus_connection);
if (self->priv->modems) {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,64 @@
/* -*- 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) 2013 - Canonical Ltd.
*/
#ifndef NM_MODEM_OFONO_H
#define NM_MODEM_OFONO_H
#include <nm-modem.h>
G_BEGIN_DECLS
#define NM_TYPE_MODEM_OFONO (nm_modem_ofono_get_type ())
#define NM_MODEM_OFONO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_OFONO, NMModemOfono))
#define NM_IS_MODEM_OFONO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_OFONO))
#define NM_MODEM_OFONO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MODEM_OFONO, NMModemOfonoClass))
#define NM_IS_MODEM_OFONO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_OFONO))
#define NM_MODEM_OFONO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_OFONO, NMModemOfonoClass))
#define NM_MODEM_OFONO_MODEM "modem"
#define OFONO_DBUS_SERVICE "org.ofono"
#define OFONO_DBUS_PATH "/"
#define OFONO_DBUS_INTERFACE "org.ofono.Manager"
#define OFONO_DBUS_INTERFACE_MODEM "org.ofono.Modem"
#define OFONO_DBUS_INTERFACE_CONNECTION_MANAGER "org.ofono.ConnectionManager"
#define OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT "org.ofono.ConnectionContext"
#define OFONO_DBUS_INTERFACE_SIM_MANAGER "org.ofono.SimManager"
typedef enum {
NM_OFONO_ERROR_CONNECTION_NOT_OFONO = 0, /*< nick=ConnectionNotOfono >*/
NM_OFONO_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/
NM_OFONO_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/
} NMOfonoError;
typedef struct {
NMModem parent;
} NMModemOfono;
typedef struct {
NMModemClass parent;
} NMModemOfonoClass;
GType nm_modem_ofono_get_type (void);
NMModem *nm_modem_ofono_new (const char *path);
G_END_DECLS
#endif /* NM_MODEM_OFONO_H */

View file

@ -202,7 +202,9 @@ nm_modem_set_mm_enabled (NMModem *self,
return;
}
NM_MODEM_GET_CLASS (self)->set_mm_enabled (self, enabled);
/* Not all modem classes support set_mm_enabled */
if (NM_MODEM_GET_CLASS (self)->set_mm_enabled)
NM_MODEM_GET_CLASS (self)->set_mm_enabled (self, enabled);
/* Pre-empt the state change signal */
nm_modem_set_state (self,
@ -573,6 +575,8 @@ nm_modem_stage3_ip4_config_start (NMModem *self,
const char *method;
NMActStageReturn ret;
nm_log_dbg (LOGD_MB, "ip4_config_start");
g_return_val_if_fail (NM_IS_MODEM (self), NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (NM_IS_DEVICE (device), NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (NM_IS_DEVICE_CLASS (device_class), NM_ACT_STAGE_RETURN_FAILURE);
@ -602,9 +606,11 @@ nm_modem_stage3_ip4_config_start (NMModem *self,
ret = ppp_stage3_ip_config_start (self, req, reason);
break;
case NM_MODEM_IP_METHOD_STATIC:
nm_log_dbg (LOGD_MB, "MODEM_IP_METHOD_STATIC");
ret = NM_MODEM_GET_CLASS (self)->static_stage3_ip4_config_start (self, req, reason);
break;
case NM_MODEM_IP_METHOD_AUTO:
nm_log_dbg (LOGD_MB, "MODEM_IP_METHOD_AUTO");
ret = device_class->act_stage3_ip4_config_start (device, NULL, reason);
break;
default:

View file

@ -2558,7 +2558,13 @@ _get_property_path (const char *ifname,
ipv6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR,
ifname,
property);
g_assert (len < sizeof (path) - 1);
/* Ubuntu: don't assert, but log about the inconsistent size. */
if (len > sizeof (path) - 1)
nm_log_warn (LOGD_CORE,
"IPv6 property path is too long: '"
IPV6_PROPERTY_DIR "%s/%s'",
ifname, property);
return path;
}
@ -2622,9 +2628,15 @@ NM_ASSERT_VALID_PATH_COMPONENT (const char *name)
nm_log_err (LOGD_CORE, "Failed asserting path component: %s%s%s",
NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)"));
g_error ("FATAL: Failed asserting path component: %s%s%s",
NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)"));
g_assert_not_reached ();
/* Ubuntu: Don't outright fail, just return the name again. It's
* logged as being invalid, which is enough.
* There is a use of slashes in paths for oFono modems, which are
* actually valid paths to refer to an oFono modem, just don't map to
* anything on the filesystem. The following calls to sysctl paths can
* (and will) fail, but that's fine.
*/
return name;
}
gboolean