Support the power-up and power-down commands for the modem's SIM card.
This allows to reset the SIM card and recover it from an illegal card
application state.

Signed-off-by: David Bauer <m...@david-bauer.net>
---
 commands-uim.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 commands-uim.h |  9 ++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/commands-uim.c b/commands-uim.c
index 68803b4..ff01d7b 100644
--- a/commands-uim.c
+++ b/commands-uim.c
@@ -19,6 +19,8 @@
  * Boston, MA 02110-1301 USA.
  */
 
+static int uim_slot = 0;
+
 #define cmd_uim_verify_pin1_cb no_cb
 static enum qmi_cmd_result
 cmd_uim_verify_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, 
struct qmi_msg *msg, char *arg)
@@ -130,3 +132,53 @@ cmd_uim_get_sim_state_prepare(struct qmi_dev *qmi, struct 
qmi_request *req, stru
        qmi_set_uim_get_card_status_request(msg);
        return QMI_CMD_REQUEST;
 }
+
+#define cmd_uim_slot_cb no_cb
+static enum qmi_cmd_result
+cmd_uim_slot_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) || value < 1 || value > 2) {
+               uqmi_add_error("Invalid UIM-Slot value. Allowed: [1,2]");
+               return QMI_CMD_EXIT;
+       }
+
+       uim_slot = value;
+
+       return QMI_CMD_DONE;
+}
+
+#define cmd_uim_power_off_cb no_cb
+static enum qmi_cmd_result
+cmd_uim_power_off_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct 
qmi_msg *msg, char *arg)
+{
+       struct qmi_uim_power_off_sim_request data = {
+               QMI_INIT(slot, uim_slot)
+       };
+
+       if (!uim_slot) {
+               uqmi_add_error("UIM-Slot not set. Use --uim-slot <slot> to set 
it.");
+               return QMI_CMD_EXIT;
+       }
+
+       qmi_set_uim_power_off_sim_request(msg, &data);
+       return QMI_CMD_REQUEST;
+}
+
+#define cmd_uim_power_on_cb no_cb
+static enum qmi_cmd_result
+cmd_uim_power_on_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct 
qmi_msg *msg, char *arg)
+{
+       struct qmi_uim_power_on_sim_request data = {
+               QMI_INIT(slot, uim_slot)
+       };
+
+       if (!uim_slot) {
+               uqmi_add_error("UIM-Slot not set. Use --uim-slot <slot> to set 
it.");
+               return QMI_CMD_EXIT;
+       }
+
+       qmi_set_uim_power_on_sim_request(msg, &data);
+       return QMI_CMD_REQUEST;
+}
diff --git a/commands-uim.h b/commands-uim.h
index 02a49b1..191f09c 100644
--- a/commands-uim.h
+++ b/commands-uim.h
@@ -20,13 +20,20 @@
  */
 
 #define __uqmi_uim_commands                                                    
                                        \
+       __uqmi_command(uim_slot, uim-slot, required, CMD_TYPE_OPTION), \
        __uqmi_command(uim_verify_pin1, uim-verify-pin1, required, 
QMI_SERVICE_UIM), \
        __uqmi_command(uim_verify_pin2, uim-verify-pin2, required, 
QMI_SERVICE_UIM), \
-       __uqmi_command(uim_get_sim_state, uim-get-sim-state, no, 
QMI_SERVICE_UIM) \
+       __uqmi_command(uim_get_sim_state, uim-get-sim-state, no, 
QMI_SERVICE_UIM), \
+       __uqmi_command(uim_power_off, uim-power-off, no, QMI_SERVICE_UIM), \
+       __uqmi_command(uim_power_on, uim-power-on, no, QMI_SERVICE_UIM) \
 
 
 #define uim_helptext \
                "  --uim-verify-pin1 <pin>:          Verify PIN1 (new 
devices)\n" \
                "  --uim-verify-pin2 <pin>:          Verify PIN2 (new 
devices)\n" \
                "  --uim-get-sim-state:                  Get current SIM 
state\n" \
+               "  --uim-power-off:                  Power off SIM card\n" \
+               "    --uim-slot:                     SIM slot [1-2]\n" \
+               "  --uim-power-on:                   Power on SIM card\n" \
+               "    --uim-slot:                     SIM slot [1-2]\n" \
 
-- 
2.42.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to