nas: add --set-network-preference
[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                 blobmsg_add_string(&status, "pin1_status", get_pin_status(res.data.pin1_status.current_status));
30                 blobmsg_add_u32(&status, "pin1_verify_tries", (int32_t) res.data.pin1_status.verify_retries_left);
31                 blobmsg_add_u32(&status, "pin1_unblock_tries", (int32_t) res.data.pin1_status.unblock_retries_left);
32         }
33         if (res.set.pin2_status) {
34                 blobmsg_add_string(&status, "pin2_status", get_pin_status(res.data.pin2_status.current_status));
35                 blobmsg_add_u32(&status, "pin2_verify_tries", (int32_t) res.data.pin2_status.verify_retries_left);
36                 blobmsg_add_u32(&status, "pin2_unblock_tries", (int32_t) res.data.pin2_status.unblock_retries_left);
37         }
38 }
39
40 static enum qmi_cmd_result
41 cmd_dms_get_pin_status_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
42 {
43         qmi_set_dms_uim_get_pin_status_request(msg);
44         return QMI_CMD_REQUEST;
45 }
46
47 #define cmd_dms_verify_pin1_cb no_cb
48 static enum qmi_cmd_result
49 cmd_dms_verify_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
50 {
51         struct qmi_dms_uim_verify_pin_request data = {
52                 QMI_INIT_SEQUENCE(info,
53                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN,
54                         .pin = arg
55                 )
56         };
57         qmi_set_dms_uim_verify_pin_request(msg, &data);
58         return QMI_CMD_REQUEST;
59 }
60
61 #define cmd_dms_verify_pin2_cb no_cb
62 static enum qmi_cmd_result
63 cmd_dms_verify_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
64 {
65         struct qmi_dms_uim_verify_pin_request data = {
66                 QMI_INIT_SEQUENCE(info,
67                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN2,
68                         .pin = arg
69                 )
70         };
71         qmi_set_dms_uim_verify_pin_request(msg, &data);
72         return QMI_CMD_REQUEST;
73 }
74
75 static void cmd_dms_get_imsi_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
76 {
77         struct qmi_dms_uim_get_imsi_response res;
78
79         qmi_parse_dms_uim_get_imsi_response(msg, &res);
80         if (res.data.imsi)
81                 blobmsg_add_string(&status, "number", res.data.imsi);
82 }
83
84 static enum qmi_cmd_result
85 cmd_dms_get_imsi_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
86 {
87         qmi_set_dms_uim_get_imsi_request(msg);
88         return QMI_CMD_REQUEST;
89 }