cinterion: rework 3GPP disconnection sequence
Group together all disconnection related logic (e.g. context) and define the context steps directly within the disconnection sequence processing.
This commit is contained in:
@@ -107,12 +107,6 @@ typedef enum {
|
|||||||
CONNECT_3GPP_CONTEXT_STEP_FINALIZE_BEARER,
|
CONNECT_3GPP_CONTEXT_STEP_FINALIZE_BEARER,
|
||||||
} Connect3gppContextStep;
|
} Connect3gppContextStep;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
DISCONNECT_3GPP_CONTEXT_STEP_STOP_SWWAN = 0,
|
|
||||||
DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS,
|
|
||||||
DISCONNECT_3GPP_CONTEXT_STEP_FINISH,
|
|
||||||
} Disconnect3gppContextStep;;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MMBroadbandBearerCinterion *self;
|
MMBroadbandBearerCinterion *self;
|
||||||
MMBaseModem *modem;
|
MMBaseModem *modem;
|
||||||
@@ -125,16 +119,6 @@ typedef struct {
|
|||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
} Connect3gppContext;
|
} Connect3gppContext;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
MMBroadbandBearerCinterion *self;
|
|
||||||
MMBaseModem *modem;
|
|
||||||
MMPortSerialAt *primary;
|
|
||||||
MMPort *data;
|
|
||||||
gint usb_interface_config_index;
|
|
||||||
Disconnect3gppContextStep disconnect;
|
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
} Disconnect3gppContext;
|
|
||||||
|
|
||||||
struct _MMBroadbandBearerCinterionPrivate {
|
struct _MMBroadbandBearerCinterionPrivate {
|
||||||
/* Flag for network-initiated disconnect */
|
/* Flag for network-initiated disconnect */
|
||||||
guint network_disconnect_pending_id;
|
guint network_disconnect_pending_id;
|
||||||
@@ -143,9 +127,7 @@ struct _MMBroadbandBearerCinterionPrivate {
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Common 3GPP Function Declarations */
|
/* Common 3GPP Function Declarations */
|
||||||
static void connect_3gpp_context_step (Connect3gppContext *ctx);
|
static void connect_3gpp_context_step (Connect3gppContext *ctx);
|
||||||
static void disconnect_3gpp_context_step (Disconnect3gppContext *ctx);
|
|
||||||
static void connect_3gpp_context_complete_and_free (Connect3gppContext *ctx);
|
static void connect_3gpp_context_complete_and_free (Connect3gppContext *ctx);
|
||||||
static void disconnect_3gpp_context_complete_and_free (Disconnect3gppContext *ctx);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Common - Helper Functions*/
|
/* Common - Helper Functions*/
|
||||||
@@ -625,34 +607,63 @@ connect_3gpp (MMBroadbandBearer *self,
|
|||||||
connect_3gpp_context_step (ctx);
|
connect_3gpp_context_step (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Disconnect - Helper Functions*/
|
/* Disconnect 3GPP */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DISCONNECT_3GPP_CONTEXT_STEP_FIRST,
|
||||||
|
DISCONNECT_3GPP_CONTEXT_STEP_STOP_SWWAN,
|
||||||
|
DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS,
|
||||||
|
DISCONNECT_3GPP_CONTEXT_STEP_LAST,
|
||||||
|
} Disconnect3gppContextStep;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMBroadbandBearerCinterion *self;
|
||||||
|
MMBaseModem *modem;
|
||||||
|
MMPortSerialAt *primary;
|
||||||
|
MMPort *data;
|
||||||
|
gint usb_interface_config_index;
|
||||||
|
Disconnect3gppContextStep step;
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
} Disconnect3gppContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_cmd_write_response_ctx_disconnect (MMBaseModem *modem,
|
disconnect_3gpp_context_complete_and_free (Disconnect3gppContext *ctx)
|
||||||
GAsyncResult *res,
|
|
||||||
Disconnect3gppContext *ctx)
|
|
||||||
{
|
{
|
||||||
/* We don't bother to check error or response here since, ctx flow's
|
g_simple_async_result_complete_in_idle (ctx->result);
|
||||||
* next step checks it */
|
g_object_unref (ctx->data);
|
||||||
|
g_object_unref (ctx->result);
|
||||||
/* GOTO next step */
|
g_object_unref (ctx->primary);
|
||||||
ctx->disconnect++;
|
g_object_unref (ctx->self);
|
||||||
disconnect_3gpp_context_step (ctx);
|
g_object_unref (ctx->modem);
|
||||||
|
g_slice_free (Disconnect3gppContext, 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_3gpp_context_step (Disconnect3gppContext *ctx);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_swwan_read_response_ctx_disconnect (MMBaseModem *modem,
|
swwan_disconnect_check_status_ready (MMBaseModem *modem,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
Disconnect3gppContext *ctx)
|
Disconnect3gppContext *ctx)
|
||||||
{
|
{
|
||||||
const gchar *response;
|
const gchar *response;
|
||||||
GError *error = NULL;
|
GList *response_parsed = NULL;
|
||||||
GList *response_parsed = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Get the SWWAN response */
|
response = mm_base_modem_at_command_full_finish (modem, res, &error);
|
||||||
response = mm_base_modem_at_command_finish (modem, res, &error);
|
if (error) {
|
||||||
|
g_simple_async_result_take_error (ctx->result, error);
|
||||||
|
disconnect_3gpp_context_complete_and_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return if the SWWAN read threw an error or parsing it fails */
|
/* Return if the SWWAN read threw an error or parsing it fails */
|
||||||
if (!mm_cinterion_parse_swwan_response (response, &response_parsed, &error)) {
|
if (!mm_cinterion_parse_swwan_response (response, &response_parsed, &error)) {
|
||||||
@@ -663,127 +674,98 @@ get_swwan_read_response_ctx_disconnect (MMBaseModem *modem,
|
|||||||
|
|
||||||
/* Check parsed SWWAN reponse to see if we are now disconnected */
|
/* Check parsed SWWAN reponse to see if we are now disconnected */
|
||||||
if (verify_connection_state_from_swwan_response (response_parsed, &error) != 1) {
|
if (verify_connection_state_from_swwan_response (response_parsed, &error) != 1) {
|
||||||
|
g_prefix_error (&error, "Disconnection attempt failed: ");
|
||||||
g_simple_async_result_set_error (ctx->result,
|
g_simple_async_result_take_error (ctx->result, error);
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_FAILED,
|
|
||||||
"Disconnection attempt failed");
|
|
||||||
|
|
||||||
disconnect_3gpp_context_complete_and_free (ctx);
|
disconnect_3gpp_context_complete_and_free (ctx);
|
||||||
|
g_list_free (response_parsed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (response_parsed);
|
g_list_free (response_parsed);
|
||||||
g_clear_error (&error);
|
|
||||||
|
|
||||||
/* GOTO next step */
|
/* Go on to next step */
|
||||||
ctx->disconnect++;
|
ctx->step++;
|
||||||
disconnect_3gpp_context_step (ctx);
|
disconnect_3gpp_context_step (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Disconnect - AT Command Wrappers*/
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_swwan_disconnect_command_ctx_disconnect (Disconnect3gppContext *ctx)
|
swwan_disconnect_ready (MMBaseModem *modem,
|
||||||
|
GAsyncResult *res,
|
||||||
|
Disconnect3gppContext *ctx)
|
||||||
{
|
{
|
||||||
/* 3rd context -> 1st wwan adapt / 1st context -> 2nd wwan adapt */
|
/* We don't bother to check error or response here since, ctx flow's
|
||||||
gchar *command;
|
* next step checks it */
|
||||||
command = g_strdup_printf ("^SWWAN=0,%u,%u",
|
mm_base_modem_at_command_full_finish (modem, res, NULL);
|
||||||
usb_interface_configs[ctx->usb_interface_config_index].pdp_context,
|
|
||||||
usb_interface_configs[ctx->usb_interface_config_index].swwan_index);
|
|
||||||
|
|
||||||
mm_base_modem_at_command_full (ctx->modem,
|
/* Go on to next step */
|
||||||
ctx->primary,
|
ctx->step++;
|
||||||
command,
|
disconnect_3gpp_context_step (ctx);
|
||||||
10,/*Seen it take 5 seconds :0 */
|
|
||||||
FALSE,
|
|
||||||
FALSE,
|
|
||||||
NULL,
|
|
||||||
(GAsyncReadyCallback)get_cmd_write_response_ctx_disconnect,
|
|
||||||
ctx);
|
|
||||||
|
|
||||||
g_free (command);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
send_swwan_read_command_ctx_disconnect (Disconnect3gppContext *ctx)
|
|
||||||
{
|
|
||||||
mm_base_modem_at_command_full (ctx->modem,
|
|
||||||
ctx->primary,
|
|
||||||
"^SWWAN?",
|
|
||||||
5,
|
|
||||||
FALSE,
|
|
||||||
FALSE,
|
|
||||||
NULL,
|
|
||||||
(GAsyncReadyCallback)get_swwan_read_response_ctx_disconnect,
|
|
||||||
ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Disconnect - Bearer */
|
|
||||||
|
|
||||||
static void
|
|
||||||
disconnect_3gpp_context_complete_and_free (Disconnect3gppContext *ctx)
|
|
||||||
{
|
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
g_clear_object (&ctx->data);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->primary);
|
|
||||||
g_object_unref (ctx->self);
|
|
||||||
g_object_unref (ctx->modem);
|
|
||||||
g_slice_free (Disconnect3gppContext, 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
|
static void
|
||||||
disconnect_3gpp_context_step (Disconnect3gppContext *ctx)
|
disconnect_3gpp_context_step (Disconnect3gppContext *ctx)
|
||||||
{
|
{
|
||||||
mm_dbg ("Disconnect Step:%i", ctx->disconnect);
|
switch (ctx->step) {
|
||||||
|
case DISCONNECT_3GPP_CONTEXT_STEP_FIRST:
|
||||||
|
/* Fall down to next step */
|
||||||
|
ctx->step++;
|
||||||
|
|
||||||
switch (ctx->disconnect) {
|
case DISCONNECT_3GPP_CONTEXT_STEP_STOP_SWWAN: {
|
||||||
case DISCONNECT_3GPP_CONTEXT_STEP_STOP_SWWAN:
|
gchar *command;
|
||||||
|
|
||||||
/* Has call back to next state */
|
command = g_strdup_printf ("^SWWAN=0,%u,%u",
|
||||||
send_swwan_disconnect_command_ctx_disconnect (ctx);
|
usb_interface_configs[ctx->usb_interface_config_index].pdp_context,
|
||||||
|
usb_interface_configs[ctx->usb_interface_config_index].swwan_index);
|
||||||
|
|
||||||
|
mm_dbg ("cinterion disconnect step 1/3: disconnecting PDP CID %u...",
|
||||||
|
usb_interface_configs[ctx->usb_interface_config_index].pdp_context);
|
||||||
|
mm_base_modem_at_command_full (ctx->modem,
|
||||||
|
ctx->primary,
|
||||||
|
command,
|
||||||
|
10,
|
||||||
|
FALSE,
|
||||||
|
FALSE,
|
||||||
|
NULL,
|
||||||
|
(GAsyncReadyCallback)swwan_disconnect_ready,
|
||||||
|
ctx);
|
||||||
|
g_free (command);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
case DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS:
|
case DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS:
|
||||||
|
mm_dbg ("cinterion disconnect step 2/3: checking SWWAN interface %u status...",
|
||||||
/* Has call back to next state */
|
usb_interface_configs[ctx->usb_interface_config_index].swwan_index);
|
||||||
send_swwan_read_command_ctx_disconnect (ctx);
|
mm_base_modem_at_command_full (ctx->modem,
|
||||||
|
ctx->primary,
|
||||||
|
"^SWWAN?",
|
||||||
|
5,
|
||||||
|
FALSE,
|
||||||
|
FALSE,
|
||||||
|
NULL,
|
||||||
|
(GAsyncReadyCallback)swwan_disconnect_check_status_ready,
|
||||||
|
ctx);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case DISCONNECT_3GPP_CONTEXT_STEP_FINISH:
|
case DISCONNECT_3GPP_CONTEXT_STEP_LAST:
|
||||||
|
mm_dbg ("cinterion disconnect step 3/3: finished");
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||||
disconnect_3gpp_context_complete_and_free (ctx);
|
disconnect_3gpp_context_complete_and_free (ctx);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect_3gpp (MMBroadbandBearer *self,
|
disconnect_3gpp (MMBroadbandBearer *self,
|
||||||
MMBroadbandModem *modem,
|
MMBroadbandModem *modem,
|
||||||
MMPortSerialAt *primary,
|
MMPortSerialAt *primary,
|
||||||
MMPortSerialAt *secondary,
|
MMPortSerialAt *secondary,
|
||||||
MMPort *data,
|
MMPort *data,
|
||||||
guint cid,
|
guint cid,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
Disconnect3gppContext *ctx;
|
Disconnect3gppContext *ctx;
|
||||||
gint usb_interface_config_index;
|
gint usb_interface_config_index;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
g_assert (primary != NULL);
|
g_assert (primary != NULL);
|
||||||
g_assert (data != NULL);
|
g_assert (data != NULL);
|
||||||
@@ -798,6 +780,9 @@ disconnect_3gpp (MMBroadbandBearer *self,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Input CID must match */
|
||||||
|
g_warn_if_fail (cid == usb_interface_configs[usb_interface_config_index].pdp_context);
|
||||||
|
|
||||||
/* Setup connection context */
|
/* Setup connection context */
|
||||||
ctx = g_slice_new0 (Disconnect3gppContext);
|
ctx = g_slice_new0 (Disconnect3gppContext);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
@@ -811,7 +796,7 @@ disconnect_3gpp (MMBroadbandBearer *self,
|
|||||||
ctx->usb_interface_config_index = usb_interface_config_index;
|
ctx->usb_interface_config_index = usb_interface_config_index;
|
||||||
|
|
||||||
/* Initialize */
|
/* Initialize */
|
||||||
ctx->disconnect = DISCONNECT_3GPP_CONTEXT_STEP_STOP_SWWAN;
|
ctx->step = DISCONNECT_3GPP_CONTEXT_STEP_FIRST;
|
||||||
|
|
||||||
/* Start */
|
/* Start */
|
||||||
disconnect_3gpp_context_step (ctx);
|
disconnect_3gpp_context_step (ctx);
|
||||||
|
Reference in New Issue
Block a user