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:
Aleksander Morgado
2016-11-24 00:23:48 +01:00
parent 6721c83d07
commit 955b46daf9

View File

@@ -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,109 +607,31 @@ connect_3gpp (MMBroadbandBearer *self,
connect_3gpp_context_step (ctx); connect_3gpp_context_step (ctx);
} }
/*****************************************************************************/ /*****************************************************************************/
/* Disconnect - Helper Functions*/ /* Disconnect 3GPP */
static void typedef enum {
get_cmd_write_response_ctx_disconnect (MMBaseModem *modem, DISCONNECT_3GPP_CONTEXT_STEP_FIRST,
GAsyncResult *res, DISCONNECT_3GPP_CONTEXT_STEP_STOP_SWWAN,
Disconnect3gppContext *ctx) DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS,
{ DISCONNECT_3GPP_CONTEXT_STEP_LAST,
/* We don't bother to check error or response here since, ctx flow's } Disconnect3gppContextStep;
* next step checks it */
/* GOTO next step */ typedef struct {
ctx->disconnect++; MMBroadbandBearerCinterion *self;
disconnect_3gpp_context_step (ctx); MMBaseModem *modem;
} MMPortSerialAt *primary;
MMPort *data;
static void gint usb_interface_config_index;
get_swwan_read_response_ctx_disconnect (MMBaseModem *modem, Disconnect3gppContextStep step;
GAsyncResult *res, GSimpleAsyncResult *result;
Disconnect3gppContext *ctx) } Disconnect3gppContext;
{
const gchar *response;
GError *error = NULL;
GList *response_parsed = NULL;
/* Get the SWWAN response */
response = mm_base_modem_at_command_finish (modem, res, &error);
/* Return if the SWWAN read threw an error or parsing it fails */
if (!mm_cinterion_parse_swwan_response (response, &response_parsed, &error)) {
g_simple_async_result_take_error (ctx->result, error);
disconnect_3gpp_context_complete_and_free (ctx);
return;
}
/* Check parsed SWWAN reponse to see if we are now disconnected */
if (verify_connection_state_from_swwan_response (response_parsed, &error) != 1) {
g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Disconnection attempt failed");
disconnect_3gpp_context_complete_and_free (ctx);
return;
}
g_list_free (response_parsed);
g_clear_error (&error);
/* GOTO next step */
ctx->disconnect++;
disconnect_3gpp_context_step (ctx);
}
/*****************************************************************************/
/* Disconnect - AT Command Wrappers*/
static void
send_swwan_disconnect_command_ctx_disconnect (Disconnect3gppContext *ctx)
{
/* 3rd context -> 1st wwan adapt / 1st context -> 2nd wwan adapt */
gchar *command;
command = g_strdup_printf ("^SWWAN=0,%u,%u",
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,
ctx->primary,
command,
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 static void
disconnect_3gpp_context_complete_and_free (Disconnect3gppContext *ctx) disconnect_3gpp_context_complete_and_free (Disconnect3gppContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_clear_object (&ctx->data); g_object_unref (ctx->data);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->primary); g_object_unref (ctx->primary);
g_object_unref (ctx->self); g_object_unref (ctx->self);
@@ -743,30 +647,108 @@ disconnect_3gpp_finish (MMBroadbandBearer *self,
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
} }
static void disconnect_3gpp_context_step (Disconnect3gppContext *ctx);
static void
swwan_disconnect_check_status_ready (MMBaseModem *modem,
GAsyncResult *res,
Disconnect3gppContext *ctx)
{
const gchar *response;
GList *response_parsed = NULL;
GError *error = NULL;
response = mm_base_modem_at_command_full_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 */
if (!mm_cinterion_parse_swwan_response (response, &response_parsed, &error)) {
g_simple_async_result_take_error (ctx->result, error);
disconnect_3gpp_context_complete_and_free (ctx);
return;
}
/* Check parsed SWWAN reponse to see if we are now disconnected */
if (verify_connection_state_from_swwan_response (response_parsed, &error) != 1) {
g_prefix_error (&error, "Disconnection attempt failed: ");
g_simple_async_result_take_error (ctx->result, error);
disconnect_3gpp_context_complete_and_free (ctx);
g_list_free (response_parsed);
return;
}
g_list_free (response_parsed);
/* Go on to next step */
ctx->step++;
disconnect_3gpp_context_step (ctx);
}
static void
swwan_disconnect_ready (MMBaseModem *modem,
GAsyncResult *res,
Disconnect3gppContext *ctx)
{
/* We don't bother to check error or response here since, ctx flow's
* next step checks it */
mm_base_modem_at_command_full_finish (modem, res, NULL);
/* Go on to next step */
ctx->step++;
disconnect_3gpp_context_step (ctx);
}
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;
} }
} }
@@ -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);