From be7ad81ab3d326c6590e70bf3970eb1d5e511204 Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakobols@kth.se>
Date: Fri, 8 Jun 2018 12:07:19 +0200
Subject: [PATCH] some more wrapper calls available

---
 dongle.h                |  2 ++
 dongle_infrastructure.c | 18 +++++++++---------
 libmobile_wrapper.c     | 40 ++++++++++++++++++++++++++++++++++++++++
 libmobile_wrapper.h     |  3 +++
 libmobile_zte.c         |  2 +-
 libmobile_zte.h         |  2 +-
 6 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/dongle.h b/dongle.h
index 0e9416c..ce39be6 100644
--- a/dongle.h
+++ b/dongle.h
@@ -1,5 +1,7 @@
 #ifndef DONGLE_H
 #define DONGLE_H
+#include "common.h"
+#include "dongle_infrastructure.h"
 #include "stack_operations.h"
 /*
 struct USB {
diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c
index 0fe8115..1b4e024 100644
--- a/dongle_infrastructure.c
+++ b/dongle_infrastructure.c
@@ -303,7 +303,7 @@ int unlock_sim(struct ubus_context *ctx, struct ubus_object *obj,
 	if (rv < 0)
 		goto fail_input;
 	printf("survived puk format\n");
-	response = mobile_unlock_sim_zte(global_dev->ip, puk, pin);
+	response = mobile_unlock_sim(global_dev->ip, pin, puk);
 	if (!response)
 		goto fail_unknown;
 	printf("did not survive the library\n");
@@ -320,7 +320,7 @@ int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj,
 {
 	struct json_object *response;
 
-	response = mobile_get_apn_profiles_zte(global_dev->ip);
+	response = mobile_get_apn_profiles(global_dev);
 	if (!response)
 		goto fail_unknown;
 
@@ -351,7 +351,7 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
 		goto fail_argument;
 	}
 
-	response = mobile_delete_apn_zte(global_dev->ip, name);
+	response = mobile_delete_apn_profile(global_dev, name);
 	if (!response)
 		goto fail_unknown;
 
@@ -384,7 +384,7 @@ int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
 		goto fail_argument;
 	}
 
-	response = mobile_set_apn_profile_zte(global_dev->ip, name);
+	response = mobile_set_apn_profile(global_dev, name);
 	if (!response)
 		goto fail_unknown;
 
@@ -575,11 +575,11 @@ struct ubus_method dynamic_object_methods[] = {
 	UBUS_METHOD("verify_pin", verify_pin, pin_policy),
 	UBUS_METHOD_NOARG("remaining_tries", remaining_tries),
 	UBUS_METHOD("unlock_sim", unlock_sim, unlock_policy),
-	UBUS_METHOD_NOARG("list", list_apn_profiles),  //apn
-	UBUS_METHOD("create", create_apn_profile, create_apn_policy),
-	UBUS_METHOD("delete", delete_apn_profile, apn_policy),
-	UBUS_METHOD("set_profile", set_apn_profile, apn_policy),
-	UBUS_METHOD_NOARG("current", show_current_apn),
+	UBUS_METHOD_NOARG("list_apn_profiles", list_apn_profiles),  //apn
+	UBUS_METHOD("create_apn_profiles", create_apn_profile, create_apn_policy),
+	UBUS_METHOD("delete_apn_profile", delete_apn_profile, apn_policy),
+	UBUS_METHOD("set_apn_profile", set_apn_profile, apn_policy),
+	UBUS_METHOD_NOARG("current_apn_profile", show_current_apn),
 	UBUS_METHOD_NOARG("signal_strength", get_signal_strength),  //network..
 	UBUS_METHOD_NOARG("connect", connect_network),
 	UBUS_METHOD_NOARG("disconnect", disconnect),
diff --git a/libmobile_wrapper.c b/libmobile_wrapper.c
index 7cfeec1..436b733 100644
--- a/libmobile_wrapper.c
+++ b/libmobile_wrapper.c
@@ -49,3 +49,43 @@ struct json_object *mobile_get_remaining_tries(struct device *dev)
 
 	return NULL;
 }
+
+struct json_object *mobile_unlock_sim(struct device *dev, char *pin, char *puk)
+{
+	if (strcmp(dev->usb.if_name, "usb0") == 0)
+		return mobile_unlock_sim_zte(dev->ip, pin, puk);
+	else if (strcmp(dev->usb.if_name, "eth5") == 0)
+		//return mobile_unlock_sim_hilink(dev->ip, pin, puk);
+
+	return NULL;
+}
+
+struct json_object *mobile_get_apn_profiles(struct device *dev)
+{
+	if (strcmp(dev->usb.if_name, "usb0") == 0)
+		return mobile_get_apn_profiles_zte(dev->ip);
+	else if (strcmp(dev->usb.if_name, "eth5") == 0)
+		//return mobile_get_apn_profiles_hilink(dev->ip);
+
+	return NULL;
+}
+
+struct json_object *mobile_delete_apn_profile(struct device *dev, char *name)
+{
+	if (strcmp(dev->usb.if_name, "usb0") == 0)
+		return mobile_delete_apn_profile_zte(dev->ip, name);
+	else if (strcmp(dev->usb.if_name, "eth5") == 0)
+		//return mobile_delete_apn_profile_hilink(dev->ip, name);
+
+	return NULL;
+}
+
+struct json_object *mobile_set_apn_profile(struct device *dev, char *name)
+{
+	if (strcmp(dev->usb.if_name, "usb0") == 0)
+		return mobile_set_apn_profile_zte(dev->ip, name);
+	else if (strcmp(dev->usb.if_name, "eth5") == 0)
+		//return mobile_set_apn_profile_hilink(dev->ip, name);
+
+	return NULL;
+}
\ No newline at end of file
diff --git a/libmobile_wrapper.h b/libmobile_wrapper.h
index 3c24490..58d7721 100644
--- a/libmobile_wrapper.h
+++ b/libmobile_wrapper.h
@@ -27,4 +27,7 @@ struct json_object *mobile_disable_pin(struct device *dev, char *pin);
 struct json_object *mobile_verify_pin(struct device *dev, char *pin);
 struct json_object *mobile_enable_pin(struct device *dev, char *pin);
 struct json_object *mobile_get_remaining_tries(struct device *dev);
+struct json_object *mobile_get_apn_profiles(struct device *dev);
+struct json_object *mobile_delete_apn_profile(struct device *dev, char *name);
+struct json_object *mobile_set_apn_profile(struct device *dev, char *name);
 #endif
\ No newline at end of file
diff --git a/libmobile_zte.c b/libmobile_zte.c
index 42719e7..645eeb4 100644
--- a/libmobile_zte.c
+++ b/libmobile_zte.c
@@ -387,7 +387,7 @@ struct json_object *mobile_disconnect_network_zte(char *ip_addr)
 	return prepare_request(ip_addr, "isTest=false&notCallback=true&goformId=DISCONNECT_NETWORK", POST);
 }
 
-struct json_object *mobile_delete_apn_zte(char *ip_addr, char *name)
+struct json_object *mobile_delete_apn_profile_zte(char *ip_addr, char *name)
 {
 	struct json_object *apn_profiles = mobile_get_apn_profiles_zte(ip_addr);
 	char query[1024] = {0};
diff --git a/libmobile_zte.h b/libmobile_zte.h
index da88ced..089d4ee 100644
--- a/libmobile_zte.h
+++ b/libmobile_zte.h
@@ -90,7 +90,7 @@ struct json_object *mobile_disconnect_network_zte(char *ip_addr);
 *		A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
  *		NULL on failure.
  */
-struct json_object *mobile_delete_apn_zte(char *ip_addr, char *name);
+struct json_object *mobile_delete_apn_profile_zte(char *ip_addr, char *name);
 
 /**
  * Function: mobile_enable_roaming
-- 
GitLab