From 744299c9ba0a57fa4839d71cec997f6c58ebf453 Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakobols@kth.se>
Date: Mon, 11 Jun 2018 11:18:02 +0200
Subject: [PATCH] added get_pin_status to wrapper, some related changes

---
 common.c                |  4 ++--
 common.h                |  2 +-
 dongle_infrastructure.c |  3 ++-
 libmobile_wrapper.c     | 10 ++++++++++
 libmobile_wrapper.h     |  1 +
 5 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/common.c b/common.c
index b4a0b8e..1d44ec3 100644
--- a/common.c
+++ b/common.c
@@ -152,13 +152,13 @@ fail:
 	return -1;
 }
 
-int pin_status(struct blob_buf *bb, char *ip_addr)
+int pin_status(struct blob_buf *bb, struct device *dev)
 {
 	struct json_object *response, *rv_json;
 	const char *rv;
 	int pin_status;
 
-	response = mobile_get_pin_status_zte(ip_addr);
+	response = mobile_get_pin_status(dev);
 	if (!response) {
 		debug_print("no response from get_pin_status!\n");
 		goto fail_response;
diff --git a/common.h b/common.h
index d96ebcf..7a7b6ad 100644
--- a/common.h
+++ b/common.h
@@ -80,6 +80,6 @@ struct json_object *xml_to_json_converter(struct write_result *result);
 int isdigits(const char *pin);
 int validate_puk_format(char *puk);
 int validate_pin_format(char *pin);
-int pin_status(struct blob_buf *bb, char *ip_addr);
+int pin_status(struct blob_buf *bb, struct device *dev);
 int check_response(struct json_object *response);
 #endif
diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c
index 6277856..33f40a2 100644
--- a/dongle_infrastructure.c
+++ b/dongle_infrastructure.c
@@ -126,13 +126,14 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj,
 		goto fail_input;
 	}
 	pin = (char *)blobmsg_data(tb[PIN]);
+
 	rv = validate_pin_format(pin);
 	if (rv < 0) {
 		debug_print("invalid pin format!\n");
 		goto fail_input;
 	}
 
-	if (!pin_status(&bb, global_dev->ip)) {
+	if (!pin_status(&bb, global_dev)) {
 		ubus_send_reply(ctx, req, bb.head);
 		debug_print("pin already disabled!\n");
 		goto disabled;
diff --git a/libmobile_wrapper.c b/libmobile_wrapper.c
index 9232d78..b0a20ce 100644
--- a/libmobile_wrapper.c
+++ b/libmobile_wrapper.c
@@ -179,3 +179,13 @@ struct json_object *mobile_get_roam_status(struct device *dev)
 
 		return NULL;
 }
+
+struct json_object *mobile_get_pin_status(struct device *dev)
+{
+	if (strcmp(dev->usb.if_name, "usb0") == 0)
+		return mobile_get_pin_status_zte(dev->ip);
+	else if (strcmp(dev->usb.if_name, "eth5") == 0)
+		return mobile_get_pin_status_hilink();
+
+	return NULL;
+}
\ No newline at end of file
diff --git a/libmobile_wrapper.h b/libmobile_wrapper.h
index ab20e06..d2dac90 100644
--- a/libmobile_wrapper.h
+++ b/libmobile_wrapper.h
@@ -34,4 +34,5 @@ struct json_object *mobile_set_apn_profile(struct device *dev, char *name);
 struct json_object *mobile_create_apn_profile(struct device *dev, char *profile_name, char *wan_apn, char *pdp_type);
 struct json_object *mobile_get_current_apn(struct device *dev);
 struct json_object *mobile_get_rssi(struct device *dev);
+struct json_object *mobile_get_pin_status(struct device *dev);
 #endif
\ No newline at end of file
-- 
GitLab