Unexpected COPS format
Colin Helliwell
colin.helliwell at ln-systems.com
Mon Mar 20 08:17:10 UTC 2017
> On 17 March 2017 at 19:56 Aleksander Morgado <aleksander at aleksander.es> wrote:
>
> On Fri, Mar 17, 2017 at 6:40 PM, Dan Williams <dcbw at redhat.com> wrote:
>
> > I ended up with something like:
> >
> > void
> > mm_3gpp_normalize_operator_id (gchar **id,
> > MMModemCharset cur_charset)
> > {
> > g_assert (id);
> >
> > /* Some modems return the operator name as a hexadecimal string of the
> >
> > * bytes of the operator name as encoded by the current character set.
> > */
> >
> > if (*id && !mm_3gpp_parse_operator_id (id, NULL, NULL, NULL)) {
> > *id = mm_charset_take_and_convert_to_utf8 (*id, cur_charset);
> > if (!mm_3gpp_parse_operator_id (id, NULL, NULL, NULL))
> > g_clear_pointer (id, g_free);
> > }
> > }
> >
> > but didn't get as far as writing testcases for it in src/tests/test-
> > modem-helpers.c. Testcases would be great, obviously.
>
> This would be very similar to mm_3gpp_normalize_operator_name()
> already; maybe we could just have a single method for both?
>
Happy to submit the patch below. Unsure about a testcase - I'm cross-building for a different target and haven't looked at building native and running tests. If it helps, the modem is giving
'+COPS: 0,2,"00320033003400310030",2'
for '23410'
> Colin, what's the AT+CSCS? return value that you're getting before any
> of this happens? Are you getting it reported as UCS2?
>
The CSCS exchanges are:
--> 'AT+CSCS=?<CR>'
<-- '<CR><LF>+CSCS: ("GSM","UCS2")<CR><LF>'
<-- '<CR><LF>OK<CR><LF>'
--> 'AT+CSCS="UCS2"<CR>'
<-- '<CR><LF>OK<CR><LF>'
--> 'AT+CSCS?<CR>'
<-- '<CR><LF>+CSCS: "UCS2"<CR><LF>'
<-- '<CR><LF>OK<CR><LF>'
diff -Nur a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
--- a/src/mm-broadband-modem.c 2017-03-20 06:36:45.210171801 +0000
+++ b/src/mm-broadband-modem.c 2017-03-20 07:12:16.865399207 +0000
@@ -3484,7 +3484,9 @@
error))
return NULL;
- mm_dbg ("loaded Operator Code: %s", operator_code);
+ mm_3gpp_normalize_operator_string (&operator_code, MM_BROADBAND_MODEM (self)->priv->modem_current_charset);
+ if (operator_code)
+ mm_dbg ("loaded Operator Code: %s", operator_code);
return operator_code;
}
@@ -3525,7 +3527,7 @@
error))
return NULL;
- mm_3gpp_normalize_operator_name (&operator_name, MM_BROADBAND_MODEM (self)->priv->modem_current_charset);
+ mm_3gpp_normalize_operator_string (&operator_name, MM_BROADBAND_MODEM (self)->priv->modem_current_charset);
if (operator_name)
mm_dbg ("loaded Operator Name: %s", operator_name);
return operator_name;
diff -Nur a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
--- a/src/mm-modem-helpers.c 2017-03-20 06:36:44.890171799 +0000
+++ b/src/mm-modem-helpers.c 2017-03-20 08:00:34.426196108 +0000
@@ -2980,12 +2980,12 @@
/*************************************************************************/
void
-mm_3gpp_normalize_operator_name (gchar **operator,
- MMModemCharset cur_charset)
+mm_3gpp_normalize_operator_string (gchar **operator_string,
+ MMModemCharset cur_charset)
{
- g_assert (operator);
+ g_assert (operator_string);
- if (*operator == NULL)
+ if (*operator_string == NULL)
return;
/* Some modems (Option & HSO) return the operator name as a hexadecimal
@@ -2994,19 +2994,19 @@
*/
if (cur_charset == MM_MODEM_CHARSET_UCS2) {
/* In this case we're already checking UTF-8 validity */
- *operator = mm_charset_take_and_convert_to_utf8 (*operator, MM_MODEM_CHARSET_UCS2);
+ *operator_string = mm_charset_take_and_convert_to_utf8 (*operator_string, MM_MODEM_CHARSET_UCS2);
}
/* Ensure the operator name is valid UTF-8 so that we can send it
* through D-Bus and such.
*/
- else if (!g_utf8_validate (*operator, -1, NULL))
- g_clear_pointer (operator, g_free);
+ else if (!g_utf8_validate (*operator_string, -1, NULL))
+ g_clear_pointer (operator_string, g_free);
/* Some modems (Novatel LTE) return the operator name as "Unknown" when
* it fails to obtain the operator name. Return NULL in such case.
*/
- if (*operator && g_ascii_strcasecmp (*operator, "unknown") == 0)
- g_clear_pointer (operator, g_free);
+ if (*operator_string && g_ascii_strcasecmp (*operator_string, "unknown") == 0)
+ g_clear_pointer (operator_string, g_free);
}
/*************************************************************************/
diff -Nur a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
--- a/src/mm-modem-helpers.h 2017-03-20 06:36:44.890171799 +0000
+++ b/src/mm-modem-helpers.h 2017-03-20 08:01:06.514196263 +0000
@@ -291,8 +291,8 @@
MMModemAccessTechnology mm_string_to_access_tech (const gchar *string);
-void mm_3gpp_normalize_operator_name (gchar **operator,
- MMModemCharset cur_charset);
+void mm_3gpp_normalize_operator_string (gchar **operator_string,
+ MMModemCharset cur_charset);
gboolean mm_3gpp_parse_operator_id (const gchar *operator_id,
guint16 *mcc,
More information about the ModemManager-devel
mailing list