From ebe07af30e7ac9018c6273bb71457d3c59087eb8 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 6 May 2016 10:17:06 +0200 Subject: [PATCH 3/4] mbm: move the disconnect handling upwards The E2NAP handling is in report_connection_status(). We'll need that for disconnect too. --- plugins/mbm/mm-broadband-bearer-mbm.c | 162 +++++++++++++++++----------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/plugins/mbm/mm-broadband-bearer-mbm.c b/plugins/mbm/mm-broadband-bearer-mbm.c index be8e559..5d97fee 100644 --- a/plugins/mbm/mm-broadband-bearer-mbm.c +++ b/plugins/mbm/mm-broadband-bearer-mbm.c @@ -51,6 +51,87 @@ struct _MMBroadbandBearerMbmPrivate { }; /*****************************************************************************/ +/* 3GPP disconnect */ + +typedef struct { + MMBroadbandBearerMbm *self; + MMBaseModem *modem; + MMPortSerialAt *primary; + GSimpleAsyncResult *result; +} DisconnectContext; + +static void +disconnect_context_complete_and_free (DisconnectContext *ctx) +{ + g_simple_async_result_complete (ctx->result); + g_object_unref (ctx->result); + g_object_unref (ctx->primary); + g_object_unref (ctx->self); + g_object_unref (ctx->modem); + g_free (ctx); +} + +static gboolean +disconnect_3gpp_finish (MMBroadbandBearer *self, + GAsyncResult *res, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + +static void +disconnect_enap_ready (MMBaseModem *modem, + GAsyncResult *res, + DisconnectContext *ctx) +{ + GError *error = NULL; + + /* Ignore errors for now */ + mm_base_modem_at_command_full_finish (modem, res, &error); + if (error) { + mm_dbg ("Disconnection failed (not fatal): %s", error->message); + g_error_free (error); + } + + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + disconnect_context_complete_and_free (ctx); +} + +static void +disconnect_3gpp (MMBroadbandBearer *self, + MMBroadbandModem *modem, + MMPortSerialAt *primary, + MMPortSerialAt *secondary, + MMPort *data, + guint cid, + GAsyncReadyCallback callback, + gpointer user_data) +{ + DisconnectContext *ctx; + + g_assert (primary != NULL); + + ctx = g_new0 (DisconnectContext, 1); + ctx->self = g_object_ref (self); + ctx->modem = MM_BASE_MODEM (g_object_ref (modem)); + ctx->primary = g_object_ref (primary); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + disconnect_3gpp); + + mm_base_modem_at_command_full (MM_BASE_MODEM (modem), + primary, + "*ENAP=0", + 3, + FALSE, + FALSE, /* raw */ + NULL, /* cancellable */ + (GAsyncReadyCallback)disconnect_enap_ready, + ctx); +} + +/*****************************************************************************/ /* 3GPP Dialing (sub-step of the 3GPP Connection sequence) */ typedef struct { @@ -630,87 +711,6 @@ get_ip_config_3gpp (MMBroadbandBearer *self, } /*****************************************************************************/ -/* 3GPP disconnect */ - -typedef struct { - MMBroadbandBearerMbm *self; - MMBaseModem *modem; - MMPortSerialAt *primary; - GSimpleAsyncResult *result; -} DisconnectContext; - -static void -disconnect_context_complete_and_free (DisconnectContext *ctx) -{ - g_simple_async_result_complete (ctx->result); - g_object_unref (ctx->result); - g_object_unref (ctx->primary); - g_object_unref (ctx->self); - g_object_unref (ctx->modem); - g_free (ctx); -} - -static gboolean -disconnect_3gpp_finish (MMBroadbandBearer *self, - GAsyncResult *res, - GError **error) -{ - return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); -} - -static void -disconnect_enap_ready (MMBaseModem *modem, - GAsyncResult *res, - DisconnectContext *ctx) -{ - GError *error = NULL; - - /* Ignore errors for now */ - mm_base_modem_at_command_full_finish (modem, res, &error); - if (error) { - mm_dbg ("Disconnection failed (not fatal): %s", error->message); - g_error_free (error); - } - - g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); - disconnect_context_complete_and_free (ctx); -} - -static void -disconnect_3gpp (MMBroadbandBearer *self, - MMBroadbandModem *modem, - MMPortSerialAt *primary, - MMPortSerialAt *secondary, - MMPort *data, - guint cid, - GAsyncReadyCallback callback, - gpointer user_data) -{ - DisconnectContext *ctx; - - g_assert (primary != NULL); - - ctx = g_new0 (DisconnectContext, 1); - ctx->self = g_object_ref (self); - ctx->modem = MM_BASE_MODEM (g_object_ref (modem)); - ctx->primary = g_object_ref (primary); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - disconnect_3gpp); - - mm_base_modem_at_command_full (MM_BASE_MODEM (modem), - primary, - "*ENAP=0", - 3, - FALSE, - FALSE, /* raw */ - NULL, /* cancellable */ - (GAsyncReadyCallback)disconnect_enap_ready, - ctx); -} - -/*****************************************************************************/ MMBaseBearer * mm_broadband_bearer_mbm_new_finish (GAsyncResult *res, -- 2.5.5