diff mbox

[OpenWrt-Devel,uqmi,2/3] Added shared struct to allow the same option names for different functions

Message ID 1418819734-17352-2-git-send-email-s.demeszko@wireless-instruments.com
State Accepted
Headers show

Commit Message

Sławomir Demeszko Dec. 17, 2014, 12:35 p.m. UTC
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>
---
 commands-dms.c | 64 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 39 insertions(+), 25 deletions(-)
diff mbox

Patch

diff --git a/commands-dms.c b/commands-dms.c
index 360e926..76144cf 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;
 }