aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-06-02 10:53:43 +0200
committerAleksander Morgado <aleksander@aleksander.es>2017-06-05 14:04:42 +0200
commitd6779b91b23e207beb9591461b25c2201f3831b9 (patch)
tree7b60e601290d439afb3aeb5908a142b8b4f529ae
parent4cd5044bfd5d2394b5001c4c6de63b181b0051bf (diff)
telit: make sure QSS status values read are always known
Given that the MMTelitQssStatus enums are mapped directly to the values read from the #QSS response, we need to make sure that we never return a value for which we don't have an enum defined. Also, use set_error() instead of the propagate_error() + error_new() combo.
-rw-r--r--plugins/telit/mm-modem-helpers-telit.c20
-rw-r--r--plugins/telit/tests/test-mm-modem-helpers-telit.c1
2 files changed, 16 insertions, 5 deletions
diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c
index a58644d1..5a7ecb79 100644
--- a/plugins/telit/mm-modem-helpers-telit.c
+++ b/plugins/telit/mm-modem-helpers-telit.c
@@ -590,6 +590,7 @@ mm_telit_get_band_flags_from_string (const gchar *flag_str,
/*****************************************************************************/
/* #QSS? response parser */
+
MMTelitQssStatus
mm_telit_parse_qss_query (const gchar *response,
GError **error)
@@ -599,11 +600,20 @@ mm_telit_parse_qss_query (const gchar *response,
qss_status = QSS_STATUS_UNKNOWN;
if (sscanf (response, "#QSS: %d,%d", &qss_mode, &qss_status) != 2) {
- g_propagate_error (error,
- g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
- "Could not parse \"#QSS?\" response: %s",
- response));
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Could not parse \"#QSS?\" response: %s", response);
+ return QSS_STATUS_UNKNOWN;
}
- return (MMTelitQssStatus)qss_status;
+ switch (qss_status) {
+ case QSS_STATUS_SIM_REMOVED:
+ case QSS_STATUS_SIM_INSERTED:
+ case QSS_STATUS_SIM_INSERTED_AND_UNLOCKED:
+ case QSS_STATUS_SIM_INSERTED_AND_READY:
+ return (MMTelitQssStatus) qss_status;
+ default:
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Unknown QSS status value given: %d", qss_status);
+ return QSS_STATUS_UNKNOWN;
+ }
}
diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c
index dba635a2..e42467ea 100644
--- a/plugins/telit/tests/test-mm-modem-helpers-telit.c
+++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c
@@ -518,6 +518,7 @@ static QssParseTest qss_parse_tests [] = {
{"#QSS: 0, 3", QSS_STATUS_SIM_INSERTED_AND_READY, NULL},
{"#QSS: 0", QSS_STATUS_UNKNOWN, "Could not parse \"#QSS?\" response: #QSS: 0"},
{"QSS:0,1", QSS_STATUS_UNKNOWN, "Could not parse \"#QSS?\" response: QSS:0,1"},
+ {"#QSS: 0,5", QSS_STATUS_UNKNOWN, "Unknown QSS status value given: 5"},
};
static void