~clint-fewbar/ubuntu/precise/modemmanager/fix-removed-not-purged

« back to all changes in this revision

Viewing changes to src/mm-modem-helpers.c

  • Committer: Package Import Robot
  • Author(s): Artem Popov
  • Date: 2012-01-02 13:32:18 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120102133218-f2xuil48af71xa7b
Tags: upstream-0.5+git.20111231t174444.1e332ab
ImportĀ upstreamĀ versionĀ 0.5+git.20111231t174444.1e332ab

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * GNU General Public License for more details:
12
12
 *
13
13
 * Copyright (C) 2008 - 2009 Novell, Inc.
14
 
 * Copyright (C) 2009 - 2010 Red Hat, Inc.
 
14
 * Copyright (C) 2009 - 2011 Red Hat, Inc.
15
15
 */
16
16
 
17
17
#include <config.h>
112
112
     *       +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0)
113
113
     */
114
114
 
115
 
    r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, NULL);
 
115
    r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &err);
116
116
    if (err) {
117
 
        g_error ("Invalid regular expression: %s", err->message);
 
117
        mm_err ("Invalid regular expression: %s", err->message);
118
118
        g_error_free (err);
119
119
        g_set_error_literal (error,
120
120
                             MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
125
125
    /* If we didn't get any hits, try the pre-UMTS format match */
126
126
    if (!g_regex_match (r, reply, 0, &match_info)) {
127
127
        g_regex_unref (r);
128
 
        if (match_info) {
129
 
            g_match_info_free (match_info);
130
 
            match_info = NULL;
131
 
        }
 
128
        g_match_info_free (match_info);
 
129
        match_info = NULL;
132
130
 
133
131
        /* Pre-UMTS format doesn't include the cell access technology after
134
132
         * the numeric operator element.
143
141
         *       +COPS: (2,"T - Mobile",,"31026"),(1,"Einstein PCS",,"31064"),(1,"Cingular",,"31041"),,(0,1,3),(0,2)
144
142
         */
145
143
 
146
 
        r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, NULL);
 
144
        r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, &err);
147
145
        if (err) {
148
 
            g_error ("Invalid regular expression: %s", err->message);
 
146
            mm_err ("Invalid regular expression: %s", err->message);
149
147
            g_error_free (err);
150
148
            g_set_error_literal (error,
151
149
                                 MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
247
245
/* '<CR><LF>+CREG: 2,1,000B,2816, B, C2816<CR><LF><CR><LF>OK<CR><LF>' */
248
246
#define CREG7 "\\+(CREG|CGREG):\\s*(\\d{1}),\\s*(\\d{1})\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*[^,\\s]*"
249
247
 
 
248
/* +CREG: <stat>,<lac>,<ci>,<AcT>,<RAC> (ETSI 27.007 v9.20 CREG=2 unsolicited with RAC) */
 
249
#define CREG8 "\\+(CREG|CGREG):\\s*(\\d{1})\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*(\\d{1,2})\\s*,\\s*([^,\\s]*)"
 
250
 
250
251
GPtrArray *
251
252
mm_gsm_creg_regex_get (gboolean solicited)
252
253
{
309
310
    g_assert (regex);
310
311
    g_ptr_array_add (array, regex);
311
312
 
 
313
    /* #8 */
 
314
    if (solicited)
 
315
        regex = g_regex_new (CREG8 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
 
316
    else
 
317
        regex = g_regex_new ("\\r\\n" CREG8 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
 
318
    g_assert (regex);
 
319
    g_ptr_array_add (array, regex);
 
320
 
312
321
    return array;
313
322
}
314
323
 
346
355
    return *valid ? (guint) ret : 0;
347
356
}
348
357
 
 
358
static gboolean
 
359
item_is_lac_not_stat (GMatchInfo *info, guint32 item)
 
360
{
 
361
    char *str;
 
362
    gboolean is_lac = FALSE;
 
363
 
 
364
    /* A <stat> will always be a single digit, without quotes */
 
365
    str = g_match_info_fetch (info, item);
 
366
    g_assert (str);
 
367
    is_lac = (strchr (str, '"') || strlen (str) > 1);
 
368
    g_free (str);
 
369
    return is_lac;
 
370
}
 
371
 
349
372
gboolean
350
373
mm_gsm_parse_creg_response (GMatchInfo *info,
351
374
                            guint32 *out_reg_state,
371
394
    str = g_match_info_fetch (info, 1);
372
395
    if (str && strstr (str, "CGREG"))
373
396
        *out_cgreg = TRUE;
 
397
    g_free (str);
374
398
 
375
399
    /* Normally the number of matches could be used to determine what each
376
400
     * item is, but we have overlap in one case.
392
416
         * CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci>
393
417
         */
394
418
 
395
 
        /* To distinguish, check length of the third match item.  If it's
396
 
         * more than one digit or has quotes in it then it's a LAC and we
397
 
         * got the first format.
398
 
         */
399
 
        str = g_match_info_fetch (info, 3);
400
 
        if (str && (strchr (str, '"') || strlen (str) > 1)) {
401
 
            g_free (str);
 
419
        /* Check if the third item is the LAC to distinguish the two cases */
 
420
        if (item_is_lac_not_stat (info, 3)) {
402
421
            istat = 2;
403
422
            ilac = 3;
404
423
            ici = 4;
409
428
            ici = 5;
410
429
        }
411
430
    } else if (n_matches == 7) {
412
 
        /* CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci>,<AcT> */
413
 
        istat = 3;
414
 
        ilac = 4;
415
 
        ici = 5;
416
 
        iact = 6;
417
 
    }
 
431
        /* CREG=2 (solicited):            +CREG: <n>,<stat>,<lac>,<ci>,<AcT>
 
432
         * CREG=2 (unsolicited with RAC): +CREG: <stat>,<lac>,<ci>,<AcT>,<RAC>
 
433
         */
 
434
 
 
435
        /* Check if the third item is the LAC to distinguish the two cases */
 
436
        if (item_is_lac_not_stat (info, 3)) {
 
437
            istat = 2;
 
438
            ilac = 3;
 
439
            ici = 4;
 
440
            iact = 5;
 
441
        } else {
 
442
            istat = 3;
 
443
            ilac = 4;
 
444
            ici = 5;
 
445
            iact = 6;
 
446
        }
 
447
     }
418
448
 
419
449
    /* Status */
420
450
    str = g_match_info_fetch (info, istat);
778
808
            g_match_info_next (match_info, NULL);
779
809
            success = TRUE;
780
810
        }
781
 
        g_match_info_free (match_info);
782
811
    }
 
812
    g_match_info_free (match_info);
783
813
    g_regex_unref (r);
784
814
 
785
815
    if (success)
855
885
    if (manf)
856
886
        g_string_append (devid, manf);
857
887
 
858
 
    if (!strlen (devid->str))
 
888
    if (!strlen (devid->str)) {
 
889
        g_string_free (devid, TRUE);
859
890
        return NULL;
 
891
    }
860
892
 
861
893
    p = devid->str;
862
894
    msg = g_string_sized_new (strlen (devid->str) + 17);
888
920
    mm_dbg ("Device ID source '%s'", msg->str);
889
921
    mm_dbg ("Device ID '%s'", ret);
890
922
    g_string_free (msg, TRUE);
 
923
    g_string_free (devid, TRUE);
891
924
 
892
925
    return ret;
893
926
}
1020
1053
 
1021
1054
            g_match_info_next (match_info, NULL);
1022
1055
        }
1023
 
        g_match_info_free (match_info);
1024
1056
    }
 
1057
    g_match_info_free (match_info);
1025
1058
    g_regex_unref (r);
1026
1059
 
1027
1060
    return hash;
1086
1119
        g_free (str);
1087
1120
        g_match_info_next (match_info, NULL);
1088
1121
    }
1089
 
    g_match_info_free (match_info);
1090
1122
 
1091
1123
done:
1092
 
    if (r)
1093
 
        g_regex_unref (r);
 
1124
    g_match_info_free (match_info);
 
1125
    g_regex_unref (r);
1094
1126
 
1095
1127
    return array;
1096
1128
}