~binli/ubuntu/vivid/modemmanager/lp1441095

« back to all changes in this revision

Viewing changes to plugins/icera/mm-broadband-bearer-icera.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Guido Günther, Michael Biebl
  • Date: 2014-06-25 02:23:09 UTC
  • mfrom: (20.2.2 sid)
  • Revision ID: package-import@ubuntu.com-20140625022309-43papaenj5ikbx3y
Tags: 1.2.0-1
[ Guido Günther ]
* New upstream version 1.2.0 (Closes: #731851)
* Update patches
* Install locale files
* Require newer libqmi
* Update symbols file
* Ship gobject introspection data
* Ship vala bindings

[ Michael Biebl ]
* Use canonical URI for Vcs-Git
* Use gir dh addon
* Update extendend package description (Closes: #744180)

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "mm-log.h"
33
33
#include "mm-modem-helpers.h"
34
34
#include "mm-error-helpers.h"
 
35
#include "mm-daemon-enums-types.h"
35
36
 
36
37
G_DEFINE_TYPE (MMBroadbandBearerIcera, mm_broadband_bearer_icera, MM_TYPE_BROADBAND_BEARER);
37
38
 
360
361
 
361
362
static void
362
363
report_disconnect_status (MMBroadbandBearerIcera *self,
363
 
                          MMBroadbandBearerIceraConnectionStatus status)
 
364
                          MMBearerConnectionStatus status)
364
365
{
365
366
    Disconnect3gppContext *ctx;
366
367
 
367
368
    /* Recover context */
368
369
    ctx = self->priv->disconnect_pending;
369
370
    self->priv->disconnect_pending = NULL;
 
371
    g_assert (ctx != NULL);
370
372
 
371
373
    /* Cleanup timeout, if any */
372
374
    if (self->priv->disconnect_pending_id) {
374
376
        self->priv->disconnect_pending_id = 0;
375
377
    }
376
378
 
377
 
    switch (status) {
378
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_UNKNOWN:
379
 
        g_warn_if_reached ();
380
 
        break;
381
 
 
382
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_CONNECTED:
383
 
        if (!ctx)
384
 
            break;
385
 
 
 
379
    /* Received 'CONNECTED' during a disconnection attempt? */
 
380
    if (status == MM_BEARER_CONNECTION_STATUS_CONNECTED) {
386
381
        g_simple_async_result_set_error (ctx->result,
387
382
                                         MM_CORE_ERROR,
388
383
                                         MM_CORE_ERROR_FAILED,
389
384
                                         "Disconnection failed");
390
385
        disconnect_3gpp_context_complete_and_free (ctx);
391
386
        return;
392
 
 
393
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_CONNECTION_FAILED:
394
 
        if (!ctx)
395
 
            break;
396
 
 
397
 
        /* Well, this actually means disconnection, right? */
398
 
        g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
399
 
        disconnect_3gpp_context_complete_and_free (ctx);
400
 
        return;
401
 
 
402
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_DISCONNECTED:
403
 
        if (!ctx) {
404
 
            mm_dbg ("Received spontaneous %%IPDPACT disconnect");
405
 
            mm_bearer_report_disconnection (MM_BEARER (self));
406
 
            break;
407
 
        }
408
 
 
409
 
        g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
410
 
        disconnect_3gpp_context_complete_and_free (ctx);
411
 
        return;
412
 
    }
 
387
    }
 
388
 
 
389
    /* Received 'DISCONNECTED' during a disconnection attempt? */
 
390
    if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED ||
 
391
        status == MM_BEARER_CONNECTION_STATUS_CONNECTION_FAILED) {
 
392
        g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
 
393
        disconnect_3gpp_context_complete_and_free (ctx);
 
394
        return;
 
395
    }
 
396
 
 
397
    /* No other status is expected by this implementation */
 
398
    g_assert_not_reached ();
413
399
}
414
400
 
415
401
static void
658
644
                 MMBroadbandBearerIcera *self)
659
645
{
660
646
    /* Just treat the forced close event as any other unsolicited message */
661
 
    mm_broadband_bearer_icera_report_connection_status (
662
 
        self,
663
 
        MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_CONNECTION_FAILED);
 
647
    mm_bearer_report_connection_status (MM_BEARER (self),
 
648
                                        MM_BEARER_CONNECTION_STATUS_CONNECTION_FAILED);
664
649
}
665
650
 
666
651
static void
699
684
 
700
685
static void
701
686
report_connect_status (MMBroadbandBearerIcera *self,
702
 
                       MMBroadbandBearerIceraConnectionStatus status)
 
687
                       MMBearerConnectionStatus status)
703
688
{
704
689
    Dial3gppContext *ctx;
705
690
 
 
691
    g_assert (status == MM_BEARER_CONNECTION_STATUS_CONNECTED ||
 
692
              status == MM_BEARER_CONNECTION_STATUS_CONNECTION_FAILED ||
 
693
              status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED);
 
694
 
706
695
    /* Recover context and remove it from the private info */
707
696
    ctx = self->priv->connect_pending;
708
697
    self->priv->connect_pending = NULL;
 
698
    g_assert (ctx != NULL);
709
699
 
710
700
    /* Cleanup cancellable, timeout and port closed watch, if any */
711
701
    if (self->priv->connect_pending_id) {
713
703
        self->priv->connect_pending_id = 0;
714
704
    }
715
705
 
716
 
    if (ctx && self->priv->connect_cancellable_id) {
 
706
    if (self->priv->connect_cancellable_id) {
717
707
        g_cancellable_disconnect (ctx->cancellable,
718
708
                                  self->priv->connect_cancellable_id);
719
709
        self->priv->connect_cancellable_id = 0;
720
710
    }
721
711
 
722
 
    if (ctx && self->priv->connect_port_closed_id) {
 
712
    if (self->priv->connect_port_closed_id) {
723
713
        g_signal_handler_disconnect (ctx->primary, self->priv->connect_port_closed_id);
724
714
        self->priv->connect_port_closed_id = 0;
725
715
    }
726
716
 
727
 
    switch (status) {
728
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_UNKNOWN:
729
 
        break;
730
 
 
731
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_CONNECTED:
732
 
        if (!ctx)
733
 
            /* We may get this if the timeout for the connection attempt is
734
 
             * reached before the unsolicited response. We should probably
735
 
             * keep the CID around to request explicit disconnection in this
736
 
             * case. */
737
 
            break;
738
 
 
 
717
    /* Received 'CONNECTED' during a connection attempt? */
 
718
    if (status == MM_BEARER_CONNECTION_STATUS_CONNECTED) {
739
719
        /* If we wanted to get cancelled before, do it now */
740
720
        if (ctx->saved_error) {
741
721
            /* Keep error */
751
731
                                                   (GDestroyNotify)g_object_unref);
752
732
        dial_3gpp_context_complete_and_free (ctx);
753
733
        return;
754
 
 
755
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_CONNECTION_FAILED:
756
 
        if (!ctx)
757
 
            break;
758
 
 
759
 
        /* If we wanted to get cancelled before and now we couldn't connect,
760
 
         * use the cancelled error and return */
761
 
        if (ctx->saved_error) {
762
 
            g_simple_async_result_take_error (ctx->result, ctx->saved_error);
763
 
            ctx->saved_error = NULL;
764
 
            dial_3gpp_context_complete_and_free (ctx);
765
 
            return;
766
 
        }
767
 
 
 
734
    }
 
735
 
 
736
    /* If we wanted to get cancelled before and now we couldn't connect,
 
737
     * use the cancelled error and return */
 
738
    if (ctx->saved_error) {
 
739
        g_simple_async_result_take_error (ctx->result, ctx->saved_error);
 
740
        ctx->saved_error = NULL;
 
741
        dial_3gpp_context_complete_and_free (ctx);
 
742
        return;
 
743
    }
 
744
 
 
745
    /* Received CONNECTION_FAILED during a connection attempt? */
 
746
    if (status == MM_BEARER_CONNECTION_STATUS_CONNECTION_FAILED) {
768
747
        /* Try to gather additional info about the connection failure */
769
748
        mm_base_modem_at_command_full (
770
749
            ctx->modem,
777
756
            (GAsyncReadyCallback)ier_query_ready,
778
757
            ctx);
779
758
        return;
780
 
 
781
 
    case MM_BROADBAND_BEARER_ICERA_CONNECTION_STATUS_DISCONNECTED:
782
 
        if (ctx) {
783
 
            /* If we wanted to get cancelled before and now we couldn't connect,
784
 
             * use the cancelled error and return */
785
 
            if (ctx->saved_error) {
786
 
                g_simple_async_result_take_error (ctx->result, ctx->saved_error);
787
 
                ctx->saved_error = NULL;
788
 
                dial_3gpp_context_complete_and_free (ctx);
789
 
                return;
790
 
            }
791
 
 
792
 
            g_simple_async_result_set_error (ctx->result,
793
 
                                             MM_CORE_ERROR,
794
 
                                             MM_CORE_ERROR_FAILED,
795
 
                                             "Call setup failed");
796
 
            dial_3gpp_context_complete_and_free (ctx);
797
 
            return;
798
 
        }
799
 
 
800
 
        /* Just ensure we mark ourselves as being disconnected... */
801
 
        mm_bearer_report_disconnection (MM_BEARER (self));
802
 
        return;
803
759
    }
804
760
 
805
 
    g_warn_if_reached ();
 
761
    /* Otherwise, received 'DISCONNECTED' during a connection attempt? */
 
762
    g_simple_async_result_set_error (ctx->result,
 
763
                                     MM_CORE_ERROR,
 
764
                                     MM_CORE_ERROR_FAILED,
 
765
                                     "Call setup failed");
 
766
    dial_3gpp_context_complete_and_free (ctx);
806
767
}
807
768
 
808
769
static void
1060
1021
 
1061
1022
/*****************************************************************************/
1062
1023
 
1063
 
void
1064
 
mm_broadband_bearer_icera_report_connection_status (MMBroadbandBearerIcera *self,
1065
 
                                                    MMBroadbandBearerIceraConnectionStatus status)
 
1024
static void
 
1025
report_connection_status (MMBearer *bearer,
 
1026
                          MMBearerConnectionStatus status)
1066
1027
{
1067
 
    if (self->priv->connect_pending)
 
1028
    MMBroadbandBearerIcera *self = MM_BROADBAND_BEARER_ICERA (bearer);
 
1029
 
 
1030
    /* Process pending connection attempt */
 
1031
    if (self->priv->connect_pending) {
1068
1032
        report_connect_status (self, status);
 
1033
        return;
 
1034
    }
1069
1035
 
1070
 
    if (self->priv->disconnect_pending)
 
1036
    /* Process pending disconnection attempt */
 
1037
    if (self->priv->disconnect_pending) {
1071
1038
        report_disconnect_status (self, status);
 
1039
        return;
 
1040
    }
 
1041
 
 
1042
    mm_dbg ("Received spontaneous %%IPDPACT (%s)",
 
1043
            mm_bearer_connection_status_get_string (status));
 
1044
 
 
1045
    /* Received a random 'DISCONNECTED'...*/
 
1046
    if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED ||
 
1047
        status == MM_BEARER_CONNECTION_STATUS_CONNECTION_FAILED) {
 
1048
        /* If no connection/disconnection attempt on-going, make sure we mark ourselves as
 
1049
         * disconnected. Make sure we only pass 'DISCONNECTED' to the parent */
 
1050
        MM_BEARER_CLASS (mm_broadband_bearer_icera_parent_class)->report_connection_status (
 
1051
            bearer,
 
1052
            MM_BEARER_CONNECTION_STATUS_DISCONNECTED);
 
1053
    }
1072
1054
}
1073
1055
 
1074
1056
/*****************************************************************************/
1165
1147
mm_broadband_bearer_icera_class_init (MMBroadbandBearerIceraClass *klass)
1166
1148
{
1167
1149
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
1150
    MMBearerClass *bearer_class = MM_BEARER_CLASS (klass);
1168
1151
    MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
1169
1152
 
1170
1153
    g_type_class_add_private (object_class, sizeof (MMBroadbandBearerIceraPrivate));
1171
1154
 
1172
1155
    object_class->get_property = get_property;
1173
1156
    object_class->set_property = set_property;
 
1157
    bearer_class->report_connection_status = report_connection_status;
1174
1158
    broadband_bearer_class->dial_3gpp = dial_3gpp;
1175
1159
    broadband_bearer_class->dial_3gpp_finish = dial_3gpp_finish;
1176
1160
    broadband_bearer_class->get_ip_config_3gpp = get_ip_config_3gpp;