aboutsummaryrefslogtreecommitdiff
path: root/plugins/mbm
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-09-20 19:29:37 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-09-23 08:29:15 +0200
commitd818d9fe065b4baac979abf5c45e0d212ccf908d (patch)
treecc466e584d3adf818663eef47f94044a0fde18d8 /plugins/mbm
parent6b4602a3356e779389ef97bac0b8461e6d26fc41 (diff)
bearer: consolidate unsolicited connection status reports
Originally developed by: Ben Chan <benchan@chromium.org> This patch replaces mm_bearer_report_disconnection() with a more generic mm_bearer_report_connection_status(), which allows reporting any connection status of a bearer. This further allows getting rid of those custom report_connection_status functions in plugic specific bearer subclasses. Note that while plugin-specific implementations can receive multiple 'MMBearerConnectionStatus' values, the generic implementation is only allowed to receive DISCONNECTED. Plugins need to make sure that they process all the other status values, and only report DISCONNECTED to the parent when required. MBM: The MBM bearer implementation of report_connection_status() expects either CONNECTED or DISCONNECTED. If any of these is received and there is an ongoing connection attempt, the corresponding operation will be completed. If there is no connection attempt, we will just handle the DISCONNECTED state, calling the parent method to notify that the modem got network-disconnected. Icera: The Icera bearer implementation of report_connection_status() expects either CONNECTED, CONNECT FAILED or DISCONNECTED. If any of these is received and there is an ongoing connection or disconnection attempt, the corresponding operation will be completed. If there is no connection or disconnection attempt, we will just handle the CONNECT FAILED and DISCONNECTED states, calling the parent method (always with DISCONNECTED) to notify that the modem got network-disconnected. Option/HSO: The Option/HSO bearer implementation of report_connection_status() expects either CONNECTED, CONNECTION FAILED or DISCONNECTED. If any of these is received and there is an ongoing connection or disconnection attempt, the corresponding operation will be completed. If there is no connection or disconnection attempt, we will just handle the CONNECTION FAILED and DISCONNECTED states, calling the parent method (always with DISCONNECTED) to notify that the modem got network-disconnected. Huawei: The Huawei bearer implementation of report_connection_status() expects either CONNECTED or DISCONNECTED. These messages are not used to process pending connection or disconnection attempts; so if they are received while one of these is on-going, it will just be ignored. CONNECTED reports are also ignored, so we will just handle the DISCONNECTED state, calling the parent method to notify that the modem got network-disconnected. Altair-LTE: The Altair-LTE bearers will only report DISCONNECTED on network-disconnected cases. There is no custom report_connection_status(). Novatel-LTE: The Novatel-LTE bearers will only report DISCONNECTED on network-disconnected cases. There is no custom report_connection_status().
Diffstat (limited to 'plugins/mbm')
-rw-r--r--plugins/mbm/mm-broadband-bearer-mbm.c63
-rw-r--r--plugins/mbm/mm-broadband-bearer-mbm.h9
-rw-r--r--plugins/mbm/mm-broadband-modem-mbm.c13
3 files changed, 43 insertions, 42 deletions
diff --git a/plugins/mbm/mm-broadband-bearer-mbm.c b/plugins/mbm/mm-broadband-bearer-mbm.c
index e4f9983c..c7495ce4 100644
--- a/plugins/mbm/mm-broadband-bearer-mbm.c
+++ b/plugins/mbm/mm-broadband-bearer-mbm.c
@@ -39,6 +39,7 @@
#include "mm-broadband-bearer-mbm.h"
#include "mm-log.h"
#include "mm-modem-helpers.h"
+#include "mm-daemon-enums-types.h"
G_DEFINE_TYPE (MMBroadbandBearerMbm, mm_broadband_bearer_mbm, MM_TYPE_BROADBAND_BEARER);
@@ -114,55 +115,63 @@ dial_3gpp_finish (MMBroadbandBearer *self,
return MM_PORT (g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))));
}
-void
-mm_broadband_bearer_mbm_report_connection_status (MMBroadbandBearerMbm *self,
- MMBroadbandBearerMbmConnectionStatus status)
+static void
+report_connection_status (MMBearer *bearer,
+ MMBearerConnectionStatus status)
{
+ MMBroadbandBearerMbm *self = MM_BROADBAND_BEARER_MBM (bearer);
Dial3gppContext *ctx;
+ g_assert (status == MM_BEARER_CONNECTION_STATUS_CONNECTED ||
+ status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED);
+
/* Recover context (if any) and remove both cancellation and timeout (if any)*/
ctx = self->priv->connect_pending;
self->priv->connect_pending = NULL;
+ /* Connection status reported but no connection attempt? */
+ if (!ctx) {
+ g_assert (self->priv->connect_pending_id == 0);
+
+ mm_dbg ("Received spontaneous *E2NAP (%s)",
+ mm_bearer_connection_status_get_string (status));
+
+ if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED) {
+ /* If no connection attempt on-going, make sure we mark ourselves as
+ * disconnected */
+ MM_BEARER_CLASS (mm_broadband_bearer_mbm_parent_class)->report_connection_status (
+ bearer,
+ status);
+ }
+ return;
+ }
+
if (self->priv->connect_pending_id) {
g_source_remove (self->priv->connect_pending_id);
self->priv->connect_pending_id = 0;
}
- if (ctx && self->priv->connect_cancellable_id) {
+ if (self->priv->connect_cancellable_id) {
g_cancellable_disconnect (ctx->cancellable,
self->priv->connect_cancellable_id);
self->priv->connect_cancellable_id = 0;
}
- switch (status) {
- case MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_UNKNOWN:
- g_warn_if_reached ();
- break;
-
- case MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_CONNECTED:
- if (!ctx)
- break;
-
+ /* Reporting connected */
+ if (status == MM_BEARER_CONNECTION_STATUS_CONNECTED) {
g_simple_async_result_set_op_res_gpointer (ctx->result,
g_object_ref (ctx->data),
(GDestroyNotify)g_object_unref);
dial_3gpp_context_complete_and_free (ctx);
return;
-
- case MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_DISCONNECTED:
- if (ctx) {
- g_simple_async_result_set_error (ctx->result,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Call setup failed");
- dial_3gpp_context_complete_and_free (ctx);
- } else {
- /* Just ensure we mark ourselves as being disconnected... */
- mm_bearer_report_disconnection (MM_BEARER (self));
- }
- break;
}
+
+ /* Reporting disconnected */
+ g_simple_async_result_set_error (ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Call setup failed");
+ dial_3gpp_context_complete_and_free (ctx);
}
static void
@@ -591,10 +600,12 @@ mm_broadband_bearer_mbm_class_init (MMBroadbandBearerMbmClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MMBearerClass *bearer_class = MM_BEARER_CLASS (klass);
MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMBroadbandBearerMbmPrivate));
+ bearer_class->report_connection_status = report_connection_status;
broadband_bearer_class->dial_3gpp = dial_3gpp;
broadband_bearer_class->dial_3gpp_finish = dial_3gpp_finish;
broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;
diff --git a/plugins/mbm/mm-broadband-bearer-mbm.h b/plugins/mbm/mm-broadband-bearer-mbm.h
index dcbeeecf..a49cce1e 100644
--- a/plugins/mbm/mm-broadband-bearer-mbm.h
+++ b/plugins/mbm/mm-broadband-bearer-mbm.h
@@ -41,12 +41,6 @@
#define MM_IS_BROADBAND_BEARER_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_MBM))
#define MM_BROADBAND_BEARER_MBM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_MBM, MMBroadbandBearerMbmClass))
-typedef enum {
- MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_UNKNOWN,
- MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_CONNECTED,
- MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_DISCONNECTED
-} MMBroadbandBearerMbmConnectionStatus;
-
typedef struct _MMBroadbandBearerMbm MMBroadbandBearerMbm;
typedef struct _MMBroadbandBearerMbmClass MMBroadbandBearerMbmClass;
typedef struct _MMBroadbandBearerMbmPrivate MMBroadbandBearerMbmPrivate;
@@ -71,7 +65,4 @@ void mm_broadband_bearer_mbm_new (MMBroadbandModemMbm *modem,
MMBearer *mm_broadband_bearer_mbm_new_finish (GAsyncResult *res,
GError **error);
-void mm_broadband_bearer_mbm_report_connection_status (MMBroadbandBearerMbm *self,
- MMBroadbandBearerMbmConnectionStatus status);
-
#endif /* MM_BROADBAND_BEARER_MBM_H */
diff --git a/plugins/mbm/mm-broadband-modem-mbm.c b/plugins/mbm/mm-broadband-modem-mbm.c
index 8380813e..5259359a 100644
--- a/plugins/mbm/mm-broadband-modem-mbm.c
+++ b/plugins/mbm/mm-broadband-modem-mbm.c
@@ -797,15 +797,14 @@ load_unlock_retries (MMIfaceModem *self,
/* Setup/Cleanup unsolicited events (3GPP interface) */
typedef struct {
- MMBroadbandBearerMbmConnectionStatus status;
+ MMBearerConnectionStatus status;
} BearerListReportStatusForeachContext;
static void
bearer_list_report_status_foreach (MMBearer *bearer,
BearerListReportStatusForeachContext *ctx)
{
- mm_broadband_bearer_mbm_report_connection_status (MM_BROADBAND_BEARER_MBM (bearer),
- ctx->status);
+ mm_bearer_report_connection_status (bearer, ctx->status);
}
static void
@@ -820,16 +819,16 @@ e2nap_received (MMAtSerialPort *port,
if (!mm_get_uint_from_match_info (info, 1, &state))
return;
- ctx.status = MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_UNKNOWN;
+ ctx.status = MM_BEARER_CONNECTION_STATUS_UNKNOWN;
switch (state) {
case MBM_E2NAP_DISCONNECTED:
mm_dbg ("disconnected");
- ctx.status = MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_DISCONNECTED;
+ ctx.status = MM_BEARER_CONNECTION_STATUS_DISCONNECTED;
break;
case MBM_E2NAP_CONNECTED:
mm_dbg ("connected");
- ctx.status = MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_CONNECTED;
+ ctx.status = MM_BEARER_CONNECTION_STATUS_CONNECTED;
break;
case MBM_E2NAP_CONNECTING:
mm_dbg ("connecting");
@@ -840,7 +839,7 @@ e2nap_received (MMAtSerialPort *port,
}
/* If unknown status, don't try to report anything */
- if (ctx.status == MM_BROADBAND_BEARER_MBM_CONNECTION_STATUS_UNKNOWN)
+ if (ctx.status == MM_BEARER_CONNECTION_STATUS_UNKNOWN)
return;
/* If empty bearer list, nothing else to do */