diff options
author | Lukas Voegl <lvoegl@tdt.de> | 2024-10-31 15:31:05 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2024-11-20 12:07:20 +0000 |
commit | 32435b430f9803f348db37e455b4db5298db1d8f (patch) | |
tree | c9ce4fb5fb81469b9d9890386e0c4a8563d91d6c /src/plugins/cinterion/mm-modem-helpers-cinterion.c | |
parent | 3de6cca46d83d08126cdf0d355a52639d255954b (diff) |
broadband-modem-cinterion: never discard operator or mode
When setting an operator, AT+COPS overwrites the currently set allowed mode. Equally, the other way around, when setting the current mode, the configured operator is overwritten.
Signed-off-by: Lukas Voegl <lvoegl@tdt.de>
Diffstat (limited to 'src/plugins/cinterion/mm-modem-helpers-cinterion.c')
-rw-r--r-- | src/plugins/cinterion/mm-modem-helpers-cinterion.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/plugins/cinterion/mm-modem-helpers-cinterion.c b/src/plugins/cinterion/mm-modem-helpers-cinterion.c index e429cbc1..52b2baf8 100644 --- a/src/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/src/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1934,3 +1934,71 @@ mm_cinterion_build_sxrat_set_command (MMModemMode allowed, return g_string_free (command, FALSE); } + +static gboolean +modem_mode_to_cops_uint (MMModemMode mode, + guint *out, + GError **error) +{ + switch (mode) { + case MM_MODEM_MODE_2G: + /* 2G-only force GERAN RAT (AcT=0) */ + *out = 0; + break; + case MM_MODEM_MODE_3G: + /* 3G-only force UTRAN RAT (AcT=2) */ + *out = 2; + break; + case MM_MODEM_MODE_4G: + /* 4G-only force E-UTRAN RAT (AcT=7) */ + *out = 7; + break; + case MM_MODEM_MODE_NONE: + case MM_MODEM_MODE_CS: + case MM_MODEM_MODE_5G: + case MM_MODEM_MODE_ANY: + default: + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Cannot use mode '%s' for COPS", + mm_modem_mode_build_string_from_mask (mode)); + return FALSE; + } + + return TRUE; +} + +gboolean +mm_cinterion_build_cops_set_command (MMModemMode mode, + const gchar *operator_code, + gchar **out, + GError **error) +{ + GString *command; + guint cops_mode; + + command = g_string_new ("+COPS="); + + if (!operator_code && mode == MM_MODEM_MODE_ANY) { + /* any operator, any mode */ + g_string_append (command, "0"); + } else { + /* append <mode>,<operator format>,<operator> */ + if (!operator_code) + g_string_append (command, "0,,"); + else + g_string_append_printf (command, "1,2,\"%s\"", operator_code); + + if (mode != MM_MODEM_MODE_ANY) { + /* append <RaT> */ + if (!modem_mode_to_cops_uint (mode, &cops_mode, error)) { + return FALSE; + } + g_string_append_printf (command, ",%u", cops_mode); + } + } + + *out = g_string_free (command, FALSE); + return TRUE; +} |