nas: add decoding of cell_id
[project/uqmi.git] / commands-dms.c
index 668c78f2615b4bec900f9ee741387a920032ed52..59648fb9e8a94d3499648cc6c6c14cb520593c28 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * uqmi -- tiny QMI support implementation
+ *
+ * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
 #include "qmi-message.h"
 
 static struct {
@@ -7,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;
@@ -60,7 +91,7 @@ cmd_dms_get_capabilities_prepare(struct qmi_dev *qmi, struct qmi_request *req, s
        return QMI_CMD_REQUEST;
 }
 
-static const char *get_pin_status(int status)
+const char *get_pin_status(int status)
 {
        static const char *pin_status[] = {
                [QMI_DMS_UIM_PIN_STATUS_NOT_INITIALIZED] = "not_initialized",
@@ -355,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;
@@ -388,3 +428,11 @@ cmd_dms_set_operating_mode_prepare(struct qmi_dev *qmi, struct qmi_request *req,
 
        return uqmi_add_error("Invalid argument");
 }
+
+#define cmd_dms_set_fcc_authentication_cb no_cb
+static enum qmi_cmd_result
+cmd_dms_set_fcc_authentication_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+       qmi_set_dms_set_fcc_authentication_request(msg);
+       return QMI_CMD_REQUEST;
+}