aboutsummaryrefslogtreecommitdiff
path: root/src/mm-base-bearer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mm-base-bearer.c')
-rw-r--r--src/mm-base-bearer.c83
1 files changed, 51 insertions, 32 deletions
diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c
index 52e8db02..7dadfff0 100644
--- a/src/mm-base-bearer.c
+++ b/src/mm-base-bearer.c
@@ -41,6 +41,8 @@
#include "mm-error-helpers.h"
#include "mm-bearer-stats.h"
#include "mm-dispatcher-connection.h"
+#include "mm-auth-provider.h"
+#include "mm-bind.h"
/* We require up to 20s to get a proper IP when using PPP */
#define BEARER_IP_TIMEOUT_DEFAULT 20
@@ -54,9 +56,11 @@
#define BEARER_CONNECTION_MONITOR_TIMEOUT 5
static void log_object_iface_init (MMLogObjectInterface *iface);
+static void bind_iface_init (MMBindInterface *iface);
G_DEFINE_TYPE_EXTENDED (MMBaseBearer, mm_base_bearer, MM_GDBUS_TYPE_BEARER_SKELETON, 0,
- G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init))
+ G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_BIND, bind_iface_init))
typedef enum {
CONNECTION_FORBIDDEN_REASON_NONE,
@@ -70,6 +74,7 @@ enum {
PROP_0,
PROP_PATH,
PROP_CONNECTION,
+ PROP_BIND_TO,
PROP_MODEM,
PROP_STATUS,
PROP_CONFIG,
@@ -83,6 +88,13 @@ struct _MMBaseBearerPrivate {
GDBusConnection *connection;
guint dbus_id;
+ /* The authorization provider */
+ MMAuthProvider *authp;
+ GCancellable *authp_cancellable;
+
+ /* The object this bearer is bound to */
+ GObject *bind_to;
+
/* The modem which owns this BEARER */
MMBaseModem *modem;
/* The path where the BEARER object is exported */
@@ -1118,7 +1130,6 @@ mm_base_bearer_connect (MMBaseBearer *self,
typedef struct {
MMBaseBearer *self;
- MMBaseModem *modem;
GDBusMethodInvocation *invocation;
} HandleConnectContext;
@@ -1126,7 +1137,6 @@ static void
handle_connect_context_free (HandleConnectContext *ctx)
{
g_object_unref (ctx->invocation);
- g_object_unref (ctx->modem);
g_object_unref (ctx->self);
g_free (ctx);
}
@@ -1147,13 +1157,13 @@ handle_connect_ready (MMBaseBearer *self,
}
static void
-handle_connect_auth_ready (MMBaseModem *modem,
+handle_connect_auth_ready (MMAuthProvider *authp,
GAsyncResult *res,
HandleConnectContext *ctx)
{
GError *error = NULL;
- if (!mm_base_modem_authorize_finish (modem, res, &error)) {
+ if (!mm_auth_provider_authorize_finish (authp, res, &error)) {
mm_dbus_method_invocation_take_error (ctx->invocation, error);
handle_connect_context_free (ctx);
return;
@@ -1174,15 +1184,13 @@ handle_connect (MMBaseBearer *self,
ctx = g_new0 (HandleConnectContext, 1);
ctx->self = g_object_ref (self);
ctx->invocation = g_object_ref (invocation);
- g_object_get (self,
- MM_BASE_BEARER_MODEM, &ctx->modem,
- NULL);
- mm_base_modem_authorize (ctx->modem,
- invocation,
- MM_AUTHORIZATION_DEVICE_CONTROL,
- (GAsyncReadyCallback)handle_connect_auth_ready,
- ctx);
+ mm_auth_provider_authorize (self->priv->authp,
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ self->priv->authp_cancellable,
+ (GAsyncReadyCallback)handle_connect_auth_ready,
+ ctx);
return TRUE;
}
@@ -1307,7 +1315,6 @@ mm_base_bearer_disconnect (MMBaseBearer *self,
typedef struct {
MMBaseBearer *self;
- MMBaseModem *modem;
GDBusMethodInvocation *invocation;
} HandleDisconnectContext;
@@ -1315,7 +1322,6 @@ static void
handle_disconnect_context_free (HandleDisconnectContext *ctx)
{
g_object_unref (ctx->invocation);
- g_object_unref (ctx->modem);
g_object_unref (ctx->self);
g_free (ctx);
}
@@ -1336,13 +1342,13 @@ handle_disconnect_ready (MMBaseBearer *self,
}
static void
-handle_disconnect_auth_ready (MMBaseModem *modem,
+handle_disconnect_auth_ready (MMAuthProvider *authp,
GAsyncResult *res,
HandleDisconnectContext *ctx)
{
GError *error = NULL;
- if (!mm_base_modem_authorize_finish (modem, res, &error)) {
+ if (!mm_auth_provider_authorize_finish (authp, res, &error)) {
mm_dbus_method_invocation_take_error (ctx->invocation, error);
handle_disconnect_context_free (ctx);
return;
@@ -1363,15 +1369,13 @@ handle_disconnect (MMBaseBearer *self,
ctx = g_new0 (HandleDisconnectContext, 1);
ctx->self = g_object_ref (self);
ctx->invocation = g_object_ref (invocation);
- g_object_get (self,
- MM_BASE_BEARER_MODEM, &ctx->modem,
- NULL);
- mm_base_modem_authorize (ctx->modem,
- invocation,
- MM_AUTHORIZATION_DEVICE_CONTROL,
- (GAsyncReadyCallback)handle_disconnect_auth_ready,
- ctx);
+ mm_auth_provider_authorize (self->priv->authp,
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ self->priv->authp_cancellable,
+ (GAsyncReadyCallback)handle_disconnect_auth_ready,
+ ctx);
return TRUE;
}
@@ -1747,17 +1751,15 @@ set_property (GObject *object,
else if (self->priv->path)
base_bearer_dbus_export (self);
break;
+ case PROP_BIND_TO:
+ g_clear_object (&self->priv->bind_to);
+ self->priv->bind_to = g_value_dup_object (value);
+ mm_bind_to (MM_BIND (self), MM_BASE_BEARER_CONNECTION, self->priv->bind_to);
+ break;
case PROP_MODEM:
g_clear_object (&self->priv->modem);
self->priv->modem = g_value_dup_object (value);
if (self->priv->modem) {
- /* Set owner ID */
- mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem)));
- /* Bind the modem's connection (which is set when it is exported,
- * and unset when unexported) to the BEARER's connection */
- g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION,
- self, MM_BASE_BEARER_CONNECTION,
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
if (self->priv->config) {
/* Listen to 3GPP/CDMA registration state changes. We need both
* 'config' and 'modem' set. */
@@ -1807,6 +1809,9 @@ get_property (GObject *object,
case PROP_CONNECTION:
g_value_set_object (value, self->priv->connection);
break;
+ case PROP_BIND_TO:
+ g_value_set_object (value, self->priv->bind_to);
+ break;
case PROP_MODEM:
g_value_set_object (value, self->priv->modem);
break;
@@ -1835,6 +1840,10 @@ mm_base_bearer_init (MMBaseBearer *self)
/* Each bearer is given a unique id to build its own DBus path */
self->priv->dbus_id = id++;
+ /* Setup authorization provider */
+ self->priv->authp = mm_auth_provider_get ();
+ self->priv->authp_cancellable = g_cancellable_new ();
+
self->priv->status = MM_BEARER_STATUS_DISCONNECTED;
self->priv->reason_3gpp = CONNECTION_FORBIDDEN_REASON_NONE;
self->priv->reason_cdma = CONNECTION_FORBIDDEN_REASON_NONE;
@@ -1885,7 +1894,10 @@ dispose (GObject *object)
reset_deferred_unregistration (self);
g_clear_object (&self->priv->modem);
+ g_clear_object (&self->priv->bind_to);
g_clear_object (&self->priv->config);
+ g_cancellable_cancel (self->priv->authp_cancellable);
+ g_clear_object (&self->priv->authp_cancellable);
G_OBJECT_CLASS (mm_base_bearer_parent_class)->dispose (object);
}
@@ -1897,6 +1909,11 @@ log_object_iface_init (MMLogObjectInterface *iface)
}
static void
+bind_iface_init (MMBindInterface *iface)
+{
+}
+
+static void
mm_base_bearer_class_init (MMBaseBearerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -1927,6 +1944,8 @@ mm_base_bearer_class_init (MMBaseBearerClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PATH, properties[PROP_PATH]);
+ g_object_class_override_property (object_class, PROP_BIND_TO, MM_BIND_TO);
+
properties[PROP_MODEM] =
g_param_spec_object (MM_BASE_BEARER_MODEM,
"Modem",