diff mbox series

[uqmi,1/3] uim: add application state to SIM status

Message ID 20231010135845.183016-1-mail@david-bauer.net
State Accepted
Delegated to: David Bauer
Headers show
Series [uqmi,1/3] uim: add application state to SIM status | expand

Commit Message

David Bauer Oct. 10, 2023, 1:58 p.m. UTC
Parse the card application state and report it to the SIM card status
output object.

This is required to detect a card application which is in the failed
(illegal) state.

Signed-off-by: David Bauer <mail@david-bauer.net>
---
 commands-uim.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/commands-uim.c b/commands-uim.c
index 3bd8a74..68803b4 100644
--- a/commands-uim.c
+++ b/commands-uim.c
@@ -59,6 +59,16 @@  static void cmd_uim_get_sim_state_cb(struct qmi_dev *qmi, struct qmi_request *re
 {
 	struct qmi_uim_get_card_status_response res;
 	void * const card_table = blobmsg_open_table(&status, NULL);
+	static const char *card_application_states[] = {
+		[QMI_UIM_CARD_APPLICATION_STATE_UNKNOWN] = "unknown",
+		[QMI_UIM_CARD_APPLICATION_STATE_DETECTED] = "detected",
+		[QMI_UIM_CARD_APPLICATION_STATE_PIN1_OR_UPIN_PIN_REQUIRED] = "pin-required",
+		[QMI_UIM_CARD_APPLICATION_STATE_PUK1_OR_UPIN_PUK_REQUIRED] = "puk-required",
+		[QMI_UIM_CARD_APPLICATION_STATE_CHECK_PERSONALIZATION_STATE] = "check-personalization-state",
+		[QMI_UIM_CARD_APPLICATION_STATE_PIN1_BLOCKED] = "pin1-blocked",
+		[QMI_UIM_CARD_APPLICATION_STATE_ILLEGAL] = "illegal",
+		[QMI_UIM_CARD_APPLICATION_STATE_READY] = "ready",
+	};
 
 	qmi_parse_uim_get_card_status_response(msg, &res);
 
@@ -66,6 +76,7 @@  static void cmd_uim_get_sim_state_cb(struct qmi_dev *qmi, struct qmi_request *re
 		if (res.data.card_status.cards[i].card_state != QMI_UIM_CARD_STATE_PRESENT)
 			continue;
 
+		uint8_t card_application_state;
 		uint8_t pin1_state = res.data.card_status.cards[i].upin_state;
 		uint8_t pin1_retries = res.data.card_status.cards[i].upin_retries;
 		uint8_t puk1_retries = res.data.card_status.cards[i].upuk_retries;
@@ -78,6 +89,8 @@  static void cmd_uim_get_sim_state_cb(struct qmi_dev *qmi, struct qmi_request *re
 			if (res.data.card_status.cards[i].applications[j].type == QMI_UIM_CARD_APPLICATION_TYPE_UNKNOWN)
 				continue;
 
+			card_application_state = pin1_state = res.data.card_status.cards[i].applications[j].state;
+
 			if (!res.data.card_status.cards[i].applications[j].upin_replaces_pin1) {
 				pin1_state = res.data.card_status.cards[i].applications[j].pin1_state;
 				pin1_retries = res.data.card_status.cards[i].applications[j].pin1_retries;
@@ -92,6 +105,10 @@  static void cmd_uim_get_sim_state_cb(struct qmi_dev *qmi, struct qmi_request *re
 			break; /* handle first application only for now */
 		}
 
+		if (card_application_state > QMI_UIM_CARD_APPLICATION_STATE_READY)
+			card_application_state = QMI_UIM_CARD_APPLICATION_STATE_UNKNOWN;
+
+		blobmsg_add_string(&status, "card_application_state", card_application_states[card_application_state]);
 		blobmsg_add_string(&status, "pin1_status", get_pin_status(pin1_state));
 		blobmsg_add_u32(&status, "pin1_verify_tries", pin1_retries);
 		blobmsg_add_u32(&status, "pin1_unlock_tries", puk1_retries);