diff mbox series

[05/10] gobi: ensure Set Data Format changes were applied

Message ID 20241121152949.56962-5-denkenz@gmail.com (mailing list archive)
State Under Review
Headers show
Series [01/10] qmi: wda: Add qmi_wda_set_data_format utility | expand

Commit Message

Denis Kenzior Nov. 21, 2024, 3:29 p.m. UTC
Some firmware accept Set Data Format command, but do not actually honor
it.  For example Quectel RM502Q happily accepts being set to 802.3
link-layer protocol, but doesn't actually change it.  Try to detect this
case and handle it appropriately.
---
 plugins/gobi.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/plugins/gobi.c b/plugins/gobi.c
index 87b54ae05f17..321a2ae0bca7 100644
--- a/plugins/gobi.c
+++ b/plugins/gobi.c
@@ -461,6 +461,33 @@  error:
 	shutdown_device(modem);
 }
 
+/*
+ * Some firmware accepts the Set Data Format command successfully, but doesn't
+ * change anything.  Try to detect and warn if that happens
+ */
+static int compare_data_format(struct gobi_data *data, struct qmi_result *result)
+{
+	struct qmi_wda_data_format expected;
+	struct qmi_wda_data_format actual;
+	int r;
+
+	if (!wda_get_data_format(data, &expected))
+		return -EPROTO;
+
+	r = qmi_wda_parse_data_format(result, &actual);
+	if (r < 0)
+		return -EBADMSG;
+
+	if (expected.ll_protocol != actual.ll_protocol ||
+			expected.ul_aggregation_protocol !=
+			actual.ul_aggregation_protocol ||
+			expected.dl_aggregation_protocol !=
+			actual.dl_aggregation_protocol)
+		return -EBADE;
+
+	return 0;
+}
+
 static void set_data_format_cb(struct qmi_result *result, void *user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -473,8 +500,12 @@  static void set_data_format_cb(struct qmi_result *result, void *user_data)
 
 	DBG("");
 
-	if (!qmi_result_set_error(result, NULL))
-		goto done;
+	if (!qmi_result_set_error(result, NULL)) {
+		if (!compare_data_format(data, result))
+			goto done;
+
+		ofono_error("Setting Data Format had no effect");
+	}
 
 	if (data->data_format == WDA_DATA_FORMAT_802_3)
 		goto error;