~ubuntu-branches/ubuntu/vivid/modemmanager/vivid-proposed

« back to all changes in this revision

Viewing changes to plugins/mm-modem-option-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-08-07 01:47:27 UTC
  • mfrom: (16.1.3 oneiric)
  • Revision ID: james.westby@ubuntu.com-20110807014727-ssze4jx65jrjltg9
Tags: 0.5-1
debian/rules: override dh_autoreconf in a nicer way so we don't have to
clean up manually afterwards.

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
}
191
191
 
192
192
static gboolean
 
193
ossys_to_mm (char ossys, MMModemGsmAccessTech *out_act)
 
194
{
 
195
    if (ossys == '0') {
 
196
        *out_act = MM_MODEM_GSM_ACCESS_TECH_GPRS;
 
197
        return TRUE;
 
198
    } else if (ossys == '2') {
 
199
        *out_act = MM_MODEM_GSM_ACCESS_TECH_UMTS;
 
200
        return TRUE;
 
201
    } else if (ossys == '3') {
 
202
        *out_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
 
203
        return TRUE;
 
204
    }
 
205
    return FALSE;
 
206
}
 
207
 
 
208
static gboolean
193
209
parse_octi_response (GString *response, MMModemGsmAccessTech *act)
194
210
{
195
211
    MMModemGsmAccessTech cur_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
222
238
    return success;
223
239
}
224
240
 
 
241
static gboolean
 
242
parse_ossys_response (GString *response, MMModemGsmAccessTech *act)
 
243
{
 
244
    MMModemGsmAccessTech cur_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
 
245
    const char *p;
 
246
    GRegex *r;
 
247
    GMatchInfo *match_info;
 
248
    char *str;
 
249
    gboolean success = FALSE;
 
250
 
 
251
    g_return_val_if_fail (act != NULL, FALSE);
 
252
    g_return_val_if_fail (response != NULL, FALSE);
 
253
 
 
254
    p = mm_strip_tag (response->str, "_OSSYS:");
 
255
 
 
256
    r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
 
257
    g_return_val_if_fail (r != NULL, FALSE);
 
258
 
 
259
    g_regex_match (r, p, 0, &match_info);
 
260
    if (g_match_info_matches (match_info)) {
 
261
        str = g_match_info_fetch (match_info, 2);
 
262
        if (str && ossys_to_mm (str[0], &cur_act)) {
 
263
            *act = cur_act;
 
264
            success = TRUE;
 
265
        }
 
266
        g_free (str);
 
267
    }
 
268
    g_match_info_free (match_info);
 
269
    g_regex_unref (r);
 
270
 
 
271
    return success;
 
272
}
 
273
 
225
274
static void
226
275
ossys_octi_request_done (MMAtSerialPort *port,
227
276
                         GString *response,
261
310
    char *str;
262
311
 
263
312
    str = g_match_info_fetch (info, 1);
264
 
    if (str) {
265
 
        switch (atoi (str)) {
266
 
        case 0:
267
 
            act = MM_MODEM_GSM_ACCESS_TECH_GPRS;
268
 
            break;
269
 
        case 2:
270
 
            act = MM_MODEM_GSM_ACCESS_TECH_UMTS;
271
 
            break;
272
 
        default:
273
 
            break;
274
 
        }
275
 
    }
 
313
    if (str)
 
314
        ossys_to_mm (str[0], &act);
276
315
    g_free (str);
277
316
 
278
317
    mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act);
408
447
{
409
448
    MMCallbackInfo *info = user_data;
410
449
    MMModemGsmAccessTech octi = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
411
 
    MMModemGsmAccessTech owcti;
 
450
    MMModemGsmAccessTech act;
412
451
 
413
452
    /* If the modem has already been removed, return without
414
453
     * scheduling callback */
417
456
 
418
457
    if (!error) {
419
458
        if (parse_octi_response (response, &octi)) {
420
 
            /* If no 3G tech yet or current tech isn't 3G, then 2G tech is the best */
421
 
            owcti = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "owcti"));
422
 
            if (octi && !owcti)
 
459
            /* If current tech is 2G or unknown then use the more specific
 
460
             * OCTI response.
 
461
             */
 
462
            act = GPOINTER_TO_UINT (mm_callback_info_get_result (info));
 
463
            if (act < MM_MODEM_GSM_ACCESS_TECH_UMTS)
423
464
                mm_callback_info_set_result (info, GUINT_TO_POINTER (octi), NULL);
424
465
        }
425
466
    }
444
485
 
445
486
    if (!error) {
446
487
        p = mm_strip_tag (response->str, "_OWCTI:");
447
 
        if (owcti_to_mm (*p, &owcti)) {
448
 
            /* 3G tech always takes precedence over 2G tech */
449
 
            if (owcti)
450
 
                mm_callback_info_set_result (info, GUINT_TO_POINTER (owcti), NULL);
 
488
        if (owcti_to_mm (*p, &owcti) && owcti)
 
489
            mm_callback_info_set_result (info, GUINT_TO_POINTER (owcti), NULL);
 
490
    }
 
491
 
 
492
    mm_callback_info_chain_complete_one (info);
 
493
}
 
494
 
 
495
static void
 
496
get_act_ossys_request_done (MMAtSerialPort *port,
 
497
                            GString *response,
 
498
                            GError *error,
 
499
                            gpointer user_data)
 
500
{
 
501
    MMCallbackInfo *info = user_data;
 
502
    MMModemGsmAccessTech ossys = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
 
503
    gboolean check_2g = TRUE, check_3g = TRUE;
 
504
 
 
505
    /* If the modem has already been removed, return without
 
506
     * scheduling callback */
 
507
    if (mm_callback_info_check_modem_removed (info))
 
508
        return;
 
509
 
 
510
    /* If for some reason the OSSYS request failed, still try to check
 
511
     * explicit 2G/3G mode with OCTI and OWCTI; maybe we'll get something.
 
512
     */
 
513
 
 
514
    if (!error) {
 
515
        /* Response is _OSSYS: <n>,<act> so we must skip the <n> */
 
516
        if (parse_ossys_response (response, &ossys)) {
 
517
            mm_callback_info_set_result (info, GUINT_TO_POINTER (ossys), NULL);
 
518
 
 
519
            /* If the OSSYS response indicated a generic access tech type
 
520
             * then only check for more specific access tech of that type.
 
521
             */
 
522
            if (ossys == MM_MODEM_GSM_ACCESS_TECH_GPRS)
 
523
                check_3g = FALSE;
 
524
            if (ossys == MM_MODEM_GSM_ACCESS_TECH_UMTS)
 
525
                check_2g = FALSE;
451
526
        }
452
527
    }
453
528
 
 
529
    if (check_2g)
 
530
        mm_at_serial_port_queue_command (port, "_OCTI?", 3, get_act_octi_request_done, info);
 
531
    else
 
532
        mm_callback_info_chain_complete_one (info);  /* complete it if it wasn't used */
 
533
 
 
534
    if (check_3g)
 
535
        mm_at_serial_port_queue_command (port, "_OWCTI?", 3, get_act_owcti_request_done, info);
 
536
    else
 
537
        mm_callback_info_chain_complete_one (info);  /* complete it if it wasn't used */
 
538
 
454
539
    mm_callback_info_chain_complete_one (info);
455
540
}
456
541
 
463
548
    MMCallbackInfo *info;
464
549
 
465
550
    info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
466
 
    mm_callback_info_chain_start (info, 2);
 
551
    mm_callback_info_chain_start (info, 3);
467
552
 
468
553
    port = mm_generic_gsm_get_best_at_port (modem, &info->error);
469
554
    if (!port) {
471
556
        return;
472
557
    }
473
558
 
474
 
    mm_at_serial_port_queue_command (port, "_OCTI?", 3, get_act_octi_request_done, info);
475
 
    mm_at_serial_port_queue_command (port, "_OWCTI?", 3, get_act_owcti_request_done, info);
 
559
    mm_at_serial_port_queue_command (port, "_OSSYS?", 3, get_act_ossys_request_done, info);
476
560
}
477
561