Add command to specify preferred PLMN
authorSławomir Demeszko <s.demeszko@wireless-instruments.com>
Fri, 16 Jan 2015 19:30:38 +0000 (20:30 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 18 Jan 2015 00:40:32 +0000 (01:40 +0100)
Signed-off-by: SÅ‚awomir Demeszko <s.demeszko@wireless-instruments.com>
commands-nas.c
commands-nas.h

index 831e3f42290615862235bf20abc412a4593ec75f..33477ddf518483d69e56864d880363ba2fcaac1d 100644 (file)
@@ -1,6 +1,10 @@
 #include "qmi-message.h"
 
 static struct qmi_nas_set_system_selection_preference_request sel_req;
+static struct  {
+       bool mcc_is_set;
+       bool mnc_is_set;
+} plmn_code_flag;
 
 #define cmd_nas_do_set_system_selection_cb no_cb
 static enum qmi_cmd_result
@@ -99,6 +103,62 @@ cmd_nas_set_roaming_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct
        return do_sel_network();
 }
 
+#define cmd_nas_set_mcc_cb no_cb
+static enum qmi_cmd_result
+cmd_nas_set_mcc_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+       char *err;
+       int value = strtoul(arg, &err, 10);
+       if (err && *err) {
+               uqmi_add_error("Invalid MCC value");
+               return QMI_CMD_EXIT;
+       }
+
+       sel_req.data.network_selection_preference.mcc = value;
+       plmn_code_flag.mcc_is_set = true;
+       return QMI_CMD_DONE;
+}
+
+#define cmd_nas_set_mnc_cb no_cb
+static enum qmi_cmd_result
+cmd_nas_set_mnc_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+       char *err;
+       int value = strtoul(arg, &err, 10);
+       if (err && *err) {
+               uqmi_add_error("Invalid MNC value");
+               return QMI_CMD_EXIT;
+       }
+
+       sel_req.data.network_selection_preference.mnc = value;
+       plmn_code_flag.mnc_is_set = true;
+       return QMI_CMD_DONE;
+}
+
+#define cmd_nas_set_plmn_cb no_cb
+static enum qmi_cmd_result
+cmd_nas_set_plmn_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+       sel_req.set.network_selection_preference = 1;
+       sel_req.data.network_selection_preference.mode = QMI_NAS_NETWORK_SELECTION_PREFERENCE_AUTOMATIC;
+
+       if (!plmn_code_flag.mcc_is_set && plmn_code_flag.mnc_is_set) {
+               uqmi_add_error("No MCC value");
+               return QMI_CMD_EXIT;
+       }
+
+       if (plmn_code_flag.mcc_is_set && sel_req.data.network_selection_preference.mcc) {
+               if (!plmn_code_flag.mnc_is_set) {
+                       uqmi_add_error("No MNC value");
+                       return QMI_CMD_EXIT;
+               } else {
+                       sel_req.data.network_selection_preference.mode = QMI_NAS_NETWORK_SELECTION_PREFERENCE_MANUAL;
+               }
+       }
+
+       return do_sel_network();
+}
+
 #define cmd_nas_initiate_network_register_cb no_cb
 static enum qmi_cmd_result
 cmd_nas_initiate_network_register_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
index 4a4dace89bda8f2e9200938c669dbe1952538f90..d2bde7b3dba1fe463599408622b14efe514325f5 100644 (file)
@@ -2,6 +2,9 @@
        __uqmi_command(nas_do_set_system_selection, __set-system-selection, no, QMI_SERVICE_NAS), \
        __uqmi_command(nas_set_network_modes, set-network-modes, required, CMD_TYPE_OPTION), \
        __uqmi_command(nas_initiate_network_register, network-register, no, QMI_SERVICE_NAS), \
+       __uqmi_command(nas_set_plmn, set-plmn, no, QMI_SERVICE_NAS), \
+       __uqmi_command(nas_set_mcc, mcc, required, CMD_TYPE_OPTION), \
+       __uqmi_command(nas_set_mnc, mnc, required, CMD_TYPE_OPTION), \
        __uqmi_command(nas_network_scan, network-scan, no, QMI_SERVICE_NAS), \
        __uqmi_command(nas_get_signal_info, get-signal-info, no, QMI_SERVICE_NAS), \
        __uqmi_command(nas_get_serving_system, get-serving-system, no, QMI_SERVICE_NAS), \
@@ -17,6 +20,9 @@
                "                                    Available modes: any, off, only\n" \
                "  --network-scan:                   Initiate network scan\n" \
                "  --network-register:               Initiate network register\n" \
+               "  --set-plmn:                       Register at specified network\n" \
+               "    --mcc <mcc>:                    Mobile Country Code (0 - auto)\n" \
+               "    --mnc <mnc>:                    Mobile Network Code\n" \
                "  --get-signal-info:                Get signal strength info\n" \
                "  --get-serving-system:             Get serving system info\n" \