[PATCH v2 1/3] drivers: simcommodem: create rat to radio_access_mode function

Sean Nyekjaer <[email protected]>
Newsgroups dev.linux.lists.ofono
Message-ID <[email protected]>
This is done in preparation for querying available rat modes
---
Changes since v1:
 - fixed function name
 - changed mode variable to int, to allow negative numbers

 drivers/simcommodem/radio-settings.c | 47 +++++++++++++++++-----------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/drivers/simcommodem/radio-settings.c b/drivers/simcommodem/radio-settings.c
index 0feba960..bf78c748 100644
--- a/drivers/simcommodem/radio-settings.c
+++ b/drivers/simcommodem/radio-settings.c
@@ -33,13 +33,36 @@ struct radio_settings_data {
 	GAtChat *chat;
 };
 
+static int cnmp_mode_to_radio_access_mode(int r_mode)
+{
+	int mode;
+
+	switch (r_mode) {
+	case 2:
+		mode = OFONO_RADIO_ACCESS_MODE_ANY;
+		break;
+	case 13:
+		mode = OFONO_RADIO_ACCESS_MODE_GSM;
+		break;
+	case 14:
+		mode = OFONO_RADIO_ACCESS_MODE_UMTS;
+		break;
+	case 38:
+		mode = OFONO_RADIO_ACCESS_MODE_LTE;
+		break;
+	default:
+		return -1;
+	}
+
+	return mode;
+}
+
 static void cnmp_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct cb_data *cbd = user_data;
 	ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb;
-	unsigned int mode;
 	struct ofono_error error;
-	int r_mode;
+	int r_mode, mode;
 	GAtResultIter iter;
 
 	DBG("ok %d", ok);
@@ -61,23 +84,9 @@ static void cnmp_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
 	DBG("r_mode %d", r_mode);
 
-	switch (r_mode) {
-	case 2:
-		mode = OFONO_RADIO_ACCESS_MODE_ANY;
-		break;
-	case 13:
-		mode = OFONO_RADIO_ACCESS_MODE_GSM;
-		break;
-	case 14:
-		mode = OFONO_RADIO_ACCESS_MODE_UMTS;
-		break;
-	case 38:
-		mode = OFONO_RADIO_ACCESS_MODE_LTE;
-		break;
-	default:
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		return;
-	}
+	mode = cnmp_mode_to_radio_access_mode(r_mode);
+	if (mode < 0)
+		goto error;
 
 	cb(&error, mode, cbd->data);
 
-- 
2.46.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.