diff --git a/dongle_apn.c b/dongle_apn.c index 2a22d32206f96e3f82e7ad39fc29c38611648532..70027cbf9d4810ee4d144896b93b70f62228f675 100644 --- a/dongle_apn.c +++ b/dongle_apn.c @@ -29,7 +29,7 @@ int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_apn_profiles(); + char *response = mobile_get_apn_profiles(); struct json_object *apn_profiles = json_tokener_parse(response); write_to_ubus(apn_profiles, ctx, req); @@ -40,7 +40,7 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_apn_profiles(); + char *response = mobile_get_apn_profiles(); struct json_object *apn_profiles = json_tokener_parse(response); struct blob_attr *tb[__APN_MAX]; char name[1024] = {0}; //what is max available name length in dongle? @@ -50,10 +50,10 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, strncpy(name, (char *)blobmsg_data(tb[APN]), 1023); printf("name to remove: %s\n", name); - idx = get_apn_profile_idx(apn_profiles, name); + idx = apn_profile_idx(apn_profiles, name); if (idx >= 0) { - char *response = _delete_apn(idx); + char *response = mobile_delete_apn(idx); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -68,7 +68,7 @@ int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_apn_profiles(); + char *response = mobile_get_apn_profiles(); struct json_object *apn_profiles = json_tokener_parse(response); struct blob_attr *tb[__APN_MAX]; char apn[1024] = {0}; //STR_MAX or something from limits.h @@ -79,12 +79,12 @@ int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, strncpy(apn, (char *)blobmsg_data(tb[APN]), 1023); printf("apn %s\n", apn); - idx = get_apn_profile_idx(apn_profiles, apn); + idx = apn_profile_idx(apn_profiles, apn); if (idx < 0) goto fail; free(response); - response = _set_apn_profile(idx); + response = mobile_set_apn_profile(idx); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -105,7 +105,7 @@ int create_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, apn[0] = '\0'; strncpy(apn, (char *)blobmsg_data(tb[APN]), 1023); - char *response = _create_apn_profile(apn); + char *response = mobile_create_apn_profile(apn); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -118,7 +118,8 @@ int show_current_apn(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *wan_apn = get_request("wan_apn"); + //char *wan_apn = mobile_get_request("wan_apn"); + char *wan_apn = mobile_get_wan_apn(); struct json_object *parsed_response = json_tokener_parse(wan_apn); write_to_ubus(parsed_response, ctx, req); diff --git a/dongle_network.c b/dongle_network.c index 5cfe29f6b745e4cfb70bc3bc3b3bf5a4e472c104..32e1cea9051a2c45e6ce506e412ce345bcaf9d7e 100644 --- a/dongle_network.c +++ b/dongle_network.c @@ -21,7 +21,7 @@ int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_request("rssi"); + char *response = mobile_get_request("rssi"); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -34,7 +34,7 @@ int connect_network(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = _connect(); + char *response = mobile_connect_network(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -45,7 +45,7 @@ int disconnect(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = _disconnect(); + char *response = mobile_disconnect_network(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -56,19 +56,20 @@ int modem_state(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_request("&sms_received_flag_flag=0&sts_received_flag_flag=0&cmd=modem_main_state%2Cpin_status%2Cloginfo%2Cnew_version_state%2Ccurrent_upgrade_state%2Cis_mandatory%2Csms_received_flag%2Csts_received_flag%2Csignalbar%2Cnetwork_type%2Cnetwork_provider%2Cppp_status%2CEX_SSID1%2Cex_wifi_status%2CEX_wifi_profile%2Cm_ssid_enable%2Csms_unread_num%2CRadioOff%2Csimcard_roam%2Clan_ipaddr%2Cstation_mac%2Cbattery_charging%2Cbattery_vol_percent%2Cbattery_pers%2Cspn_display_flag%2Cplmn_display_flag%2Cspn_name_data%2Cspn_b1_flag%2Cspn_b2_flag%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_time%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt%2Cmonthly_rx_bytes%2Cmonthly_tx_bytes%2Cmonthly_time%2Cdate_month%2Cdata_volume_limit_switch%2Cdata_volume_limit_size%2Cdata_volume_alert_percent%2Cdata_volume_limit_unit%2Croam_setting_option%2Cupg_roam_switch%2Chplmn"); + //char *response = mobile_get_request("&sms_received_flag_flag=0&sts_received_flag_flag=0&cmd=modem_main_state%2Cpin_status%2Cloginfo%2Cnew_version_state%2Ccurrent_upgrade_state%2Cis_mandatory%2Csms_received_flag%2Csts_received_flag%2Csignalbar%2Cnetwork_type%2Cnetwork_provider%2Cppp_status%2CEX_SSID1%2Cex_wifi_status%2CEX_wifi_profile%2Cm_ssid_enable%2Csms_unread_num%2CRadioOff%2Csimcard_roam%2Clan_ipaddr%2Cstation_mac%2Cbattery_charging%2Cbattery_vol_percent%2Cbattery_pers%2Cspn_display_flag%2Cplmn_display_flag%2Cspn_name_data%2Cspn_b1_flag%2Cspn_b2_flag%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_time%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt%2Cmonthly_rx_bytes%2Cmonthly_tx_bytes%2Cmonthly_time%2Cdate_month%2Cdata_volume_limit_switch%2Cdata_volume_limit_size%2Cdata_volume_alert_percent%2Cdata_volume_limit_unit%2Croam_setting_option%2Cupg_roam_switch%2Chplmn"); + char *response = mobile_get_modem_state(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); return 0; } -///goform/goform_set_cmd_process?isTest=false¬Callback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=on int enable_roaming(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = post_request("/goform/goform_set_cmd_process?isTest=false¬Callback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=on"); + //char *response = mobile_post_request("/goform/goform_set_cmd_process?isTest=false¬Callback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=on"); + char *response = mobile_enable_roaming(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -79,7 +80,8 @@ int disable_roaming(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = post_request("/goform/goform_set_cmd_process?isTest=false¬Callback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=off"); + //char *response = mobile_post_request("/goform/goform_set_cmd_process?isTest=false¬Callback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=off"); + char response = *mobile_disable_roaming(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -90,7 +92,8 @@ int roam_status(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_request("roam_setting_option"); + //char *response = mobile_get_request("roam_setting_option"); + char *response = mobile_get_roam_status(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); diff --git a/dongle_pin.c b/dongle_pin.c index 7e5a56121a454e8cff57b96110e468426f1464ba..11983e816c5130473d77bcc76d1a9311804f25d4 100644 --- a/dongle_pin.c +++ b/dongle_pin.c @@ -84,14 +84,15 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj, validate_pin_format(current_pin); printf("new: %s, old: %s\n", new_pin, current_pin); - char *response = get_request("pin_status"); + //char *response = mobile_get_request("pin_status"); + char *response = mobile_get_pin_status(); struct json_object *parsed_response = json_tokener_parse(response); struct json_object *rv; json_object_object_get_ex(parsed_response, "pin_status", &rv); if (!json_object_get_int(rv)) { free(response); - response = _enable_pin(current_pin); + response = mobile_enable_pin(current_pin); json_object_put(parsed_response); parsed_response = json_tokener_parse(response); json_object_object_get_ex(parsed_response, "result", &rv); @@ -102,7 +103,7 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj, } free(response); - response = _set_pin(current_pin, new_pin); + response = mobile_set_pin(current_pin, new_pin); json_object_put(parsed_response); parsed_response = json_tokener_parse(response); json_object_object_get_ex(parsed_response, "result", &rv); @@ -133,13 +134,14 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj, strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9); validate_pin_format(pin); - char *response = get_request("pin_status"); + //char *response = mobile_get_request("pin_status"); + char *response = mobile_get_pin_status(); struct json_object *parsed_response = json_tokener_parse(response); struct json_object *rv; json_object_object_get_ex(parsed_response, "pin_status", &rv); if (json_object_get_int(rv)) { - response = _disable_pin(pin); + response = mobile_disable_pin(pin); json_object_put(parsed_response); parsed_response = json_tokener_parse(response); json_object_object_get_ex(parsed_response, "result", &rv); @@ -174,13 +176,14 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj, strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9); validate_pin_format(pin); - char *response = get_request("pin_status"); + //char *response = mobile_get_request("pin_status"); + char *response = mobile_get_pin_status(); struct json_object *parsed_response = json_tokener_parse(response); struct json_object *rv; json_object_object_get_ex(parsed_response, "pin_status", &rv); if (!json_object_get_int(rv)) { - response = _enable_pin(pin); + response = mobile_enable_pin(pin); json_object_put(parsed_response); parsed_response = json_tokener_parse(response); json_object_object_get_ex(parsed_response, "result", &rv); @@ -214,7 +217,7 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj, strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9); validate_pin_format(pin); - char *response = _set_pin(pin, pin); + char *response = mobile_set_pin(pin, pin); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); @@ -227,7 +230,8 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char *response = get_request("pinnumber"); + //char *response = mobile_get_request("pinnumber"); + char *response = mobile_get_pinnumber(); struct json_object *parsed_response = json_tokener_parse(response); write_to_ubus(parsed_response, ctx, req); diff --git a/libmobile.c b/libmobile.c index f0124e88a7b1e45dfb14989b11c9ec430d040526..5a771534be195cafe81604be88722852ca78a063 100644 --- a/libmobile.c +++ b/libmobile.c @@ -41,13 +41,6 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp) return size * nmemb; } -char *get_apn_profiles(void) -{ - char *values = "APN_config0,APN_config1,APN_config2,APN_config3,APN_config4,APN_config5,APN_config6,APN_config7,APN_config8,APN_config9,APN_config10,APN_config11,APN_config12,APN_config13,APN_config14,APN_config15,APN_config16,APN_config17,APN_config18,APN_config19"; - - return get_request(values); -} - struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb) { void *arr, *obj; @@ -83,9 +76,25 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb) return bb; } +int apn_profile_idx(struct json_object *apn_profiles, char *name) +{ + int idx = 0; + + json_object_object_foreach(apn_profiles, key, val) + { + char *apn_profile = json_object_get_string(val); + char *apn_name = strtok(apn_profile, "($)"); + + if (strncmp(apn_name, name, 1024) == 0) + return idx; + idx++; + } + return -1; +} + int get_apn_profiles_len(void) { - char *response = get_apn_profiles(); + char *response = mobile_get_apn_profiles(); struct json_object *apn_profiles = json_tokener_parse(response); int len = 0; @@ -100,23 +109,23 @@ int get_apn_profiles_len(void) return -1; } -char *_connect(void) +char *mobile_connect_network(void) { char query[1024] = {0}; - strncpy(query, "http://192.168.0.1/goform//goform_set_cmd_process?isTest=false&goformId=CONNECT_NETWORK", 1023); - return post_request(query); + strncpy(query, "isTest=false&goformId=CONNECT_NETWORK", 1023); + return mobile_post_request(query); } -char *_disconnect(void) +char *mobile_disconnect_network(void) { char query[1024] = {0}; // removed notcallback, why have it? - strncpy(query, "http://192.168.0.1/goform//goform_set_cmd_process?isTest=false&goformId=DISCONNECT_NETWORK", 1023); - return post_request(query); + strncpy(query, "isTest=false&goformId=DISCONNECT_NETWORK", 1023); + return mobile_post_request(query); } -char *_delete_apn(int idx) +char *mobile_delete_apn(int idx) { char query[1024] = {0}; @@ -124,25 +133,50 @@ char *_delete_apn(int idx) sprintf(query + strlen(query), "%d", idx); strncat(query + strlen(query), "&goformId=APN_PROC_EX", 1023); - return post_request(query); + return mobile_post_request(query); } -int get_apn_profile_idx(struct json_object *apn_profiles, char *name) +char *mobile_enable_roaming(void) { - int idx = 0; + return mobile_post_request("isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=on"); +} - json_object_object_foreach(apn_profiles, key, val) { - char *apn_profile = json_object_get_string(val); - char *apn_name = strtok(apn_profile, "($)"); +char *mobile_disable_roaming(void) +{ + return mobile_post_request("isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=off"); +} - if (strncmp(apn_name, name, 1024) == 0) - return idx; - idx++; - } - return -1; +char *mobile_get_roam_status(void) +{ + return mobile_get_request("roam_setting_option"); +} + +char *mobile_get_wan_apn(void) +{ + return mobile_get_request("wan_apn"); +} + +char *mobile_get_pinnumber(void) +{ + return mobile_get_request("pinnumber"); +} + +char *mobile_get_pin_status(void) +{ + return mobile_get_request("pin_status"); +} + + +char *mobile_get_modem_state(void) +{ + return mobile_get_request("&sms_received_flag_flag=0&sts_received_flag_flag=0&cmd=modem_main_state%2Cpin_status%2Cloginfo%2Cnew_version_state%2Ccurrent_upgrade_state%2Cis_mandatory%2Csms_received_flag%2Csts_received_flag%2Csignalbar%2Cnetwork_type%2Cnetwork_provider%2Cppp_status%2CEX_SSID1%2Cex_wifi_status%2CEX_wifi_profile%2Cm_ssid_enable%2Csms_unread_num%2CRadioOff%2Csimcard_roam%2Clan_ipaddr%2Cstation_mac%2Cbattery_charging%2Cbattery_vol_percent%2Cbattery_pers%2Cspn_display_flag%2Cplmn_display_flag%2Cspn_name_data%2Cspn_b1_flag%2Cspn_b2_flag%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_time%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt%2Cmonthly_rx_bytes%2Cmonthly_tx_bytes%2Cmonthly_time%2Cdate_month%2Cdata_volume_limit_switch%2Cdata_volume_limit_size%2Cdata_volume_alert_percent%2Cdata_volume_limit_unit%2Croam_setting_option%2Cupg_roam_switch%2Chplmn"); +} +char *mobile_get_apn_profiles(void) +{ + return mobile_get_request("APN_config0,APN_config1,APN_config2,APN_config3,APN_config4,APN_config5,APN_config6,APN_config7,APN_config8,APN_config9,APN_config10,APN_config11,APN_config12,APN_config13,APN_config14,APN_config15,APN_config16,APN_config17,APN_config18,APN_config19"); } -char *_create_apn_profile(char *apn) +char *mobile_create_apn_profile(char *apn) { char query[1024] = {0}; @@ -155,56 +189,56 @@ char *_create_apn_profile(char *apn) strncat(query + strlen(query), "&ppp_auth_mode=none&ppp_username=&ppp_passwd=&dns_mode=auto&prefer_dns_manual=&standby_dns_manual=", 1023); printf("query: %s\n", query); - return post_request(query); + return mobile_post_request(query); } -char *_set_apn_profile(int idx) +char *mobile_set_apn_profile(int idx) { char query[1024] = {0}; strncpy(query, "isTest=false&goformId=APN_PROC_EX&apn_mode=manual&apn_action=set_default&set_default_flag=1&pdp_type=IP&index=", 1023); sprintf(query + strlen(query), "%d", idx); - return post_request(query); + return mobile_post_request(query); } -char *_enable_pin(char *pin) +char *mobile_enable_pin(char *pin) { char query[1024] = {0}; - strncpy(query, "goformId=ENABLE_PIN&OldPinNumber=", 1023); + strncpy(query, "isTest=false&goformId=ENABLE_PIN&OldPinNumber=", 1023); strncat(query + strlen(query), pin, 1023); strncat(query + strlen(query), "&pin_save_flag=0&isTest=false", 1023); - return post_request(query); + return mobile_post_request(query); } -char *_set_pin(char *current_pin, char *new_pin) +char *mobile_set_pin(char *current_pin, char *new_pin) { char query[1024] = {0}; - strncpy(query, "goformId=ENABLE_PIN&OldPinNumber=", 1023); + strncpy(query, "isTest=false&goformId=ENABLE_PIN&OldPinNumber=", 1023); strncat(query + strlen(query), current_pin, 1023); strncat(query + strlen(query), "&NewPinNumber=", 1023); strncat(query + strlen(query), new_pin, 1023); strncat(query + strlen(query), "&pin_save_flag=0&isTest=false", 1023); - return post_request(query); + return mobile_post_request(query); } -char *_disable_pin(char *pin) +char *mobile_disable_pin(char *pin) { char query[1024] = {0}; - strncpy(query, "goformId=DISABLE_PIN&OldPinNumber=", 1023); + strncpy(query, "isTest=false&goformId=DISABLE_PIN&OldPinNumber=", 1023); strncat(query + strlen(query), pin, 1023); strncat(query + strlen(query), "&pin_save_flag=0&isTest=false", 1023); - return post_request(query); + return mobile_post_request(query); } -char *post_request(char *query) +char *mobile_post_request(char *query) { CURL *curl; CURLcode res; @@ -234,7 +268,7 @@ fail: return NULL; } -char *get_request(char *vars) +char *mobile_get_request(char *vars) { CURL *curl; CURLcode res; diff --git a/libmobile.h b/libmobile.h index 230228cf22a45e59fc672bb0806226cb2b325e24..5fab753b8eb90f21762acc9d6fee03b8bbeb0334 100644 --- a/libmobile.h +++ b/libmobile.h @@ -9,19 +9,26 @@ int write_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req); void curl_cleaner(CURLcode *curl); size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp); -char *get_apn_profiles(void); struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb); +int apn_profile_idx(struct json_object *apn_profiles, char *name); int get_apn_profiles_len(void); -char *_connect(void); -char *_disconnect(void); -char *_delete_apn(int idx); -int get_apn_profile_idx(struct json_object *apn_profiles, char *name); -char *get_current_wan_apn(void); -char *_create_apn_profile(char *apn); -char *_set_apn_profile(int idx); -char *_enable_pin(char *pin); -char *_set_pin(char *current_pin, char *new_pin); -char *_disable_pin(char *pin); -char *post_request(char *query); -char *get_request(char *vars); + +char *mobile_connect_network(void); +char *mobile_disconnect_network(void); +char *mobile_delete_apn(int idx); +char *mobile_enable_roaming(void); +char *mobile_disable_roaming(void); +char *mobile_get_roam_status(void); +char *mobile_get_wan_apn(void); +char *mobile_get_pinnumber(void); +char *mobile_get_pin_status(void); +char *mobile_get_modem_state(void); +char *mobile_get_apn_profiles(void); +char *mobile_create_apn_profile(char *apn); +char *mobile_set_apn_profile(int idx); +char *mobile_enable_pin(char *pin); +char *mobile_set_pin(char *current_pin, char *new_pin); +char *mobile_disable_pin(char *pin); +char *mobile_post_request(char *query); +char *mobile_get_request(char *vars); #endif \ No newline at end of file