diff options
author | Eric Shienbrood <ers@chromium.org> | 2011-08-11 13:58:59 -0400 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-11-16 23:41:49 -0600 |
commit | eede5bb621152eb1774495d9cd403b1e653c076c (patch) | |
tree | d8fc5bfcb140e444aba52f8d64d1738d441ccca6 /src/mm-modem-helpers.c | |
parent | e7b6b2dc1c709ae877e3cd472d4134b918bb5fb7 (diff) |
gsm: add new property to track which facility locks are enabled
The property EnabledFacilityLocks on the .Modem.Gsm.Card interface
is a bit mask that indicates which of the various personalization
codes from 3GPP TS 22.022, plus the SIM PIN lock and SIM PIN2 lock,
are enabled. The set of facility locks supported by the modem is
determined at the time the modem is initialized, and the state of
each supported lock (enabled or disabled) is determined. When the
state of a lock changes, a property-change signal is sent out. Note
that ModemManager only supports enabling and disabling SIM-PIN, via
the EnablePin method on Modem.Gsm.Card.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 0bf62378..25e0561d 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -819,6 +819,151 @@ mm_gsm_parse_cscs_support_response (const char *reply, /*************************************************************************/ +/* Map two letter facility codes into flag values. There are + * many more facilities defined (for various flavors of call + * barring); we only map the ones we care about. */ +static MMModemGsmFacility +mm_gsm_string_to_facility (const char *string) +{ + g_return_val_if_fail (string != NULL, MM_MODEM_GSM_FACILITY_NONE); + + if (!strcmp (string, "SC")) + return MM_MODEM_GSM_FACILITY_SIM; + else if (!strcmp (string, "PS")) + return MM_MODEM_GSM_FACILITY_PH_SIM; + else if (!strcmp (string, "PF")) + return MM_MODEM_GSM_FACILITY_PH_FSIM; + else if (!strcmp (string, "FD")) + return MM_MODEM_GSM_FACILITY_FIXED_DIALING; + else if (!strcmp (string, "PN")) + return MM_MODEM_GSM_FACILITY_NET_PERS; + else if (!strcmp (string, "PU")) + return MM_MODEM_GSM_FACILITY_NET_SUB_PERS; + else if (!strcmp (string, "PP")) + return MM_MODEM_GSM_FACILITY_PROVIDER_PERS; + else if (!strcmp (string, "PC")) + return MM_MODEM_GSM_FACILITY_CORP_PERS; + else + return MM_MODEM_GSM_FACILITY_NONE; + +} + +/*************************************************************************/ + +char * +mm_gsm_get_facility_name (MMModemGsmFacility facility) +{ + switch (facility) { + case MM_MODEM_GSM_FACILITY_SIM: + return "SC"; + case MM_MODEM_GSM_FACILITY_PH_SIM: + return "PS"; + case MM_MODEM_GSM_FACILITY_PH_FSIM: + return "PF"; + case MM_MODEM_GSM_FACILITY_FIXED_DIALING: + return "FD"; + case MM_MODEM_GSM_FACILITY_NET_PERS: + return "PN"; + case MM_MODEM_GSM_FACILITY_NET_SUB_PERS: + return "PU"; + case MM_MODEM_GSM_FACILITY_PROVIDER_PERS: + return "PP"; + case MM_MODEM_GSM_FACILITY_CORP_PERS: + return "PC"; + default: + return NULL; + } +} + +gboolean +mm_gsm_parse_clck_test_response (const char *reply, + MMModemGsmFacility *out_facilities) +{ + MMModemGsmFacility facilities = MM_MODEM_GSM_FACILITY_NONE; + GRegex *r; + GMatchInfo *match_info; + char *p, *str; + gboolean success = FALSE; + + g_return_val_if_fail (reply != NULL, FALSE); + g_return_val_if_fail (out_facilities != NULL, FALSE); + + /* the general format is: + * + * +CLCK: ("SC","AO","AI","PN") + */ + p = strchr (reply, '('); + if (p) + p++; + else { + p = strchr (reply, '"'); + if (!p) + return FALSE; + } + + /* Now parse each facility */ + r = g_regex_new ("\\s*\"([^,\\)]+)\"\\s*", 0, 0, NULL); + if (!r) + return FALSE; + + if (g_regex_match_full (r, p, strlen (p), 0, 0, &match_info, NULL)) { + while (g_match_info_matches (match_info)) { + str = g_match_info_fetch (match_info, 1); + if (str) + facilities |= mm_gsm_string_to_facility (str); + g_free (str); + + g_match_info_next (match_info, NULL); + success = TRUE; + } + } + g_match_info_free (match_info); + g_regex_unref (r); + + if (success) + *out_facilities = facilities; + + return success; +} + +gboolean +mm_gsm_parse_clck_response (const char *reply, gboolean *enabled) +{ + GRegex *r; + GMatchInfo *match_info; + char *p, *str; + gboolean success = FALSE; + + g_return_val_if_fail (reply != NULL, FALSE); + g_return_val_if_fail (enabled != NULL, FALSE); + + p = strchr (reply, ':'); + if (p) + p++; + + r = g_regex_new ("\\s*([01])\\s*", 0, 0, NULL); + if (!r) + return FALSE; + + if (g_regex_match (r, p, 0, &match_info)) { + success = TRUE; + str = g_match_info_fetch (match_info, 1); + if (str) { + if (*str == '0') + *enabled = FALSE; + else if (*str == '1') + *enabled = TRUE; + else + success = FALSE; + } + } + g_match_info_free (match_info); + g_regex_unref (r); + return success; +} + +/*************************************************************************/ + MMModemGsmAccessTech mm_gsm_string_to_access_tech (const char *string) { |