uqmi: wms - added storage to read text messages
authorHenrik Ginstmark <henrik@ginstmark.se>
Tue, 15 Mar 2022 19:35:46 +0000 (20:35 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 4 May 2022 00:16:53 +0000 (01:16 +0100)
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.

Reviewed-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Tested-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Henrik Ginstmark <henrik@ginstmark.se>
commands-wms.c
commands-wms.h

index a58fd6a64f31c5f4c7a5e28c7b05e43d44addbbf..186c043058ded0d4fd0abab4376ad8f8305159a7 100644 (file)
 #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;
 }
index e28b97bcd895963c27ff36efd61b907f7464394d..03110bcd26ae9dbb5d09397b9fde8a6ff35de51d 100644 (file)
@@ -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), \
 
 #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" \