~ubuntu-branches/ubuntu/wily/modemmanager/wily

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2013-12-20 15:35:26 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131220153526-j3xu9gp51ltzlizc
Tags: 1.0.0-1
* New upstream release. (Closes: #728214, #728215)
* debian/control: add a versioned dependency for libqmi -- we need at least
  version 1.4.
* debian/control: build-depends on libmbim-glib-dev 1.4
* debian/rules: run the local autogen.sh rather than gnome-autogen.sh.
* debian/rules: drop --with-tests. 
* debian/rules: clean up after gtk-doc files left around.
* debian/patches/glib_fixes.patch: link against glib explicitly for the
  huawei modem helper tests.
* debian/libmm-glib0.symbols: updated symbols.
* debian/watch: update watch file for new location of upstream source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
/*****************************************************************************/
71
71
/* Load supported modes (Modem interface) */
72
72
 
 
73
static void
 
74
add_supported_mode (GArray **combinations,
 
75
                    guint mode)
 
76
{
 
77
    MMModemModeCombination combination;
 
78
 
 
79
    switch (mode) {
 
80
    case 0:
 
81
        mm_dbg ("Modem supports 2G-only mode");
 
82
        combination.allowed = MM_MODEM_MODE_2G;
 
83
        combination.preferred = MM_MODEM_MODE_NONE;
 
84
        break;
 
85
    case 1:
 
86
        mm_dbg ("Modem supports 3G-only mode");
 
87
        combination.allowed = MM_MODEM_MODE_3G;
 
88
        combination.preferred = MM_MODEM_MODE_NONE;
 
89
        break;
 
90
    case 2:
 
91
        mm_dbg ("Modem supports 2G/3G mode with 2G preferred");
 
92
        combination.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
 
93
        combination.preferred = MM_MODEM_MODE_2G;
 
94
        break;
 
95
    case 3:
 
96
        mm_dbg ("Modem supports 2G/3G mode with 3G preferred");
 
97
        combination.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
 
98
        combination.preferred = MM_MODEM_MODE_3G;
 
99
        break;
 
100
    case 5:
 
101
        mm_dbg ("Modem supports 'any', but not explicitly listing it");
 
102
        /* Any, no need to add it to the list */
 
103
        return;
 
104
    default:
 
105
        mm_warn ("Unsupported Icera mode found: %u", mode);
 
106
        return;
 
107
    }
 
108
 
 
109
    if (*combinations == NULL)
 
110
        *combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 5);
 
111
 
 
112
    g_array_append_val (*combinations, combination);
 
113
}
 
114
 
73
115
static GArray *
74
116
load_supported_modes_finish (MMIfaceModem *self,
75
117
                             GAsyncResult *res,
76
118
                             GError **error)
77
119
{
78
 
    if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
79
 
        return NULL;
80
 
 
81
 
    return g_array_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
82
 
}
83
 
 
84
 
static void
85
 
parent_load_supported_modes_ready (MMIfaceModem *self,
86
 
                                   GAsyncResult *res,
87
 
                                   GSimpleAsyncResult *simple)
88
 
{
89
 
    GError *error = NULL;
90
 
    GArray *all;
91
 
    GArray *combinations;
92
 
    GArray *filtered;
93
 
    MMModemModeCombination mode;
94
 
 
95
 
    all = iface_modem_parent->load_supported_modes_finish (self, res, &error);
96
 
    if (!all) {
97
 
        g_simple_async_result_take_error (simple, error);
98
 
        g_simple_async_result_complete (simple);
99
 
        g_object_unref (simple);
100
 
        return;
101
 
    }
102
 
 
103
 
    /* Build list of combinations */
104
 
    combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 5);
105
 
 
106
 
    /* 2G only */
107
 
    mode.allowed = MM_MODEM_MODE_2G;
108
 
    mode.preferred = MM_MODEM_MODE_NONE;
109
 
    g_array_append_val (combinations, mode);
110
 
    /* 3G only */
111
 
    mode.allowed = MM_MODEM_MODE_3G;
112
 
    mode.preferred = MM_MODEM_MODE_NONE;
113
 
    g_array_append_val (combinations, mode);
114
 
    /* 2G and 3G */
115
 
    mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
116
 
    mode.preferred = MM_MODEM_MODE_NONE;
117
 
    g_array_append_val (combinations, mode);
118
 
    /* 2G and 3G, 2G preferred */
119
 
    mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
120
 
    mode.preferred = MM_MODEM_MODE_2G;
121
 
    g_array_append_val (combinations, mode);
122
 
    /* 2G and 3G, 3G preferred */
123
 
    mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
124
 
    mode.preferred = MM_MODEM_MODE_3G;
125
 
    g_array_append_val (combinations, mode);
126
 
 
127
 
    /* Filter out those unsupported modes */
128
 
    filtered = mm_filter_supported_modes (all, combinations);
129
 
    g_array_unref (all);
130
 
    g_array_unref (combinations);
131
 
 
132
 
    g_simple_async_result_set_op_res_gpointer (simple, filtered, (GDestroyNotify) g_array_unref);
133
 
    g_simple_async_result_complete (simple);
134
 
    g_object_unref (simple);
 
120
    GArray *combinations = NULL;
 
121
    const gchar *response;
 
122
    gchar **split = NULL;
 
123
    GMatchInfo *match_info;
 
124
    GRegex *r;
 
125
    guint i;
 
126
 
 
127
    response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
 
128
    if (!response)
 
129
        return NULL;
 
130
 
 
131
    /* Reply goes like this:
 
132
     * AT%IPSYS=?
 
133
     * %IPSYS: (0-3,5),(0-3)
 
134
     */
 
135
 
 
136
    r = g_regex_new ("\\%IPSYS:\\s*\\((.*)\\)\\s*,\\((.*)\\)",
 
137
                     G_REGEX_RAW, 0, NULL);
 
138
    g_assert (r != NULL);
 
139
 
 
140
    g_regex_match (r, response, 0, &match_info);
 
141
    if (g_match_info_matches (match_info)) {
 
142
        gchar *aux;
 
143
 
 
144
        aux = mm_get_string_unquoted_from_match_info (match_info, 1);
 
145
        if (aux) {
 
146
            split = g_strsplit (aux, ",", -1);
 
147
            g_free (aux);
 
148
        }
 
149
    }
 
150
 
 
151
    g_match_info_free (match_info);
 
152
    g_regex_unref (r);
 
153
 
 
154
    if (!split) {
 
155
        g_set_error (error,
 
156
                     MM_CORE_ERROR,
 
157
                     MM_CORE_ERROR_FAILED,
 
158
                     "%%IPSYS=? response didn't match");
 
159
        g_regex_unref (r);
 
160
        return NULL;
 
161
    }
 
162
 
 
163
    for (i = 0; split[i]; i++) {
 
164
        gchar *interval_separator;
 
165
 
 
166
        g_strstrip (split[i]);
 
167
        interval_separator = strstr (split[i], "-");
 
168
        if (interval_separator) {
 
169
            /* Add all in interval */
 
170
            gchar *first, *last;
 
171
            guint modefirst, modelast;
 
172
 
 
173
            first = g_strdup (split[i]);
 
174
            interval_separator = strstr (first, "-");
 
175
            *(interval_separator++) = '\0';
 
176
            last = interval_separator;
 
177
 
 
178
            if (mm_get_uint_from_str (first, &modefirst) &&
 
179
                mm_get_uint_from_str (last, &modelast) &&
 
180
                modefirst < modelast &&
 
181
                modelast <= 5) {
 
182
                guint j;
 
183
 
 
184
                for (j = modefirst; j <= modelast; j++)
 
185
                    add_supported_mode (&combinations, j);
 
186
            } else
 
187
                mm_warn ("Couldn't parse mode interval (%s) in %%IPSYS=? response", split[i]);
 
188
            g_free (first);
 
189
        } else {
 
190
            guint mode;
 
191
 
 
192
            /* Add single */
 
193
            if (mm_get_uint_from_str (split[i], &mode))
 
194
                add_supported_mode (&combinations, mode);
 
195
            else
 
196
                mm_warn ("Couldn't parse mode (%s) in %%IPSYS=? response", split[i]);
 
197
        }
 
198
    }
 
199
 
 
200
    g_strfreev (split);
 
201
 
 
202
    if (!combinations)
 
203
        g_set_error (error,
 
204
                     MM_CORE_ERROR,
 
205
                     MM_CORE_ERROR_FAILED,
 
206
                     "No mode combinations were parsed from the %%IPSYS=? response (%s)",
 
207
                     response);
 
208
 
 
209
    return combinations;
135
210
}
136
211
 
137
212
static void
139
214
                      GAsyncReadyCallback callback,
140
215
                      gpointer user_data)
141
216
{
142
 
    /* Run parent's loading */
143
 
    iface_modem_parent->load_supported_modes (
144
 
        MM_IFACE_MODEM (self),
145
 
        (GAsyncReadyCallback)parent_load_supported_modes_ready,
146
 
        g_simple_async_result_new (G_OBJECT (self),
147
 
                                   callback,
148
 
                                   user_data,
149
 
                                   load_supported_modes));
 
217
    mm_base_modem_at_command (MM_BASE_MODEM (self),
 
218
                              "%IPSYS=?",
 
219
                              3,
 
220
                              TRUE,
 
221
                              callback,
 
222
                              user_data);
150
223
}
151
224
 
152
225
/*****************************************************************************/