Skip to content
Snippets Groups Projects
Commit ece696c9 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

rearrange, move a lot of strings to library

parent 8cbe63a1
Branches
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -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 ubus_request_data *req, const char *method,
struct blob_attr *msg) 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 json_object *apn_profiles = json_tokener_parse(response);
write_to_ubus(apn_profiles, ctx, req); write_to_ubus(apn_profiles, ctx, req);
...@@ -40,7 +40,7 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -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 ubus_request_data *req, const char *method,
struct blob_attr *msg) 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 json_object *apn_profiles = json_tokener_parse(response);
struct blob_attr *tb[__APN_MAX]; struct blob_attr *tb[__APN_MAX];
char name[1024] = {0}; //what is max available name length in dongle? 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, ...@@ -50,10 +50,10 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
strncpy(name, (char *)blobmsg_data(tb[APN]), 1023); strncpy(name, (char *)blobmsg_data(tb[APN]), 1023);
printf("name to remove: %s\n", name); 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) { if (idx >= 0) {
char *response = _delete_apn(idx); char *response = mobile_delete_apn(idx);
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -68,7 +68,7 @@ int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -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 ubus_request_data *req, const char *method,
struct blob_attr *msg) 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 json_object *apn_profiles = json_tokener_parse(response);
struct blob_attr *tb[__APN_MAX]; struct blob_attr *tb[__APN_MAX];
char apn[1024] = {0}; //STR_MAX or something from limits.h 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, ...@@ -79,12 +79,12 @@ int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
strncpy(apn, (char *)blobmsg_data(tb[APN]), 1023); strncpy(apn, (char *)blobmsg_data(tb[APN]), 1023);
printf("apn %s\n", apn); printf("apn %s\n", apn);
idx = get_apn_profile_idx(apn_profiles, apn); idx = apn_profile_idx(apn_profiles, apn);
if (idx < 0) if (idx < 0)
goto fail; goto fail;
free(response); free(response);
response = _set_apn_profile(idx); response = mobile_set_apn_profile(idx);
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -105,7 +105,7 @@ int create_apn_profile(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -105,7 +105,7 @@ int create_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
apn[0] = '\0'; apn[0] = '\0';
strncpy(apn, (char *)blobmsg_data(tb[APN]), 1023); 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); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -118,7 +118,8 @@ int show_current_apn(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -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 ubus_request_data *req, const char *method,
struct blob_attr *msg) 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); struct json_object *parsed_response = json_tokener_parse(wan_apn);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
......
...@@ -21,7 +21,7 @@ int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -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 ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
char *response = get_request("rssi"); char *response = mobile_get_request("rssi");
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -34,7 +34,7 @@ int connect_network(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -34,7 +34,7 @@ int connect_network(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
char *response = _connect(); char *response = mobile_connect_network();
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -45,7 +45,7 @@ int disconnect(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -45,7 +45,7 @@ int disconnect(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
char *response = _disconnect(); char *response = mobile_disconnect_network();
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -56,19 +56,20 @@ int modem_state(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -56,19 +56,20 @@ int modem_state(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) 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); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
return 0; return 0;
} }
///goform/goform_set_cmd_process?isTest=false&notCallback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=on
int enable_roaming(struct ubus_context *ctx, struct ubus_object *obj, int enable_roaming(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
char *response = post_request("/goform/goform_set_cmd_process?isTest=false&notCallback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=on"); //char *response = mobile_post_request("/goform/goform_set_cmd_process?isTest=false&notCallback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=on");
char *response = mobile_enable_roaming();
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -79,7 +80,8 @@ int disable_roaming(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -79,7 +80,8 @@ int disable_roaming(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
char *response = post_request("/goform/goform_set_cmd_process?isTest=false&notCallback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=off"); //char *response = mobile_post_request("/goform/goform_set_cmd_process?isTest=false&notCallback=true&goformId=SET_CONNECTION_MODE&roam_setting_option=off");
char response = *mobile_disable_roaming();
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -90,7 +92,8 @@ int roam_status(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -90,7 +92,8 @@ int roam_status(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) 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); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
......
...@@ -84,14 +84,15 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -84,14 +84,15 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj,
validate_pin_format(current_pin); validate_pin_format(current_pin);
printf("new: %s, old: %s\n", new_pin, 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 *parsed_response = json_tokener_parse(response);
struct json_object *rv; struct json_object *rv;
json_object_object_get_ex(parsed_response, "pin_status", &rv); json_object_object_get_ex(parsed_response, "pin_status", &rv);
if (!json_object_get_int(rv)) { if (!json_object_get_int(rv)) {
free(response); free(response);
response = _enable_pin(current_pin); response = mobile_enable_pin(current_pin);
json_object_put(parsed_response); json_object_put(parsed_response);
parsed_response = json_tokener_parse(response); parsed_response = json_tokener_parse(response);
json_object_object_get_ex(parsed_response, "result", &rv); json_object_object_get_ex(parsed_response, "result", &rv);
...@@ -102,7 +103,7 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -102,7 +103,7 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj,
} }
free(response); free(response);
response = _set_pin(current_pin, new_pin); response = mobile_set_pin(current_pin, new_pin);
json_object_put(parsed_response); json_object_put(parsed_response);
parsed_response = json_tokener_parse(response); parsed_response = json_tokener_parse(response);
json_object_object_get_ex(parsed_response, "result", &rv); json_object_object_get_ex(parsed_response, "result", &rv);
...@@ -133,13 +134,14 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -133,13 +134,14 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj,
strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9); strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9);
validate_pin_format(pin); 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 *parsed_response = json_tokener_parse(response);
struct json_object *rv; struct json_object *rv;
json_object_object_get_ex(parsed_response, "pin_status", &rv); json_object_object_get_ex(parsed_response, "pin_status", &rv);
if (json_object_get_int(rv)) { if (json_object_get_int(rv)) {
response = _disable_pin(pin); response = mobile_disable_pin(pin);
json_object_put(parsed_response); json_object_put(parsed_response);
parsed_response = json_tokener_parse(response); parsed_response = json_tokener_parse(response);
json_object_object_get_ex(parsed_response, "result", &rv); json_object_object_get_ex(parsed_response, "result", &rv);
...@@ -174,13 +176,14 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -174,13 +176,14 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj,
strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9); strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9);
validate_pin_format(pin); 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 *parsed_response = json_tokener_parse(response);
struct json_object *rv; struct json_object *rv;
json_object_object_get_ex(parsed_response, "pin_status", &rv); json_object_object_get_ex(parsed_response, "pin_status", &rv);
if (!json_object_get_int(rv)) { if (!json_object_get_int(rv)) {
response = _enable_pin(pin); response = mobile_enable_pin(pin);
json_object_put(parsed_response); json_object_put(parsed_response);
parsed_response = json_tokener_parse(response); parsed_response = json_tokener_parse(response);
json_object_object_get_ex(parsed_response, "result", &rv); json_object_object_get_ex(parsed_response, "result", &rv);
...@@ -214,7 +217,7 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -214,7 +217,7 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj,
strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9); strncpy(pin, (char *)blobmsg_data(tb[PIN]), 9);
validate_pin_format(pin); 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); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
...@@ -227,7 +230,8 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -227,7 +230,8 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) 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); struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req); write_to_ubus(parsed_response, ctx, req);
......
...@@ -41,13 +41,6 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp) ...@@ -41,13 +41,6 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp)
return size * nmemb; 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) struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb)
{ {
void *arr, *obj; void *arr, *obj;
...@@ -83,9 +76,25 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb) ...@@ -83,9 +76,25 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb)
return 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) 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); struct json_object *apn_profiles = json_tokener_parse(response);
int len = 0; int len = 0;
...@@ -100,23 +109,23 @@ int get_apn_profiles_len(void) ...@@ -100,23 +109,23 @@ int get_apn_profiles_len(void)
return -1; return -1;
} }
char *_connect(void) char *mobile_connect_network(void)
{ {
char query[1024] = {0}; char query[1024] = {0};
strncpy(query, "http://192.168.0.1/goform//goform_set_cmd_process?isTest=false&goformId=CONNECT_NETWORK", 1023); strncpy(query, "isTest=false&goformId=CONNECT_NETWORK", 1023);
return post_request(query); return mobile_post_request(query);
} }
char *_disconnect(void) char *mobile_disconnect_network(void)
{ {
char query[1024] = {0}; char query[1024] = {0};
// removed notcallback, why have it? // removed notcallback, why have it?
strncpy(query, "http://192.168.0.1/goform//goform_set_cmd_process?isTest=false&goformId=DISCONNECT_NETWORK", 1023); strncpy(query, "isTest=false&goformId=DISCONNECT_NETWORK", 1023);
return post_request(query); return mobile_post_request(query);
} }
char *_delete_apn(int idx) char *mobile_delete_apn(int idx)
{ {
char query[1024] = {0}; char query[1024] = {0};
...@@ -124,25 +133,50 @@ char *_delete_apn(int idx) ...@@ -124,25 +133,50 @@ char *_delete_apn(int idx)
sprintf(query + strlen(query), "%d", idx); sprintf(query + strlen(query), "%d", idx);
strncat(query + strlen(query), "&goformId=APN_PROC_EX", 1023); 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 *mobile_disable_roaming(void)
char *apn_profile = json_object_get_string(val); {
char *apn_name = strtok(apn_profile, "($)"); return mobile_post_request("isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=off");
}
if (strncmp(apn_name, name, 1024) == 0) char *mobile_get_roam_status(void)
return idx; {
idx++; return mobile_get_request("roam_setting_option");
} }
return -1;
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}; char query[1024] = {0};
...@@ -155,56 +189,56 @@ char *_create_apn_profile(char *apn) ...@@ -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); 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); 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}; 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); 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); 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}; 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, 1023);
strncat(query + strlen(query), "&pin_save_flag=0&isTest=false", 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}; 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), current_pin, 1023);
strncat(query + strlen(query), "&NewPinNumber=", 1023); strncat(query + strlen(query), "&NewPinNumber=", 1023);
strncat(query + strlen(query), new_pin, 1023); strncat(query + strlen(query), new_pin, 1023);
strncat(query + strlen(query), "&pin_save_flag=0&isTest=false", 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}; 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, 1023);
strncat(query + strlen(query), "&pin_save_flag=0&isTest=false", 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; CURL *curl;
CURLcode res; CURLcode res;
...@@ -234,7 +268,7 @@ fail: ...@@ -234,7 +268,7 @@ fail:
return NULL; return NULL;
} }
char *get_request(char *vars) char *mobile_get_request(char *vars)
{ {
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
......
...@@ -9,19 +9,26 @@ ...@@ -9,19 +9,26 @@
int write_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req); int write_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req);
void curl_cleaner(CURLcode *curl); void curl_cleaner(CURLcode *curl);
size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp); 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); 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); int get_apn_profiles_len(void);
char *_connect(void);
char *_disconnect(void); char *mobile_connect_network(void);
char *_delete_apn(int idx); char *mobile_disconnect_network(void);
int get_apn_profile_idx(struct json_object *apn_profiles, char *name); char *mobile_delete_apn(int idx);
char *get_current_wan_apn(void); char *mobile_enable_roaming(void);
char *_create_apn_profile(char *apn); char *mobile_disable_roaming(void);
char *_set_apn_profile(int idx); char *mobile_get_roam_status(void);
char *_enable_pin(char *pin); char *mobile_get_wan_apn(void);
char *_set_pin(char *current_pin, char *new_pin); char *mobile_get_pinnumber(void);
char *_disable_pin(char *pin); char *mobile_get_pin_status(void);
char *post_request(char *query); char *mobile_get_modem_state(void);
char *get_request(char *vars); 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 #endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment