All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonas Bonn <jonas@norrbonn.se>
To: ofono@ofono.org
Subject: [PATCH 07/14] ublox: query USBCONF for applicable devices
Date: Tue, 12 Mar 2019 12:10:01 +0100	[thread overview]
Message-ID: <20190312111008.29258-8-jonas@norrbonn.se> (raw)
In-Reply-To: <20190312111008.29258-1-jonas@norrbonn.se>

[-- Attachment #1: Type: text/plain, Size: 4039 bytes --]

The TOBY L2 series of modems presents a number of different
configurations with different throughtput characteristics.  These
configurations are packaged up as USB profiles; moreover, changing the
profile actually changes the USB model ID so this is even more like
selecting a different "device" altogether.  Nonetheless, all we need to
know is which profile is selected in order to set things up correctly
and this can be queried directly.

This patch adds a call to UUSBCONF for applicable modems in order to
query the USB configuration to find out which profile is active.
---
 plugins/ublox.c | 82 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 59 insertions(+), 23 deletions(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index efb0afbc..f7c2a374 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -46,6 +46,7 @@
 
 #include <drivers/ubloxmodem/ubloxmodem.h>
 
+static const char *uusbconf_prefix[] = { "+UUSBCONF:", NULL };
 static const char *none_prefix[] = { NULL };
 
 enum supported_models {
@@ -155,6 +156,57 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_modem_set_powered(modem, TRUE);
 }
 
+static void query_usbconf_cb(gboolean ok, GAtResult *result, gpointer user_data){
+	struct ofono_modem* modem = user_data;
+	struct ublox_data *data = ofono_modem_get_data(modem);
+	GAtResultIter iter;
+	int profile;
+
+	if (!ok) {
+		ofono_error("Unable to query USB configuration");
+		goto error;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+retry:
+	if (!g_at_result_iter_next(&iter, "+UUSBCONF")) {
+		ofono_error("Unable to query USB configuration");
+		goto error;
+	}
+
+	if (!g_at_result_iter_next_number(&iter, &profile))
+		goto retry;
+
+	switch (profile) {
+	case 0: /* Fairly back compatible */
+	case 1: /* Fairly back compatible plus audio */
+		data->model_id =  TOBYL2_COMPATIBLE_MODE;
+		break;
+	case 2: /* Low/medium throughput */
+		data->model_id = TOBYL2_MEDIUM_THROUGHPUT_MODE;
+		break;
+	case 3: /* High throughput mode */
+		data->model_id = TOBYL2_HIGH_THROUGHPUT_MODE;
+		break;
+	default:
+		ofono_error("Unexpected USB profile: %d", profile);
+		goto error;
+	}
+
+	if (g_at_chat_send(data->aux, "AT+CFUN=4", none_prefix,
+					cfun_enable, modem, NULL))
+		return;
+
+error:
+	g_at_chat_unref(data->aux);
+	data->aux = NULL;
+	g_at_chat_unref(data->modem);
+	data->modem = NULL;
+	ofono_modem_set_powered(modem, FALSE);
+}
+
+
 static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem* modem = user_data;
@@ -162,7 +214,6 @@ static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	struct ofono_error error;
 	const char *model;
 	const struct ublox_model* m;
-	const char* model_str;
 
 	decode_at_error(&error, g_at_result_final_response(result));
 
@@ -184,28 +235,13 @@ static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
 	DBG("Model: %s", data->model->name);
 
-	if (data->model->flags & UBLOX_F_TOBY_L2) {
-		model_str = ofono_modem_get_string(modem, "Model");
-		if (!model_str)
-			goto fail;
-
-		/*
-		 * Toby L2 devices are more complex and special than previously
-		 * supported U-Blox devices. So they need a vendor of their own.
-		 */
-		data->model_id = atoi(model_str);
-
-		switch (data->model_id) {
-		case TOBYL2_COMPATIBLE_MODE:
-		case TOBYL2_HIGH_THROUGHPUT_MODE:
-			break;
-		case TOBYL2_MEDIUM_THROUGHPUT_MODE:
-			DBG("low/medium throughtput profile unsupported");
-			break;
-		default:
-			DBG("unknown ublox model id %d", data->model_id);
-			goto fail;
-		}
+	if (data->model->flags & UBLOX_F_HAVE_USBCONF) {
+		if (g_at_chat_send(data->aux, "AT+UUSBCONF?", uusbconf_prefix,
+					query_usbconf_cb, modem, NULL))
+			return;
+
+		ofono_error("Unable to query USB configuration");
+		goto fail;
 	} else {
 		data->vendor_family = OFONO_VENDOR_UBLOX;
 	}
-- 
2.19.1


  parent reply	other threads:[~2019-03-12 11:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-12 11:09 [PATCH 00/14] ublox patches Jonas Bonn
2019-03-12 11:09 ` [PATCH 01/14] Fix whitespace weirdness Jonas Bonn
2019-03-13 18:14   ` Denis Kenzior
2019-03-12 11:09 ` [PATCH 02/14] ublox: drop vendor type for Toby L2 model Jonas Bonn
2019-03-13 18:21   ` Denis Kenzior
2019-03-12 11:09 ` [PATCH 03/14] ublox: make device selection more flexible Jonas Bonn
2019-03-13 18:43   ` Denis Kenzior
2019-03-12 11:09 ` [PATCH 04/14] ublox: create model data structures Jonas Bonn
2019-03-13 18:48   ` Denis Kenzior
2019-03-12 11:09 ` [PATCH 05/14] ublox: query device model Jonas Bonn
2019-03-13 18:37   ` Denis Kenzior
2019-03-13 20:24     ` Jonas Bonn
2019-03-12 11:10 ` [PATCH 06/14] ublox: add model flag HAVE_USBCONF Jonas Bonn
2019-03-12 11:10 ` Jonas Bonn [this message]
2019-03-12 11:10 ` [PATCH 08/14] udevng: ublox: Model string no longer used Jonas Bonn
2019-03-12 11:10 ` [PATCH 09/14] ublox: add device flags Jonas Bonn
2019-03-12 11:10 ` [PATCH 10/14] ublox: add TOBY L4 models Jonas Bonn
2019-03-12 11:10 ` [PATCH 11/14] udevng: detect ublox TOBY L4 Jonas Bonn
2019-03-12 11:10 ` [PATCH 12/14] Separate ATE and AT+CMEE commands Jonas Bonn
2019-03-12 11:10 ` [PATCH 13/14] ublox: extend LTE driver Jonas Bonn
2019-03-12 11:10 ` [PATCH 14/14] ublox: pass model id to LTE plugin Jonas Bonn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190312111008.29258-8-jonas@norrbonn.se \
    --to=jonas@norrbonn.se \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.