From: Felix Fietkau Date: Sun, 17 Feb 2013 14:50:32 +0000 (+0100) Subject: add command for setting network preference X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuqmi.git;a=commitdiff_plain;h=ba83df61a02c582edd655f046d7f714fb7a7b556 add command for setting network preference --- diff --git a/commands-nas.c b/commands-nas.c new file mode 100644 index 0000000..aef2745 --- /dev/null +++ b/commands-nas.c @@ -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 index 0000000..b3e0154 --- /dev/null +++ b/commands-nas.h @@ -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 : Set preferred network mode (Syntax: [,,...])\n" \ + " Available modes: all, lte, umts, gsm, cdma, td-scdma\n" + diff --git a/commands.c b/commands.c index 152b1bc..c0c0584 100644 --- a/commands.c +++ b/commands.c @@ -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] = { \ diff --git a/commands.h b/commands.h index 2b1562a..7854eb5 100644 --- a/commands.h +++ b/commands.h @@ -4,6 +4,7 @@ #include #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 5605da2..7bfaba8 100644 --- 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; }