summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSławomir Demeszko <s.demeszko@wireless-instruments.com>2014-12-17 13:35:33 +0100
committerFelix Fietkau <nbd@openwrt.org>2014-12-18 13:03:28 +0100
commit34db1f7991934675392c7af9c41c4fe0d8cd64b0 (patch)
tree37c006b408a9e444343372841fa0f443de5bc832
parent695ac858744ee1321582b76d8faaecbe00f79ab7 (diff)
Added shared struct to allow the same option names for different functions
For example we can use one option --new-pin with commands unblock-pin and with change-pin, without that we need to invent new name for every new command. Signed-off-by: SÅ‚awomir Demeszko <s.demeszko@wireless-instruments.com>
-rw-r--r--commands-dms.c64
1 files changed, 39 insertions, 25 deletions
diff --git a/commands-dms.c b/commands-dms.c
index 3a3c394..15cf829 100644
--- a/commands-dms.c
+++ b/commands-dms.c
@@ -1,5 +1,12 @@
#include "qmi-message.h"
+static struct {
+ QmiDmsUimPinId pin_id;
+ char* pin;
+ char* new_pin;
+ char* puk;
+} dms_req_data;
+
static const char *get_pin_status(int status)
{
static const char *pin_status[] = {
@@ -75,24 +82,18 @@ cmd_dms_verify_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct
return QMI_CMD_REQUEST;
}
-static struct qmi_dms_uim_set_pin_protection_request dms_pin_protection_req = {
- QMI_INIT_SEQUENCE(info,
- .pin_id = QMI_DMS_UIM_PIN_ID_PIN
- )
-};
-
#define cmd_dms_set_pin_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_pin_protection_req, info.pin, arg);
+ dms_req_data.pin = arg;
return QMI_CMD_DONE;
}
static enum qmi_cmd_result
cmd_dms_set_pin_protection_prepare(struct qmi_msg *msg, char *arg)
{
- if (!dms_pin_protection_req.data.info.pin) {
+ if (!dms_req_data.pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
@@ -107,7 +108,14 @@ cmd_dms_set_pin_protection_prepare(struct qmi_msg *msg, char *arg)
return QMI_CMD_EXIT;
}
- qmi_set_ptr(&dms_pin_protection_req, info.protection_enabled, is_enabled);
+ struct qmi_dms_uim_set_pin_protection_request dms_pin_protection_req = {
+ QMI_INIT_SEQUENCE(info,
+ .pin_id = dms_req_data.pin_id
+ ),
+ QMI_INIT_PTR(info.pin, dms_req_data.pin),
+ QMI_INIT_PTR(info.protection_enabled, is_enabled)
+ };
+
qmi_set_dms_uim_set_pin_protection_request(msg, &dms_pin_protection_req);
return QMI_CMD_REQUEST;
}
@@ -116,7 +124,7 @@ cmd_dms_set_pin_protection_prepare(struct qmi_msg *msg, char *arg)
static enum qmi_cmd_result
cmd_dms_set_pin1_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_pin_protection_req, info.pin_id, QMI_DMS_UIM_PIN_ID_PIN);
+ dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN;
return cmd_dms_set_pin_protection_prepare(msg, arg);
}
@@ -124,21 +132,15 @@ cmd_dms_set_pin1_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req
static enum qmi_cmd_result
cmd_dms_set_pin2_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_pin_protection_req, info.pin_id, QMI_DMS_UIM_PIN_ID_PIN2);
+ dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN2;
return cmd_dms_set_pin_protection_prepare(msg, arg);
}
-static struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
- QMI_INIT_SEQUENCE(info,
- .pin_id = QMI_DMS_UIM_PIN_ID_PIN
- )
- };
-
#define cmd_dms_set_new_pin_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_new_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_unlock_pin_req, info.new_pin, arg);
+ dms_req_data.new_pin = arg;
return QMI_CMD_DONE;
}
@@ -146,7 +148,7 @@ cmd_dms_set_new_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct
static enum qmi_cmd_result
cmd_dms_set_puk_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_unlock_pin_req, info.puk, arg);
+ dms_req_data.puk = arg;
return QMI_CMD_DONE;
}
@@ -154,13 +156,19 @@ cmd_dms_set_puk_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi
static enum qmi_cmd_result
cmd_dms_unblock_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_unlock_pin_req, info.pin_id, QMI_DMS_UIM_PIN_ID_PIN);
-
- if (!dms_unlock_pin_req.data.info.puk || !dms_unlock_pin_req.data.info.new_pin) {
+ if (!dms_req_data.puk || !dms_req_data.new_pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
+ struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
+ QMI_INIT_SEQUENCE(info,
+ .pin_id = QMI_DMS_UIM_PIN_ID_PIN
+ ),
+ QMI_INIT_PTR(info.puk, dms_req_data.puk),
+ QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
+ };
+
qmi_set_dms_uim_unblock_pin_request(msg, &dms_unlock_pin_req);
return QMI_CMD_REQUEST;
}
@@ -169,13 +177,19 @@ cmd_dms_unblock_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struc
static enum qmi_cmd_result
cmd_dms_unblock_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
- qmi_set_ptr(&dms_unlock_pin_req, info.pin_id, QMI_DMS_UIM_PIN_ID_PIN2);
-
- if (!dms_unlock_pin_req.data.info.puk || !dms_unlock_pin_req.data.info.new_pin) {
+ if (!dms_req_data.puk || !dms_req_data.new_pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
+ struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
+ QMI_INIT_SEQUENCE(info,
+ .pin_id = QMI_DMS_UIM_PIN_ID_PIN2
+ ),
+ QMI_INIT_PTR(info.puk, dms_req_data.puk),
+ QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
+ };
+
qmi_set_dms_uim_unblock_pin_request(msg, &dms_unlock_pin_req);
return QMI_CMD_REQUEST;
}