[PATCH v2] uqmi: wms - added storage to read text messages

Henrik Ginstmark henrik at ginstmark.se
Tue Mar 15 12:35:46 PDT 2022


Today it's hard coded to read text messages from SIM card.
Not all devices store received text messages in SIM, they store
in me, QMI_WMS_STORAGE_TYPE_NV.
I have added --storage as an argumet available to
--list-messages
--get-message
--delete-message
--get-raw-message

If --storage is omitted default storage is sim, as before.


Signed-off-by: Henrik Ginstmark <henrik at ginstmark.se>
---
 uqmi/src/commands-wms.c | 62 ++++++++++++++++++++++++++---------------
 uqmi/src/commands-wms.h |  5 ++++
 2 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/uqmi/src/commands-wms.c b/uqmi/src/commands-wms.c
index a58fd6a..186c043 100644
--- a/uqmi/src/commands-wms.c
+++ b/uqmi/src/commands-wms.c
@@ -24,6 +24,40 @@
 #define MIN(a,b) (((a)<(b))?(a):(b))
 #define CEILDIV(x,y) (((x) + (y) - 1) / (y))
 
+static struct qmi_wms_list_messages_request lmreq = {
+	QMI_INIT(storage_type, QMI_WMS_STORAGE_TYPE_UIM),
+	QMI_INIT(message_tag, QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ),
+};
+
+static struct qmi_wms_delete_request dmreq = {
+	QMI_INIT(memory_storage, QMI_WMS_STORAGE_TYPE_UIM),
+	QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
+};
+
+static struct qmi_wms_raw_read_request gmreq = {
+	QMI_INIT_SEQUENCE(message_memory_storage_id,
+		.storage_type = QMI_WMS_STORAGE_TYPE_UIM,
+	),
+	QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
+};
+
+
+#define cmd_wms_storage_cb no_cb
+static enum qmi_cmd_result
+cmd_wms_storage_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+	if (strcmp(arg, "sim") == 0) {
+	} else if (strcmp(arg, "me") == 0) {
+		qmi_set_ptr(&lmreq, storage_type, QMI_WMS_STORAGE_TYPE_NV);
+		qmi_set_ptr(&dmreq, memory_storage, QMI_WMS_STORAGE_TYPE_NV);
+		qmi_set_ptr(&gmreq, message_memory_storage_id.storage_type, QMI_WMS_STORAGE_TYPE_NV);
+	} else {
+		uqmi_add_error("Invalid value (sim or me)");
+		return QMI_CMD_EXIT;
+	}
+	return QMI_CMD_DONE;
+}
+
 static void cmd_wms_list_messages_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
 {
 	struct qmi_wms_list_messages_response res;
@@ -41,12 +75,7 @@ static void cmd_wms_list_messages_cb(struct qmi_dev *qmi, struct qmi_request *re
 static enum qmi_cmd_result
 cmd_wms_list_messages_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
 {
-	static struct qmi_wms_list_messages_request mreq = {
-		QMI_INIT(storage_type, QMI_WMS_STORAGE_TYPE_UIM),
-		QMI_INIT(message_tag, QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ),
-	};
-
-	qmi_set_wms_list_messages_request(msg, &mreq);
+	qmi_set_wms_list_messages_request(msg, &lmreq);
 
 	return QMI_CMD_REQUEST;
 }
@@ -292,15 +321,10 @@ cmd_wms_delete_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, str
 		return QMI_CMD_EXIT;
 	}
 
-	static struct qmi_wms_delete_request mreq = {
-		QMI_INIT(memory_storage, QMI_WMS_STORAGE_TYPE_UIM),
-		QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
-	};
-
-	mreq.set.memory_index = 1;
-	mreq.data.memory_index = id;
+	dmreq.set.memory_index = 1;
+	dmreq.data.memory_index = id;
 
-	qmi_set_wms_delete_request(msg, &mreq);
+	qmi_set_wms_delete_request(msg, &dmreq);
 
 	return QMI_CMD_REQUEST;
 }
@@ -443,12 +467,6 @@ error:
 static enum qmi_cmd_result
 cmd_wms_get_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
 {
-	static struct qmi_wms_raw_read_request mreq = {
-		QMI_INIT_SEQUENCE(message_memory_storage_id,
-			.storage_type = QMI_WMS_STORAGE_TYPE_UIM,
-		),
-		QMI_INIT(message_mode, QMI_WMS_MESSAGE_MODE_GSM_WCDMA),
-	};
 	char *err;
 	int id;
 
@@ -458,8 +476,8 @@ cmd_wms_get_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct
 		return QMI_CMD_EXIT;
 	}
 
-	mreq.data.message_memory_storage_id.memory_index = id;
-	qmi_set_wms_raw_read_request(msg, &mreq);
+	gmreq.data.message_memory_storage_id.memory_index = id;
+	qmi_set_wms_raw_read_request(msg, &gmreq);
 
 	return QMI_CMD_REQUEST;
 }
diff --git a/uqmi/src/commands-wms.h b/uqmi/src/commands-wms.h
index e28b97b..03110bc 100644
--- a/uqmi/src/commands-wms.h
+++ b/uqmi/src/commands-wms.h
@@ -20,6 +20,7 @@
  */
 
 #define __uqmi_wms_commands \
+	__uqmi_command(wms_storage, storage, required, CMD_TYPE_OPTION), \
 	__uqmi_command(wms_list_messages, list-messages, no, QMI_SERVICE_WMS), \
 	__uqmi_command(wms_delete_message, delete-message, required, QMI_SERVICE_WMS), \
 	__uqmi_command(wms_get_message, get-message, required, QMI_SERVICE_WMS), \
@@ -31,9 +32,13 @@
 
 #define wms_helptext \
 		"  --list-messages:                  List SMS messages\n" \
+		"    --storage <mem>:                Messages storage (sim (default), me)\n" \
 		"  --delete-message <id>:            Delete SMS message at index <id>\n" \
+		"    --storage <mem>:                Messages storage (sim (default), me)\n" \
 		"  --get-message <id>:               Get SMS message at index <id>\n" \
+		"    --storage <mem>:                Messages storage (sim (default), me)\n" \
 		"  --get-raw-message <id>:           Get SMS raw message contents at index <id>\n" \
+		"    --storage <mem>:                Messages storage (sim (default), me)\n" \
 		"  --send-message <data>:            Send SMS message (use options below)\n" \
 		"    --send-message-smsc <nr>:       SMSC number\n" \
 		"    --send-message-target <nr>:     Destination number (required)\n" \
-- 
2.34.1




More information about the openwrt-devel mailing list