4e049b143a49b94830ee786e8613148d362f1db5
[project/uqmi.git] / commands-dms.c
1 #include "qmi-message.h"
2
3 static const char *get_pin_status(QmiDmsUimPinStatus status)
4 {
5         static const char *pin_status[] = {
6                 [QMI_DMS_UIM_PIN_STATUS_NOT_INITIALIZED] = "not_initialized",
7                 [QMI_DMS_UIM_PIN_STATUS_ENABLED_NOT_VERIFIED] = "not_verified",
8                 [QMI_DMS_UIM_PIN_STATUS_ENABLED_VERIFIED] = "verified",
9                 [QMI_DMS_UIM_PIN_STATUS_DISABLED] = "disabled",
10                 [QMI_DMS_UIM_PIN_STATUS_BLOCKED] = "blocked",
11                 [QMI_DMS_UIM_PIN_STATUS_PERMANENTLY_BLOCKED] = "permanently_blocked",
12                 [QMI_DMS_UIM_PIN_STATUS_UNBLOCKED] = "unblocked",
13                 [QMI_DMS_UIM_PIN_STATUS_CHANGED] = "changed",
14         };
15         const char *res = "Unknown";
16
17         if (status < ARRAY_SIZE(pin_status) && pin_status[status])
18                 res = pin_status[status];
19
20         return res;
21 }
22
23 static void cmd_dms_get_pin_status_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
24 {
25         struct qmi_dms_uim_get_pin_status_response res;
26
27         qmi_parse_dms_uim_get_pin_status_response(msg, &res);
28         if (res.set.pin1_status) {
29                 printf("pin1_status=%s\n"
30                            "pin1_verify_tries=%d\n"
31                            "pin1_unblock_tries=%d\n",
32                            get_pin_status(res.data.pin1_status.current_status),
33                            res.data.pin1_status.verify_retries_left,
34                            res.data.pin1_status.unblock_retries_left);
35         }
36         if (res.set.pin2_status) {
37                 printf("pin2_status=%s\n"
38                            "pin2_verify_tries=%d\n"
39                            "pin2_unblock_tries=%d\n",
40                            get_pin_status(res.data.pin2_status.current_status),
41                            res.data.pin2_status.verify_retries_left,
42                            res.data.pin2_status.unblock_retries_left);
43         }
44 }
45
46 static enum qmi_cmd_result
47 cmd_dms_get_pin_status_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
48 {
49         qmi_set_dms_uim_get_pin_status_request(msg);
50         return QMI_CMD_REQUEST;
51 }
52
53 static void cmd_dms_verify_pin1_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
54 {
55         struct qmi_dms_uim_verify_pin_response res;
56
57         if (!msg) {
58                 fprintf(stderr, "failed\n");
59                 return;
60         }
61
62         printf("ok\n");
63 }
64
65 static enum qmi_cmd_result
66 cmd_dms_verify_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
67 {
68         struct qmi_dms_uim_verify_pin_request data = {
69                 QMI_INIT_SEQUENCE(info,
70                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN,
71                         .pin = arg
72                 )
73         };
74         qmi_set_dms_uim_verify_pin_request(msg, &data);
75         return QMI_CMD_REQUEST;
76 }
77
78 #define cmd_dms_verify_pin2_cb cmd_dms_verify_pin1_cb
79 static enum qmi_cmd_result
80 cmd_dms_verify_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
81 {
82         struct qmi_dms_uim_verify_pin_request data = {
83                 QMI_INIT_SEQUENCE(info,
84                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN2,
85                         .pin = arg
86                 )
87         };
88         qmi_set_dms_uim_verify_pin_request(msg, &data);
89         return QMI_CMD_REQUEST;
90 }