From 9a9019a34251c2505068a52c6acf50bfa939092d Mon Sep 17 00:00:00 2001 From: Henrik Ginstmark Date: Tue, 15 Mar 2022 20:35:46 +0100 Subject: [PATCH] uqmi: wms - added storage to read text messages 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 Tested-by: Daniel Golle Signed-off-by: Henrik Ginstmark --- commands-wms.c | 62 ++++++++++++++++++++++++++++++++------------------ commands-wms.h | 5 ++++ 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/commands-wms.c b/commands-wms.c index a58fd6a..186c043 100644 --- a/commands-wms.c +++ b/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/commands-wms.h b/commands-wms.h index e28b97b..03110bc 100644 --- a/commands-wms.h +++ b/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 : Messages storage (sim (default), me)\n" \ " --delete-message : Delete SMS message at index \n" \ + " --storage : Messages storage (sim (default), me)\n" \ " --get-message : Get SMS message at index \n" \ + " --storage : Messages storage (sim (default), me)\n" \ " --get-raw-message : Get SMS raw message contents at index \n" \ + " --storage : Messages storage (sim (default), me)\n" \ " --send-message : Send SMS message (use options below)\n" \ " --send-message-smsc : SMSC number\n" \ " --send-message-target : Destination number (required)\n" \ -- 2.30.2