add command for setting network preference
authorFelix Fietkau <nbd@openwrt.org>
Sun, 17 Feb 2013 14:50:32 +0000 (15:50 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 17 Feb 2013 14:50:32 +0000 (15:50 +0100)
commands-nas.c [new file with mode: 0644]
commands-nas.h [new file with mode: 0644]
commands.c
commands.h
main.c

diff --git a/commands-nas.c b/commands-nas.c
new file mode 100644 (file)
index 0000000..aef2745
--- /dev/null
@@ -0,0 +1,45 @@
+static struct qmi_nas_set_system_selection_preference_request sel_req;
+
+#define cmd_nas_set_network_modes_cb no_cb
+static enum qmi_cmd_result
+cmd_nas_set_network_modes_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+       static const struct {
+               const char *name;
+               QmiNasRatModePreference val;
+       } modes[] = {
+               { "cdma", QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1X | QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1XEVDO },
+               { "td-scdma", QMI_NAS_RAT_MODE_PREFERENCE_TD_SCDMA },
+               { "gsm", QMI_NAS_RAT_MODE_PREFERENCE_GSM },
+               { "umts", QMI_NAS_RAT_MODE_PREFERENCE_UMTS },
+               { "lte", QMI_NAS_RAT_MODE_PREFERENCE_LTE },
+       };
+       QmiNasRatModePreference val = 0;
+       char *word;
+       int i;
+
+       for (word = strtok(arg, ",");
+            word;
+            word = strtok(NULL, ",")) {
+               bool found = false;
+
+               for (i = 0; i < ARRAY_SIZE(modes); i++) {
+                       if (strcmp(word, modes[i].name) != 0 &&
+                               strcmp(word, "all") != 0)
+                               continue;
+
+                       val |= modes[i].val;
+                       found = true;
+               }
+
+               if (!found) {
+                       fprintf(stderr, "Invalid network mode '%s'\n", word);
+                       return QMI_CMD_EXIT;
+               }
+       }
+
+       qmi_set(&sel_req, mode_preference, val);
+       qmi_set_nas_set_system_selection_preference_request(msg, &sel_req);
+       return QMI_CMD_REQUEST;
+}
+
diff --git a/commands-nas.h b/commands-nas.h
new file mode 100644 (file)
index 0000000..b3e0154
--- /dev/null
@@ -0,0 +1,7 @@
+#define __uqmi_nas_commands \
+       __uqmi_command(nas_set_network_modes, set-network-modes, required, QMI_SERVICE_NAS) \
+
+#define nas_helptext \
+               "  --set-network-modes <modes>:      Set preferred network mode (Syntax: <mode1>[,<mode2>,...])\n" \
+               "                                    Available modes: all, lte, umts, gsm, cdma, td-scdma\n"
+
index 152b1bc30cc1e4143337b27167d2a3e968f7caf1..c0c058451a57869560206da9bdd9fab927b89b6b 100644 (file)
@@ -96,6 +96,7 @@ cmd_set_client_id_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct q
 
 #include "commands-wds.c"
 #include "commands-dms.c"
+#include "commands-nas.c"
 
 #define __uqmi_command(_name, _optname, _arg, _type) \
        [__UQMI_COMMAND_##_name] = { \
index 2b1562aa7545d2a91688ce62cbab6761cabebcbb..7854eb549e50564e5423bd809c538a5609312f3d 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include "commands-wds.h"
 #include "commands-dms.h"
+#include "commands-nas.h"
 
 enum qmi_cmd_result {
        QMI_CMD_DONE,
@@ -33,7 +34,8 @@ struct uqmi_cmd {
        __uqmi_command(set_client_id, set-client-id, required, CMD_TYPE_OPTION), \
        __uqmi_command(get_client_id, get-client-id, required, QMI_SERVICE_CTL), \
        __uqmi_wds_commands, \
-       __uqmi_dms_commands
+       __uqmi_dms_commands, \
+       __uqmi_nas_commands
 
 #define __uqmi_command(_name, _optname, _arg, _option) __UQMI_COMMAND_##_name
 enum uqmi_command {
diff --git a/main.c b/main.c
index 5605da21a0e535874db51d6fbce6c1a78e3fdb71..7bfaba875aedee453e424892aa57f348e3d0652d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -40,6 +40,7 @@ static int usage(const char *progname)
                "                                    (implies --keep-client-id)\n"
                wds_helptext
                dms_helptext
+               nas_helptext
                "\n", progname);
        return 1;
 }