diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-01-09 13:30:00 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:48 +0100 |
commit | d1cfdd974cefb6ec87d6bc2889320ac8373dd4be (patch) | |
tree | 07ffb52cfd9c44cd8a00ff5caedf988a7d1374b8 /src/mm-modem-helpers.c | |
parent | 070c27701305dfa5c549f072d09785a12d6f03f5 (diff) |
bearer-cdma: when specific RM protocol given to be used, ensure it is supported
If the requested RM protocol is not supported, the CDMA Bearer creation will
fail.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index ded11b03..2262a4b3 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1595,6 +1595,87 @@ mm_cdma_convert_sid (const gchar *sid) return (gint) tmp_sid; } +MMModemCdmaRmProtocol +mm_cdma_get_rm_protocol_from_index (guint index, + GError **error) +{ + guint protocol; + + /* just adding 1 from the index value should give us the enum */ + protocol = index + 1 ; + if (protocol > MM_MODEM_CDMA_RM_PROTOCOL_STU_III) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Unexpected RM protocol index (%u)", + index); + protocol = MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN; + } + + return (MMModemCdmaRmProtocol)protocol; +} + +gboolean +mm_cdma_parse_crm_range_response (const gchar *reply, + MMModemCdmaRmProtocol *min, + MMModemCdmaRmProtocol *max, + GError **error) +{ + gboolean result = FALSE; + GRegex *r; + + + /* Expected reply format is: + * ---> AT+CRM=? + * <--- +CRM: (0-2) + */ + + r = g_regex_new ("\\+CRM:\\s*\\((\\d+)-(\\d+)\\)", + G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, + 0, error); + if (r) { + GMatchInfo *match_info = NULL; + + if (g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, error)) { + gchar *aux; + guint min_val = 0; + guint max_val = 0; + + aux = g_match_info_fetch (match_info, 1); + min_val = (guint) atoi (aux); + g_free (aux); + + aux = g_match_info_fetch (match_info, 2); + max_val = (guint) atoi (aux); + g_free (aux); + + if (min_val == 0 || + max_val == 0 || + min_val >= max_val) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't parse CRM range: " + "Unexpected range of RM protocols (%u,%u)", + min_val, + max_val); + } else { + *min = mm_cdma_get_rm_protocol_from_index (min_val, error); + if (*min != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) { + *max = mm_cdma_get_rm_protocol_from_index (max_val, error); + if (*max != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) + result = TRUE; + } + } + } + + g_match_info_free (match_info); + g_regex_unref (r); + } + + return result; +} + guint mm_count_bits_set (gulong number) { |