From f254fc59c710d781eca3ec36e0bff2d8970370fa Mon Sep 17 00:00:00 2001 From: Oskari Lemmela Date: Tue, 25 Jan 2022 20:05:49 +0200 Subject: [PATCH] uqmi: add support for get operating mode Currently only the set operation is supported. Add support for getting the current operating mode. Reviewed-by: Sergey Ryazanov Signed-off-by: Henrik Ginstmark Signed-off-by: Oskari Lemmela --- commands-dms.c | 46 +++++++++++++++++++++++++++++++++------------- commands-dms.h | 2 ++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/commands-dms.c b/commands-dms.c index 954daca..59648fb 100644 --- a/commands-dms.c +++ b/commands-dms.c @@ -27,6 +27,17 @@ static struct { char* puk; } dms_req_data; +const char *oper_modes[] = { + [QMI_DMS_OPERATING_MODE_ONLINE] = "online", + [QMI_DMS_OPERATING_MODE_LOW_POWER] = "low_power", + [QMI_DMS_OPERATING_MODE_FACTORY_TEST] = "factory_test", + [QMI_DMS_OPERATING_MODE_OFFLINE] = "offline", + [QMI_DMS_OPERATING_MODE_RESET] = "reset", + [QMI_DMS_OPERATING_MODE_SHUTTING_DOWN] = "shutting_down", + [QMI_DMS_OPERATING_MODE_PERSISTENT_LOW_POWER] = "persistent_low_power", + [QMI_DMS_OPERATING_MODE_MODE_ONLY_LOW_POWER] = "mode_only_low_power", +}; + static void cmd_dms_get_capabilities_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg) { void *t, *networks; @@ -375,30 +386,39 @@ cmd_dms_reset_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_m return QMI_CMD_REQUEST; } +static void +cmd_dms_get_operating_mode_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg) +{ + struct qmi_dms_get_operating_mode_response res; + + qmi_parse_dms_get_operating_mode_response(msg, &res); + if (res.data.mode < ARRAY_SIZE(oper_modes)) + blobmsg_add_string(&status, NULL, oper_modes[res.data.mode]); + else + blobmsg_add_string(&status, NULL, "unknown"); +} + +static enum qmi_cmd_result +cmd_dms_get_operating_mode_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg) +{ + qmi_set_dms_get_operating_mode_request(msg); + return QMI_CMD_REQUEST; +} + #define cmd_dms_set_operating_mode_cb no_cb static enum qmi_cmd_result cmd_dms_set_operating_mode_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg) { - static const char *modes[] = { - [QMI_DMS_OPERATING_MODE_ONLINE] = "online", - [QMI_DMS_OPERATING_MODE_LOW_POWER] = "low_power", - [QMI_DMS_OPERATING_MODE_FACTORY_TEST] = "factory_test", - [QMI_DMS_OPERATING_MODE_OFFLINE] = "offline", - [QMI_DMS_OPERATING_MODE_RESET] = "reset", - [QMI_DMS_OPERATING_MODE_SHUTTING_DOWN] = "shutting_down", - [QMI_DMS_OPERATING_MODE_PERSISTENT_LOW_POWER] = "persistent_low_power", - [QMI_DMS_OPERATING_MODE_MODE_ONLY_LOW_POWER] = "mode_only_low_power", - }; static struct qmi_dms_set_operating_mode_request sreq = { QMI_INIT(mode, QMI_DMS_OPERATING_MODE_ONLINE), }; int i; - for (i = 0; i < ARRAY_SIZE(modes); i++) { - if (!modes[i]) + for (i = 0; i < ARRAY_SIZE(oper_modes); i++) { + if (!oper_modes[i]) continue; - if (strcmp(arg, modes[i]) != 0) + if (strcmp(arg, oper_modes[i]) != 0) continue; sreq.data.mode = i; diff --git a/commands-dms.h b/commands-dms.h index eea8308..68c004a 100644 --- a/commands-dms.h +++ b/commands-dms.h @@ -37,6 +37,7 @@ __uqmi_command(dms_get_imsi, get-imsi, no, QMI_SERVICE_DMS), \ __uqmi_command(dms_get_imei, get-imei, no, QMI_SERVICE_DMS), \ __uqmi_command(dms_get_msisdn, get-msisdn, no, QMI_SERVICE_DMS), \ + __uqmi_command(dms_get_operating_mode, get-device-operating-mode, no, QMI_SERVICE_DMS), \ __uqmi_command(dms_set_operating_mode, set-device-operating-mode, required, QMI_SERVICE_DMS), \ __uqmi_command(dms_reset, reset-dms, no, QMI_SERVICE_DMS), \ __uqmi_command(dms_set_fcc_authentication, fcc-auth, no, QMI_SERVICE_DMS) \ @@ -67,6 +68,7 @@ " --get-imei: Get International Mobile Equipment ID\n" \ " --get-msisdn: Get the MSISDN (telephone number)\n" \ " --reset-dms: Reset the DMS service\n" \ + " --get-device-operating-mode Get the device operating mode\n" \ " --set-device-operating-mode Set the device operating mode\n" \ " (modes: online, low_power, factory_test, offline\n" \ " reset, shutting_down, persistent_low_power,\n" \ -- 2.30.2