aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-12-27 12:11:09 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:38 +0100
commit10a4360d83488c29abaf525ed22da20b937c9a78 (patch)
treeeca76b560f9b944d988d6578a2a2a4df40ab7ff4 /src
parent6cdc6a4f731b0b9afe959bc10bc7386ff6735607 (diff)
bearer: provide reason of why connection is forbidden
Diffstat (limited to 'src')
-rw-r--r--src/mm-bearer.c67
-rw-r--r--src/mm-bearer.h19
-rw-r--r--src/mm-iface-modem-3gpp.c48
3 files changed, 87 insertions, 47 deletions
diff --git a/src/mm-bearer.c b/src/mm-bearer.c
index d2b1caf1..b7ab9a72 100644
--- a/src/mm-bearer.c
+++ b/src/mm-bearer.c
@@ -41,7 +41,7 @@ enum {
PROP_PATH,
PROP_CONNECTION,
PROP_MODEM,
- PROP_CONNECTION_ALLOWED,
+ PROP_CONNECTION_FORBIDDEN_REASON,
PROP_STATUS,
PROP_LAST
};
@@ -55,8 +55,8 @@ struct _MMBearerPrivate {
MMBaseModem *modem;
/* The path where the BEARER object is exported */
gchar *path;
- /* Flag to specify whether the bearer can be connected */
- gboolean connection_allowed;
+ /* Reason for not allowing connection */
+ MMBearerConnectionForbiddenReason connection_forbidden_reason;
/* Status of this bearer */
MMBearerStatus status;
@@ -150,12 +150,21 @@ handle_connect (MMBearer *self,
g_assert (MM_BEARER_GET_CLASS (self)->connect_finish != NULL);
/* Bearer may not be allowed to connect yet */
- if (!self->priv->connection_allowed) {
+ if (self->priv->connection_forbidden_reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE) {
+ GEnumClass *enum_class;
+ GEnumValue *value;
+
+ enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_BEARER_CONNECTION_FORBIDDEN_REASON));
+ value = g_enum_get_value (enum_class, self->priv->connection_forbidden_reason);
+
g_dbus_method_invocation_return_error (
invocation,
MM_CORE_ERROR,
- MM_CORE_ERROR_WRONG_STATE,
- "Not allowed to connect bearer");
+ MM_CORE_ERROR_UNAUTHORIZED,
+ "Not allowed to connect bearer: %s",
+ value->value_nick);
+
+ g_type_class_unref (enum_class);
return TRUE;
}
@@ -403,11 +412,11 @@ mm_bearer_get_path (MMBearer *self)
void
mm_bearer_set_connection_allowed (MMBearer *self)
{
- if (self->priv->connection_allowed)
+ if (self->priv->connection_forbidden_reason == MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE)
return;
mm_dbg ("Connection in bearer '%s' is allowed", self->priv->path);
- self->priv->connection_allowed = TRUE;
+ self->priv->connection_forbidden_reason = MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE;
}
static void
@@ -431,13 +440,21 @@ disconnect_after_forbidden_ready (MMBearer *self,
}
void
-mm_bearer_set_connection_forbidden (MMBearer *self)
+mm_bearer_set_connection_forbidden (MMBearer *self,
+ MMBearerConnectionForbiddenReason reason)
{
- if (!self->priv->connection_allowed)
- return;
+ GEnumClass *enum_class;
+ GEnumValue *value;
+
+ g_assert (reason != MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE);
- mm_dbg ("Connection in bearer '%s' is forbidden", self->priv->path);
- self->priv->connection_allowed = FALSE;
+ self->priv->connection_forbidden_reason = reason;
+ enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_BEARER_CONNECTION_FORBIDDEN_REASON));
+ value = g_enum_get_value (enum_class, self->priv->connection_forbidden_reason);
+ mm_dbg ("Connection in bearer '%s' is forbidden: '%s'",
+ self->priv->path,
+ value->value_nick);
+ g_type_class_unref (enum_class);
if (self->priv->status == MM_BEARER_STATUS_DISCONNECTING ||
self->priv->status == MM_BEARER_STATUS_DISCONNECTED) {
@@ -535,8 +552,8 @@ set_property (GObject *object,
self, MM_BEARER_CONNECTION,
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
break;
- case PROP_CONNECTION_ALLOWED:
- self->priv->connection_allowed = g_value_get_boolean (value);
+ case PROP_CONNECTION_FORBIDDEN_REASON:
+ self->priv->connection_forbidden_reason = g_value_get_enum (value);
break;
case PROP_STATUS:
self->priv->status = g_value_get_enum (value);
@@ -565,8 +582,8 @@ get_property (GObject *object,
case PROP_MODEM:
g_value_set_object (value, self->priv->modem);
break;
- case PROP_CONNECTION_ALLOWED:
- g_value_set_boolean (value, self->priv->connection_allowed);
+ case PROP_CONNECTION_FORBIDDEN_REASON:
+ g_value_set_enum (value, self->priv->connection_forbidden_reason);
break;
case PROP_STATUS:
g_value_set_enum (value, self->priv->status);
@@ -585,6 +602,7 @@ mm_bearer_init (MMBearer *self)
MM_TYPE_BEARER,
MMBearerPrivate);
self->priv->status = MM_BEARER_STATUS_DISCONNECTED;
+ self->priv->connection_forbidden_reason = MM_BEARER_CONNECTION_FORBIDDEN_REASON_UNREGISTERED;
/* Set defaults */
mm_gdbus_bearer_set_interface (MM_GDBUS_BEARER (self), NULL);
@@ -658,13 +676,14 @@ mm_bearer_class_init (MMBearerClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_MODEM, properties[PROP_MODEM]);
- properties[PROP_CONNECTION_ALLOWED] =
- g_param_spec_boolean (MM_BEARER_CONNECTION_ALLOWED,
- "Connection allowed",
- "Flag to specify whether the bearer is allowed to get connected",
- FALSE,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONNECTION_ALLOWED, properties[PROP_CONNECTION_ALLOWED]);
+ properties[PROP_CONNECTION_FORBIDDEN_REASON] =
+ g_param_spec_enum (MM_BEARER_CONNECTION_FORBIDDEN_REASON,
+ "Connection forbidden reason",
+ "Reason to specify why the connection in the bearer is forbidden",
+ MM_TYPE_BEARER_CONNECTION_FORBIDDEN_REASON,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_UNREGISTERED,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_CONNECTION_FORBIDDEN_REASON, properties[PROP_CONNECTION_FORBIDDEN_REASON]);
properties[PROP_STATUS] =
g_param_spec_enum (MM_BEARER_STATUS,
diff --git a/src/mm-bearer.h b/src/mm-bearer.h
index 95266ad8..36c09fe0 100644
--- a/src/mm-bearer.h
+++ b/src/mm-bearer.h
@@ -35,11 +35,11 @@ typedef struct _MMBearer MMBearer;
typedef struct _MMBearerClass MMBearerClass;
typedef struct _MMBearerPrivate MMBearerPrivate;
-#define MM_BEARER_PATH "bearer-path"
-#define MM_BEARER_CONNECTION "bearer-connection"
-#define MM_BEARER_MODEM "bearer-modem"
-#define MM_BEARER_CONNECTION_ALLOWED "bearer-connection-allowed"
-#define MM_BEARER_STATUS "bearer-status"
+#define MM_BEARER_PATH "bearer-path"
+#define MM_BEARER_CONNECTION "bearer-connection"
+#define MM_BEARER_MODEM "bearer-modem"
+#define MM_BEARER_CONNECTION_FORBIDDEN_REASON "bearer-connection-forbidden-reason"
+#define MM_BEARER_STATUS "bearer-status"
/* Prefix for all bearer object paths */
#define MM_DBUS_BEARER_PREFIX MM_DBUS_PATH "/Bearers"
@@ -51,6 +51,12 @@ typedef enum { /*< underscore_name=mm_bearer_status >*/
MM_BEARER_STATUS_CONNECTED,
} MMBearerStatus;
+typedef enum { /*< underscore_name=mm_bearer_connection_forbidden_reason >*/
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_NONE,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_UNREGISTERED,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_ROAMING,
+} MMBearerConnectionForbiddenReason;
+
struct _MMBearer {
MmGdbusBearerSkeleton parent;
MMBearerPrivate *priv;
@@ -87,7 +93,8 @@ void mm_bearer_expose_properties (MMBearer *bearer,
...);
void mm_bearer_set_connection_allowed (MMBearer *bearer);
-void mm_bearer_set_connection_forbidden (MMBearer *bearer);
+void mm_bearer_set_connection_forbidden (MMBearer *bearer,
+ MMBearerConnectionForbiddenReason reason);
MMBearerStatus mm_bearer_get_status (MMBearer *bearer);
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c
index 569856af..673d88e2 100644
--- a/src/mm-iface-modem-3gpp.c
+++ b/src/mm-iface-modem-3gpp.c
@@ -325,31 +325,39 @@ mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
gboolean allow_roaming)
{
MMModem3gppRegistrationState current_state;
- MMBearer3gpp *bearer;
+ MMBearer *bearer;
g_assert (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer != NULL);
/* Create new 3GPP bearer using the method set in the interface, so that
* plugins can subclass it and implement their own. */
- bearer = MM_BEARER_3GPP (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->
- create_3gpp_bearer (MM_BASE_MODEM (self),
- apn,
- ip_type,
- allow_roaming));
+ bearer = MM_BEARER (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->
+ create_3gpp_bearer (MM_BASE_MODEM (self),
+ apn,
+ ip_type,
+ allow_roaming));
g_object_get (self,
MM_IFACE_MODEM_3GPP_REGISTRATION_STATE, &current_state,
NULL);
/* Don't allow bearer to get connected if roaming forbidden */
- if (current_state == MM_MODEM_3GPP_REGISTRATION_STATE_HOME ||
- (current_state == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING &&
- mm_bearer_3gpp_get_allow_roaming (bearer)))
- mm_bearer_set_connection_allowed (MM_BEARER (bearer));
+ if (current_state == MM_MODEM_3GPP_REGISTRATION_STATE_HOME)
+ mm_bearer_set_connection_allowed (bearer);
+ else if (current_state == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) {
+ if (mm_bearer_3gpp_get_allow_roaming (MM_BEARER_3GPP (bearer)))
+ mm_bearer_set_connection_allowed (bearer);
+ else
+ mm_bearer_set_connection_forbidden (
+ bearer,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_ROAMING);
+ }
else
- mm_bearer_set_connection_forbidden (MM_BEARER (bearer));
+ mm_bearer_set_connection_forbidden (
+ bearer,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_UNREGISTERED);
- return MM_BEARER (bearer);
+ return bearer;
}
MMBearer *
@@ -546,10 +554,14 @@ set_bearer_3gpp_connection_allowed (MMBearer *bearer,
const gboolean *roaming_network)
{
/* Don't allow bearer to get connected if roaming forbidden */
- if (MM_IS_BEARER_3GPP (bearer) &&
- (!*roaming_network ||
- mm_bearer_3gpp_get_allow_roaming (MM_BEARER_3GPP (bearer))))
- mm_bearer_set_connection_allowed (bearer);
+ if (MM_IS_BEARER_3GPP (bearer)) {
+ if (!*roaming_network ||
+ mm_bearer_3gpp_get_allow_roaming (MM_BEARER_3GPP (bearer)))
+ mm_bearer_set_connection_allowed (bearer);
+ else
+ mm_bearer_set_connection_forbidden (bearer,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_ROAMING);
+ }
}
static void
@@ -575,7 +587,9 @@ static void
set_bearer_3gpp_connection_forbidden (MMBearer *bearer)
{
if (MM_IS_BEARER_3GPP (bearer))
- mm_bearer_set_connection_forbidden (bearer);
+ mm_bearer_set_connection_forbidden (
+ bearer,
+ MM_BEARER_CONNECTION_FORBIDDEN_REASON_UNREGISTERED);
}
static void