All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Nguyen <tomirq@earthlink.net>
To: ofono@ofono.org
Subject: [PATCH v2] qmimodem: return all serial numbers
Date: Sat, 28 Sep 2019 01:48:38 +0000	[thread overview]
Message-ID: <2097825122.6387.1555084361605@wamui-cinderella.atl.sa.earthlink.net> (raw)

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

Some modems, eg. Quectel EC25E, return the ESN, IMEI, and MEID even
though they support only one network type in a region. Current serial
number query gives precedence to the ESN if it exists, and does not
consider the IMEI and MEID.

Add a check of the supported radio interfaces in deciding which
serial number to return. If radio interfaces are 3GPP based, then
return the IMEI, else return the ESN. If neither exist, return MEID
if available, else fail.
---
 drivers/qmimodem/devinfo.c | 88 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 75 insertions(+), 13 deletions(-)

diff --git a/drivers/qmimodem/devinfo.c b/drivers/qmimodem/devinfo.c
index af976b7..4722efd 100644
--- a/drivers/qmimodem/devinfo.c
+++ b/drivers/qmimodem/devinfo.c
@@ -36,6 +36,7 @@
 
 struct devinfo_data {
 	struct qmi_service *dms;
+	bool device_is_3gpp;
 };
 
 static void string_cb(struct qmi_result *result, void *user_data)
@@ -116,7 +117,12 @@ static void qmi_query_revision(struct ofono_devinfo *devinfo,
 static void get_ids_cb(struct qmi_result *result, void *user_data)
 {
 	struct cb_data *cbd = user_data;
+	struct ofono_devinfo *devinfo = cbd->user;
+	struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
 	ofono_devinfo_query_cb_t cb = cbd->cb;
+	char *esn;
+	char *imei;
+	char *meid;
 	char *str;
 
 	DBG("");
@@ -126,20 +132,28 @@ static void get_ids_cb(struct qmi_result *result, void *user_data)
 		return;
 	}
 
-	str = qmi_result_get_string(result, QMI_DMS_RESULT_ESN);
-	/* Telit qmi modems return a "0" string when ESN is not available. */
-	if (!str || strcmp(str, "0") == 0) {
-		qmi_free(str);
-		str = qmi_result_get_string(result, QMI_DMS_RESULT_IMEI);
-		if (!str) {
-			CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
-			return;
-		}
-	}
+	esn = qmi_result_get_string(result, QMI_DMS_RESULT_ESN);
+	imei = qmi_result_get_string(result, QMI_DMS_RESULT_IMEI);
+	meid = qmi_result_get_string(result, QMI_DMS_RESULT_MEID);
 
-	CALLBACK_WITH_SUCCESS(cb, str, cbd->data);
+	str = NULL;
 
-	qmi_free(str);
+	if (data->device_is_3gpp && imei && strcmp(imei, "0"))
+		str = imei;
+	else if (esn && strcmp(esn, "0"))
+		str = esn;
+
+	if (str == NULL && meid && strcmp(meid, "0"))
+		str = meid;
+
+	if (str)
+		CALLBACK_WITH_SUCCESS(cb, str, cbd->data);
+	else
+		CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
+
+	qmi_free(esn);
+	qmi_free(imei);
+	qmi_free(meid);
 }
 
 static void qmi_query_serial(struct ofono_devinfo *devinfo,
@@ -150,6 +164,8 @@ static void qmi_query_serial(struct ofono_devinfo *devinfo,
 
 	DBG("");
 
+	cbd->user = (void *) devinfo;
+
 	if (qmi_service_send(data->dms, QMI_DMS_GET_IDS, NULL,
 					get_ids_cb, cbd, g_free) > 0)
 		return;
@@ -159,6 +175,51 @@ static void qmi_query_serial(struct ofono_devinfo *devinfo,
 	g_free(cbd);
 }
 
+static void get_caps_cb(struct qmi_result *result, void *user_data)
+{
+	struct ofono_devinfo *devinfo = user_data;
+	struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
+	const struct qmi_dms_device_caps *caps;
+	uint8_t i;
+
+	DBG("");
+
+	if (qmi_result_set_error(result, NULL))
+		goto error;
+
+	caps = qmi_result_get(result, QMI_DMS_RESULT_DEVICE_CAPS, NULL);
+	if (caps == NULL)
+		goto error;
+
+	data->device_is_3gpp = false;
+
+	for (i = 0; i < caps->radio_if_count; i++) {
+		switch (caps->radio_if[i]) {
+		case QMI_DMS_RADIO_IF_GSM:
+		case QMI_DMS_RADIO_IF_UMTS:
+		case QMI_DMS_RADIO_IF_LTE:
+			data->device_is_3gpp = true;
+			break;
+		}
+	}
+
+error:
+	ofono_devinfo_register(devinfo);
+}
+
+static void qmi_query_caps(struct ofono_devinfo *devinfo)
+{
+	struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
+
+	DBG("");
+
+	if (qmi_service_send(data->dms, QMI_DMS_GET_CAPS, NULL,
+					get_caps_cb, devinfo, NULL) > 0)
+		return;
+
+	ofono_devinfo_register(devinfo);
+}
+
 static void create_dms_cb(struct qmi_service *service, void *user_data)
 {
 	struct ofono_devinfo *devinfo = user_data;
@@ -173,8 +234,9 @@ static void create_dms_cb(struct qmi_service *service, void *user_data)
 	}
 
 	data->dms = qmi_service_ref(service);
+	data->device_is_3gpp = false;
 
-	ofono_devinfo_register(devinfo);
+	qmi_query_caps(devinfo);
 }
 
 static int qmi_devinfo_probe(struct ofono_devinfo *devinfo,
-- 
1.9.1


             reply	other threads:[~2019-09-28  1:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-28  1:48 Tom Nguyen [this message]
2019-04-16 16:52 ` [PATCH v2] qmimodem: return all serial numbers Denis Kenzior

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=2097825122.6387.1555084361605@wamui-cinderella.atl.sa.earthlink.net \
    --to=tomirq@earthlink.net \
    --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.