aboutsummaryrefslogtreecommitdiff
path: root/src/mm-generic-gsm.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-03-16 16:45:32 -0700
committerDan Williams <dcbw@redhat.com>2010-03-16 16:45:32 -0700
commit6266f949ba5e745c385d674b2aa934f42b0fb17c (patch)
tree800a2d285627d3652177dde1b568ed4ee35607d9 /src/mm-generic-gsm.c
parentc18dfa67d81d5a16acf78c2267bccae352fe06c6 (diff)
gsm: fix operator name on Option devices with UCS2 charset
Diffstat (limited to 'src/mm-generic-gsm.c')
-rw-r--r--src/mm-generic-gsm.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index f13a7fff..f888d9d3 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -1408,8 +1408,37 @@ reg_info_updated (MMGenericGsm *self,
}
}
+static void
+convert_operator_from_ucs2 (char **operator)
+{
+ const char *p;
+ char *converted;
+ size_t len;
+
+ g_return_if_fail (operator != NULL);
+ g_return_if_fail (*operator != NULL);
+
+ p = *operator;
+ len = strlen (p);
+
+ /* Len needs to be a multiple of 4 for UCS2 */
+ if ((len < 4) && ((len % 4) != 0))
+ return;
+
+ while (*p) {
+ if (!isxdigit (*p++))
+ return;
+ }
+
+ converted = mm_modem_charset_hex_to_utf8 (*operator, MM_MODEM_CHARSET_UCS2);
+ if (converted) {
+ g_free (*operator);
+ *operator = converted;
+ }
+}
+
static char *
-parse_operator (const char *reply)
+parse_operator (const char *reply, MMModemCharset cur_charset)
{
char *operator = NULL;
@@ -1431,6 +1460,13 @@ parse_operator (const char *reply)
g_regex_unref (r);
}
+ /* Some modems (Option & HSO) return the operator name as a hexadecimal
+ * string of the bytes of the operator name as encoded by the current
+ * character set.
+ */
+ if (operator && (cur_charset == MM_MODEM_CHARSET_UCS2))
+ convert_operator_from_ucs2 (&operator);
+
return operator;
}
@@ -1444,7 +1480,7 @@ read_operator_code_done (MMAtSerialPort *port,
char *oper;
if (!error) {
- oper = parse_operator (response->str);
+ oper = parse_operator (response->str, MM_MODEM_CHARSET_UNKNOWN);
if (oper)
reg_info_updated (self, FALSE, 0, TRUE, oper, FALSE, NULL);
}
@@ -1457,10 +1493,11 @@ read_operator_name_done (MMAtSerialPort *port,
gpointer user_data)
{
MMGenericGsm *self = MM_GENERIC_GSM (user_data);
+ MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
char *oper;
if (!error) {
- oper = parse_operator (response->str);
+ oper = parse_operator (response->str, priv->cur_charset);
if (oper)
reg_info_updated (self, FALSE, 0, FALSE, NULL, TRUE, oper);
}