bearer-qmi: allocate different WDS clients for IPv4 and IPv6 setups

This commit is contained in:
Aleksander Morgado
2012-08-27 15:10:23 +02:00
parent 28eb5df342
commit fb93226858
2 changed files with 126 additions and 56 deletions

View File

@@ -33,7 +33,8 @@ G_DEFINE_TYPE (MMBearerQmi, mm_bearer_qmi, MM_TYPE_BEARER);
struct _MMBearerQmiPrivate { struct _MMBearerQmiPrivate {
/* State kept while connected */ /* State kept while connected */
QmiClientWds *client; QmiClientWds *client_ipv4;
QmiClientWds *client_ipv6;
MMPort *data; MMPort *data;
guint32 packet_data_handle_ipv4; guint32 packet_data_handle_ipv4;
guint32 packet_data_handle_ipv6; guint32 packet_data_handle_ipv6;
@@ -62,8 +63,11 @@ connect_result_free (ConnectResult *result)
typedef enum { typedef enum {
CONNECT_STEP_FIRST, CONNECT_STEP_FIRST,
CONNECT_STEP_OPEN_QMI_PORT, CONNECT_STEP_OPEN_QMI_PORT,
CONNECT_STEP_WDS_CLIENT, CONNECT_STEP_IPV4,
CONNECT_STEP_WDS_CLIENT_IPV4,
CONNECT_STEP_START_NETWORK_IPV4, CONNECT_STEP_START_NETWORK_IPV4,
CONNECT_STEP_IPV6,
CONNECT_STEP_WDS_CLIENT_IPV6,
CONNECT_STEP_START_NETWORK_IPV6, CONNECT_STEP_START_NETWORK_IPV6,
CONNECT_STEP_LAST CONNECT_STEP_LAST
} ConnectStep; } ConnectStep;
@@ -75,18 +79,19 @@ typedef struct {
ConnectStep step; ConnectStep step;
MMPort *data; MMPort *data;
MMQmiPort *qmi; MMQmiPort *qmi;
QmiClientWds *client;
gchar *user; gchar *user;
gchar *password; gchar *password;
gchar *apn; gchar *apn;
gboolean ipv4; gboolean ipv4;
gboolean running_ipv4; gboolean running_ipv4;
QmiClientWds *client_ipv4;
guint32 packet_data_handle_ipv4; guint32 packet_data_handle_ipv4;
GError *error_ipv4; GError *error_ipv4;
gboolean ipv6; gboolean ipv6;
gboolean running_ipv6; gboolean running_ipv6;
QmiClientWds *client_ipv6;
guint32 packet_data_handle_ipv6; guint32 packet_data_handle_ipv6;
GError *error_ipv6; GError *error_ipv6;
} ConnectContext; } ConnectContext;
@@ -103,8 +108,10 @@ connect_context_complete_and_free (ConnectContext *ctx)
g_error_free (ctx->error_ipv4); g_error_free (ctx->error_ipv4);
if (ctx->error_ipv6) if (ctx->error_ipv6)
g_error_free (ctx->error_ipv6); g_error_free (ctx->error_ipv6);
if (ctx->client) if (ctx->client_ipv4)
g_object_unref (ctx->client); g_object_unref (ctx->client_ipv4);
if (ctx->client_ipv6)
g_object_unref (ctx->client_ipv6);
g_object_unref (ctx->data); g_object_unref (ctx->data);
g_object_unref (ctx->qmi); g_object_unref (ctx->qmi);
g_object_unref (ctx->cancellable); g_object_unref (ctx->cancellable);
@@ -242,15 +249,23 @@ qmi_port_allocate_client_ready (MMQmiPort *qmi,
{ {
GError *error = NULL; GError *error = NULL;
g_assert (ctx->running_ipv4 || ctx->running_ipv6);
g_assert (!(ctx->running_ipv4 && ctx->running_ipv6));
if (!mm_qmi_port_allocate_client_finish (qmi, res, &error)) { if (!mm_qmi_port_allocate_client_finish (qmi, res, &error)) {
g_simple_async_result_take_error (ctx->result, error); g_simple_async_result_take_error (ctx->result, error);
connect_context_complete_and_free (ctx); connect_context_complete_and_free (ctx);
return; return;
} }
ctx->client = QMI_CLIENT_WDS (mm_qmi_port_get_client (qmi, if (ctx->running_ipv4)
QMI_SERVICE_WDS, ctx->client_ipv4 = QMI_CLIENT_WDS (mm_qmi_port_get_client (qmi,
MM_QMI_PORT_FLAG_DEFAULT)); QMI_SERVICE_WDS,
MM_QMI_PORT_FLAG_WDS_IPV4));
else
ctx->client_ipv6 = QMI_CLIENT_WDS (mm_qmi_port_get_client (qmi,
QMI_SERVICE_WDS,
MM_QMI_PORT_FLAG_WDS_IPV6));
/* Keep on */ /* Keep on */
ctx->step++; ctx->step++;
@@ -308,66 +323,109 @@ connect_context_step (ConnectContext *ctx)
/* If already open, just fall down */ /* If already open, just fall down */
ctx->step++; ctx->step++;
case CONNECT_STEP_WDS_CLIENT: { case CONNECT_STEP_IPV4:
/* If no IPv4 setup needed, jump to IPv6 */
if (!ctx->ipv4) {
ctx->step = CONNECT_STEP_IPV6;
connect_context_step (ctx);
return;
}
/* Start IPv4 setup */
mm_dbg ("Running IPv4 connection setup");
ctx->running_ipv4 = TRUE;
ctx->running_ipv6 = FALSE;
/* Just fall down */
ctx->step++;
case CONNECT_STEP_WDS_CLIENT_IPV4: {
QmiClient *client; QmiClient *client;
client = mm_qmi_port_get_client (ctx->qmi, client = mm_qmi_port_get_client (ctx->qmi,
QMI_SERVICE_WDS, QMI_SERVICE_WDS,
MM_QMI_PORT_FLAG_DEFAULT); MM_QMI_PORT_FLAG_WDS_IPV4);
if (!client) { if (!client) {
mm_dbg ("Allocating IPv4-specific WDS client");
mm_qmi_port_allocate_client (ctx->qmi, mm_qmi_port_allocate_client (ctx->qmi,
QMI_SERVICE_WDS, QMI_SERVICE_WDS,
MM_QMI_PORT_FLAG_DEFAULT, MM_QMI_PORT_FLAG_WDS_IPV4,
ctx->cancellable, ctx->cancellable,
(GAsyncReadyCallback)qmi_port_allocate_client_ready, (GAsyncReadyCallback)qmi_port_allocate_client_ready,
ctx); ctx);
return; return;
} }
ctx->client = QMI_CLIENT_WDS (client); ctx->client_ipv4 = QMI_CLIENT_WDS (client);
/* Just fall down */
ctx->step++;
} }
case CONNECT_STEP_START_NETWORK_IPV4: case CONNECT_STEP_START_NETWORK_IPV4: {
if (ctx->ipv4) { QmiMessageWdsStartNetworkInput *input;
QmiMessageWdsStartNetworkInput *input;
ctx->running_ipv4 = TRUE; mm_dbg ("Starting IPv4 connection...");
ctx->running_ipv6 = FALSE; input = build_start_network_input (ctx);
input = build_start_network_input (ctx); qmi_client_wds_start_network (ctx->client_ipv4,
qmi_client_wds_start_network (ctx->client, input,
input, 10,
10, ctx->cancellable,
ctx->cancellable, (GAsyncReadyCallback)start_network_ready,
(GAsyncReadyCallback)start_network_ready, ctx);
ctx); qmi_message_wds_start_network_input_unref (input);
if (input) return;
qmi_message_wds_start_network_input_unref (input); }
case CONNECT_STEP_IPV6:
/* If no IPv6 setup needed, jump to last */
if (!ctx->ipv6) {
ctx->step = CONNECT_STEP_LAST;
connect_context_step (ctx);
return; return;
} }
/* No IPv4 setup needed, fall down */ /* Start IPv6 setup */
mm_dbg ("Running IPv6 connection setup");
ctx->running_ipv4 = FALSE;
ctx->running_ipv6 = TRUE;
/* Just fall down */
ctx->step++; ctx->step++;
case CONNECT_STEP_START_NETWORK_IPV6: case CONNECT_STEP_WDS_CLIENT_IPV6: {
if (ctx->ipv6) { QmiClient *client;
QmiMessageWdsStartNetworkInput *input;
ctx->running_ipv4 = FALSE; client = mm_qmi_port_get_client (ctx->qmi,
ctx->running_ipv6 = TRUE; QMI_SERVICE_WDS,
input = build_start_network_input (ctx); MM_QMI_PORT_FLAG_WDS_IPV6);
qmi_client_wds_start_network (ctx->client, if (!client) {
input, mm_dbg ("Allocating IPv6-specific WDS client");
10, mm_qmi_port_allocate_client (ctx->qmi,
ctx->cancellable, QMI_SERVICE_WDS,
(GAsyncReadyCallback)start_network_ready, MM_QMI_PORT_FLAG_WDS_IPV6,
ctx); ctx->cancellable,
if (input) (GAsyncReadyCallback)qmi_port_allocate_client_ready,
qmi_message_wds_start_network_input_unref (input); ctx);
return; return;
} }
/* No IPv6 setup needed, fall down */ ctx->client_ipv6 = QMI_CLIENT_WDS (client);
/* Just fall down */
ctx->step++; ctx->step++;
}
case CONNECT_STEP_START_NETWORK_IPV6: {
QmiMessageWdsStartNetworkInput *input;
mm_dbg ("Starting IPv6 connection...");
input = build_start_network_input (ctx);
qmi_client_wds_start_network (ctx->client_ipv6,
input,
10,
ctx->cancellable,
(GAsyncReadyCallback)start_network_ready,
ctx);
qmi_message_wds_start_network_input_unref (input);
return;
}
case CONNECT_STEP_LAST: case CONNECT_STEP_LAST:
/* If one of IPv4 or IPv6 succeeds, we're connected */ /* If one of IPv4 or IPv6 succeeds, we're connected */
@@ -381,10 +439,12 @@ connect_context_step (ConnectContext *ctx)
/* Keep connection related data */ /* Keep connection related data */
g_assert (ctx->self->priv->data == NULL); g_assert (ctx->self->priv->data == NULL);
ctx->self->priv->data = g_object_ref (ctx->data); ctx->self->priv->data = g_object_ref (ctx->data);
g_assert (ctx->self->priv->client == NULL); g_assert (ctx->self->priv->client_ipv4 == NULL);
ctx->self->priv->client = g_object_ref (ctx->client); ctx->self->priv->client_ipv4 = g_object_ref (ctx->client_ipv4);
g_assert (ctx->self->priv->packet_data_handle_ipv4 == 0); g_assert (ctx->self->priv->packet_data_handle_ipv4 == 0);
ctx->self->priv->packet_data_handle_ipv4 = ctx->packet_data_handle_ipv4; ctx->self->priv->packet_data_handle_ipv4 = ctx->packet_data_handle_ipv4;
g_assert (ctx->self->priv->client_ipv6 == NULL);
ctx->self->priv->client_ipv6 = g_object_ref (ctx->client_ipv6);
g_assert (ctx->self->priv->packet_data_handle_ipv6 == 0); g_assert (ctx->self->priv->packet_data_handle_ipv6 == 0);
ctx->self->priv->packet_data_handle_ipv6 = ctx->packet_data_handle_ipv6; ctx->self->priv->packet_data_handle_ipv6 = ctx->packet_data_handle_ipv6;
@@ -549,15 +609,16 @@ typedef enum {
typedef struct { typedef struct {
MMBearerQmi *self; MMBearerQmi *self;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
QmiClientWds *client;
MMPort *data; MMPort *data;
DisconnectStep step; DisconnectStep step;
gboolean running_ipv4; gboolean running_ipv4;
QmiClientWds *client_ipv4;
guint32 packet_data_handle_ipv4; guint32 packet_data_handle_ipv4;
GError *error_ipv4; GError *error_ipv4;
gboolean running_ipv6; gboolean running_ipv6;
QmiClientWds *client_ipv6;
guint32 packet_data_handle_ipv6; guint32 packet_data_handle_ipv6;
GError *error_ipv6; GError *error_ipv6;
} DisconnectContext; } DisconnectContext;
@@ -571,7 +632,10 @@ disconnect_context_complete_and_free (DisconnectContext *ctx)
g_error_free (ctx->error_ipv4); g_error_free (ctx->error_ipv4);
if (ctx->error_ipv6) if (ctx->error_ipv6)
g_error_free (ctx->error_ipv6); g_error_free (ctx->error_ipv6);
g_object_unref (ctx->client); if (ctx->client_ipv4)
g_object_unref (ctx->client_ipv4);
if (ctx->client_ipv6)
g_object_unref (ctx->client_ipv6);
g_object_unref (ctx->data); g_object_unref (ctx->data);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_slice_free (DisconnectContext, ctx); g_slice_free (DisconnectContext, ctx);
@@ -590,11 +654,15 @@ reset_bearer_connection (MMBearerQmi *self,
gboolean reset_ipv4, gboolean reset_ipv4,
gboolean reset_ipv6) gboolean reset_ipv6)
{ {
if (reset_ipv4) if (reset_ipv4) {
self->priv->packet_data_handle_ipv4 = 0; self->priv->packet_data_handle_ipv4 = 0;
g_clear_object (&self->priv->client_ipv4);
}
if (reset_ipv6) if (reset_ipv6) {
self->priv->packet_data_handle_ipv6 = 0; self->priv->packet_data_handle_ipv6 = 0;
g_clear_object (&self->priv->client_ipv6);
}
if (!self->priv->packet_data_handle_ipv4 && if (!self->priv->packet_data_handle_ipv4 &&
!self->priv->packet_data_handle_ipv6) { !self->priv->packet_data_handle_ipv6) {
@@ -603,8 +671,6 @@ reset_bearer_connection (MMBearerQmi *self,
mm_port_set_connected (self->priv->data, FALSE); mm_port_set_connected (self->priv->data, FALSE);
g_clear_object (&self->priv->data); g_clear_object (&self->priv->data);
} }
g_clear_object (&self->priv->client);
} }
} }
@@ -659,7 +725,7 @@ disconnect_context_step (DisconnectContext *ctx)
ctx->running_ipv4 = TRUE; ctx->running_ipv4 = TRUE;
ctx->running_ipv6 = FALSE; ctx->running_ipv6 = FALSE;
qmi_client_wds_stop_network (ctx->client, qmi_client_wds_stop_network (ctx->client_ipv4,
input, input,
10, 10,
NULL, NULL,
@@ -680,7 +746,7 @@ disconnect_context_step (DisconnectContext *ctx)
ctx->running_ipv4 = FALSE; ctx->running_ipv4 = FALSE;
ctx->running_ipv6 = TRUE; ctx->running_ipv6 = TRUE;
qmi_client_wds_stop_network (ctx->client, qmi_client_wds_stop_network (ctx->client_ipv6,
input, input,
10, 10,
NULL, NULL,
@@ -724,7 +790,7 @@ disconnect (MMBearer *_self,
DisconnectContext *ctx; DisconnectContext *ctx;
if ((!self->priv->packet_data_handle_ipv4 && !self->priv->packet_data_handle_ipv6) || if ((!self->priv->packet_data_handle_ipv4 && !self->priv->packet_data_handle_ipv6) ||
!self->priv->client || (!self->priv->client_ipv4 && self->priv->client_ipv6) ||
!self->priv->data) { !self->priv->data) {
g_simple_async_report_error_in_idle ( g_simple_async_report_error_in_idle (
G_OBJECT (self), G_OBJECT (self),
@@ -739,8 +805,9 @@ disconnect (MMBearer *_self,
ctx = g_slice_new0 (DisconnectContext); ctx = g_slice_new0 (DisconnectContext);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->data = g_object_ref (self->priv->data); ctx->data = g_object_ref (self->priv->data);
ctx->client = g_object_ref (self->priv->client); ctx->client_ipv4 = self->priv->client_ipv4 ? g_object_ref (self->priv->client_ipv4) : NULL;
ctx->packet_data_handle_ipv4 = self->priv->packet_data_handle_ipv4; ctx->packet_data_handle_ipv4 = self->priv->packet_data_handle_ipv4;
ctx->client_ipv6 = self->priv->client_ipv6 ? g_object_ref (self->priv->client_ipv6) : NULL;
ctx->packet_data_handle_ipv6 = self->priv->packet_data_handle_ipv6; ctx->packet_data_handle_ipv6 = self->priv->packet_data_handle_ipv6;
ctx->result = g_simple_async_result_new (G_OBJECT (self), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
@@ -801,7 +868,8 @@ dispose (GObject *object)
MMBearerQmi *self = MM_BEARER_QMI (object); MMBearerQmi *self = MM_BEARER_QMI (object);
g_clear_object (&self->priv->data); g_clear_object (&self->priv->data);
g_clear_object (&self->priv->client); g_clear_object (&self->priv->client_ipv4);
g_clear_object (&self->priv->client_ipv6);
G_OBJECT_CLASS (mm_bearer_qmi_parent_class)->dispose (object); G_OBJECT_CLASS (mm_bearer_qmi_parent_class)->dispose (object);
} }

View File

@@ -59,7 +59,9 @@ gboolean mm_qmi_port_is_open (MMQmiPort *self);
void mm_qmi_port_close (MMQmiPort *self); void mm_qmi_port_close (MMQmiPort *self);
typedef enum { typedef enum {
MM_QMI_PORT_FLAG_DEFAULT = 0 MM_QMI_PORT_FLAG_DEFAULT = 0,
MM_QMI_PORT_FLAG_WDS_IPV4 = 100,
MM_QMI_PORT_FLAG_WDS_IPV6 = 101
} MMQmiPortFlag; } MMQmiPortFlag;
void mm_qmi_port_allocate_client (MMQmiPort *self, void mm_qmi_port_allocate_client (MMQmiPort *self,