From 68e725d45e55e842e9a9df9ef47a0fe3a8199f2b Mon Sep 17 00:00:00 2001 From: Lukas Voegl Date: Mon, 4 Nov 2024 12:55:54 +0100 Subject: broadband-modem-cinterion: implement load_current_modes Signed-off-by: Lukas Voegl --- src/plugins/cinterion/mm-modem-helpers-cinterion.c | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/plugins/cinterion/mm-modem-helpers-cinterion.c') diff --git a/src/plugins/cinterion/mm-modem-helpers-cinterion.c b/src/plugins/cinterion/mm-modem-helpers-cinterion.c index 52b2baf8..b2ef89a9 100644 --- a/src/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/src/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1993,6 +1993,7 @@ mm_cinterion_build_cops_set_command (MMModemMode mode, if (mode != MM_MODEM_MODE_ANY) { /* append */ if (!modem_mode_to_cops_uint (mode, &cops_mode, error)) { + g_string_free (command, TRUE); return FALSE; } g_string_append_printf (command, ",%u", cops_mode); @@ -2002,3 +2003,63 @@ mm_cinterion_build_cops_set_command (MMModemMode mode, *out = g_string_free (command, FALSE); return TRUE; } + +gboolean +mm_cinterion_parse_ws46_response (const gchar *response, + MMModemMode *result, + GError **error) +{ + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + guint mode_num; + + r = g_regex_new ("\\+WS46:\\s*(\\d+)", + G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + g_assert (r != NULL); + + if (!g_regex_match (r, response, 0, &match_info)) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Failed to parse WS46 response '%s'", + response); + return FALSE; + } + + if (!mm_get_uint_from_match_info (match_info, 1, &mode_num)) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Failed to get mode from WS46 response '%s'", + response); + return FALSE; + } + + switch (mode_num) { + case 12: + /* GSM digital cellular (GERAN only) */ + *result = MM_MODEM_MODE_2G; + break; + case 22: + /* UTRAN only */ + *result = MM_MODEM_MODE_3G; + break; + case 25: + /* GERAN, UTRAN and E-UTRAN */ + *result = MM_MODEM_MODE_ANY; + break; + case 28: + /* E-UTRAN only */ + *result = MM_MODEM_MODE_4G; + break; + default: + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Unknown WS46 mode '%u'", + mode_num); + return FALSE; + } + + return TRUE; +} -- cgit v1.2.3-70-g09d2