[OpenWrt-Devel,uqmi] Add command to specify preferred PLMN
diff mbox

Message ID 1421436638-25758-1-git-send-email-s.demeszko@wireless-instruments.com
State Accepted
Headers show

Commit Message

Sławomir Demeszko Jan. 16, 2015, 7:30 p.m. UTC
Signed-off-by: Sławomir Demeszko <s.demeszko@wireless-instruments.com>
---
 commands-nas.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 commands-nas.h |  6 ++++++
 2 files changed, 66 insertions(+)

Comments

Felix Fietkau Jan. 18, 2015, 12:40 a.m. UTC | #1
On 2015-01-16 20:30, Sławomir Demeszko wrote:
> Signed-off-by: Sławomir Demeszko <s.demeszko@wireless-instruments.com>
Applied, thanks.

- Felix

Patch
diff mbox

diff --git a/commands-nas.c b/commands-nas.c
index 831e3f4..33477dd 100644
--- a/commands-nas.c
+++ b/commands-nas.c
@@ -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)
diff --git a/commands-nas.h b/commands-nas.h
index 4a4dace..d2bde7b 100644
--- a/commands-nas.h
+++ b/commands-nas.h
@@ -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" \