uim: support SIM card power-up/down
authorDavid Bauer <mail@david-bauer.net>
Sat, 7 Oct 2023 17:04:10 +0000 (19:04 +0200)
committerDavid Bauer <mail@david-bauer.net>
Tue, 10 Oct 2023 09:33:56 +0000 (11:33 +0200)
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 <mail@david-bauer.net>
commands-uim.c
commands-uim.h

index 68803b4a303c953f8236bb658f9133be0440cb7b..ff01d7b4a6204bb38da0d7286957831bb8c73555 100644 (file)
@@ -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;
+}
index 02a49b11161444872c3bd1e9f7fe5f72d58144ef..191f09c0f96f5a9eadd9845040ad8050623564c6 100644 (file)
  */
 
 #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" \