diff --git a/common.h b/common.h index 94e15db93ba7d82b1abbf869141c56b4dc2d7a5e..d96ebcf6ff163f63f588b539d16ef033bda6db07 100644 --- a/common.h +++ b/common.h @@ -26,7 +26,7 @@ #include "libmobile_wrapper.h" extern int debug; -extern char *global_ip_addr; +extern struct device *global_dev; extern struct ubus_context *global_ctx; #define debug_print(...) \ diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c index 46bc4dfdd2ca2214bacbad17b1b179bda45f19a2..9469498bc2db87dc975793c98461b6891601d330 100644 --- a/dongle_infrastructure.c +++ b/dongle_infrastructure.c @@ -15,8 +15,6 @@ #include <ifaddrs.h> #include "dongle_infrastructure.h" -#include "dongle.h" -#include "stack_operations.h" //dynamic object policies.. const struct blobmsg_policy set_pin_policy[__SET_PIN_MAX] = { @@ -81,12 +79,12 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj, goto fail_input; } - if (!pin_status(&bb, global_ip_addr)) { + if (!pin_status(&bb, global_dev->ip)) { ubus_send_reply(ctx, req, bb.head); goto disabled; } - response = mobile_set_pin_zte(global_ip_addr, current_pin, new_pin); + response = mobile_set_pin_zte(global_dev, current_pin, new_pin); if (!response) { debug_print("error setting pin!\n"); goto fail_data; @@ -134,13 +132,13 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj, goto fail_input; } - if (!pin_status(&bb, global_ip_addr)) { + if (!pin_status(&bb, global_dev->ip)) { ubus_send_reply(ctx, req, bb.head); debug_print("pin already disabled!\n"); goto disabled; } - response = mobile_disable_pin_zte(global_ip_addr, pin); + response = mobile_disable_pin_zte(global_dev, pin); if (!response) { debug_print("error disabling pin!\n"); goto fail_data; @@ -190,12 +188,18 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj, goto fail_input; } - if (pin_status(&bb, global_ip_addr)) { + if (pin_status(&bb, global_dev->ip)) { debug_print("pin already enabled"); ubus_send_reply(ctx, req, bb.head); goto enabled; } + response = mobile_enable_pin_zte(global_dev, pin); + if (!response) { + debug_print("error disabling pin!\n"); + goto fail_data; + } + rv = check_response(response); if (rv < 0) { debug_print("incorrect pin!\n"); @@ -209,6 +213,8 @@ fail_input_response: json_object_put(response); fail_input: return UBUS_STATUS_INVALID_ARGUMENT; +fail_data: + return UBUS_STATUS_UNKNOWN_ERROR; } int verify_pin(struct ubus_context *ctx, struct ubus_object *obj, @@ -237,13 +243,13 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj, goto fail_input; } - if (!pin_status(&bb, global_ip_addr)) { + if (!pin_status(&bb, global_dev->ip)) { debug_print("pin disabled"); ubus_send_reply(ctx, req, bb.head); goto disabled; } - response = mobile_set_pin_zte(global_ip_addr, pin, pin); + response = mobile_set_pin(global_dev, pin, pin); if (!response) goto fail_unknown; @@ -262,7 +268,7 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_get_remaining_tries_zte(global_ip_addr); + response = mobile_get_remaining_tries_zte(global_dev); if (!response) goto fail_unknown; @@ -297,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_ip_addr, puk, pin); + response = mobile_unlock_sim_zte(global_dev->ip, puk, pin); if (!response) goto fail_unknown; printf("did not survive the library\n"); @@ -314,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_ip_addr); + response = mobile_get_apn_profiles_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -345,7 +351,7 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, goto fail_argument; } - response = mobile_delete_apn_zte(global_ip_addr, name); + response = mobile_delete_apn_zte(global_dev->ip, name); if (!response) goto fail_unknown; @@ -378,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_ip_addr, name); + response = mobile_set_apn_profile_zte(global_dev->ip, name); if (!response) goto fail_unknown; @@ -415,7 +421,7 @@ int create_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, goto fail_argument; } - response = mobile_create_apn_profile_zte(global_ip_addr, profile_name, wan_apn, pdp_type); + response = mobile_create_apn_profile_zte(global_dev->ip, profile_name, wan_apn, pdp_type); if (!response) goto fail_unknown; @@ -432,7 +438,7 @@ int show_current_apn(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_get_current_apn_zte(global_ip_addr); + response = mobile_get_current_apn_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -452,7 +458,7 @@ int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_get_rssi_zte(global_ip_addr); + response = mobile_get_rssi_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -468,7 +474,7 @@ int connect_network(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_connect_network_zte(global_ip_addr); + response = mobile_connect_network_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -484,7 +490,7 @@ int disconnect(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_disconnect_network_zte(global_ip_addr); + response = mobile_disconnect_network_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -500,7 +506,7 @@ int modem_state(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_get_modem_state_zte(global_ip_addr); + response = mobile_get_modem_state_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -517,7 +523,7 @@ int enable_roaming(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_enable_roaming_zte(global_ip_addr); + response = mobile_enable_roaming_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -534,7 +540,7 @@ int disable_roaming(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_disable_roaming_zte(global_ip_addr); + response = mobile_disable_roaming_zte(global_dev->ip); if (!response) goto fail_unknown; @@ -551,7 +557,7 @@ int roam_status(struct ubus_context *ctx, struct ubus_object *obj, { struct json_object *response; - response = mobile_get_roam_status_zte(global_ip_addr); + response = mobile_get_roam_status_zte(global_dev->ip); if (!response) goto fail_unknown; diff --git a/dongle_infrastructure.h b/dongle_infrastructure.h index 77b09fc37beb01fb0828b635a58202d58a12ac7b..a036b63a1f0f87467718127cb60f5ebf00025e87 100644 --- a/dongle_infrastructure.h +++ b/dongle_infrastructure.h @@ -2,6 +2,7 @@ #define INFRASTRUCTURE_H #include "common.h" #include "dongle.h" +#include "stack_operations.h" #define IPV4_MAX 16 #define DYNAMIC_OBJ_NAME_SIZE 50