From 2858f0afce879219dd63cb74340012bffc2115d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C5=82awomir=20Demeszko?= Date: Fri, 16 Jan 2015 20:30:38 +0100 Subject: [PATCH] Add command to specify preferred PLMN MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: SÅ‚awomir Demeszko --- commands-nas.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ commands-nas.h | 6 +++++ 2 files changed, 66 insertions(+) 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 : Mobile Country Code (0 - auto)\n" \ + " --mnc : Mobile Network Code\n" \ " --get-signal-info: Get signal strength info\n" \ " --get-serving-system: Get serving system info\n" \ -- 2.25.1