diff --git a/dongle_apn.c b/dongle_apn.c
index 37bd07019e597acc9adbffdb220e2d3746ea7126..09354ff38c41bcb0332bd608a9a7408e8e900a55 100644
--- a/dongle_apn.c
+++ b/dongle_apn.c
@@ -58,28 +58,17 @@ 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 = mobile_get_apn_profiles();
- struct json_object *apn_profiles = json_tokener_parse(response);
struct blob_attr *tb[__APN_MAX];
char name[1024] = {0}; //STR_MAX or something from limits.h
- int idx;
blobmsg_parse(apn_policy, __APN_MAX, tb, blob_data(msg), blob_len(msg));
strncpy(name, (char *)blobmsg_data(tb[name]), 1023);
- printf("name %s\n", name);
- idx = apn_profile_idx(apn_profiles, name);
- if (idx < 0)
- goto fail;
-
- free(response);
- response = mobile_set_apn_profile(idx);
+ char *response = mobile_set_apn_profile(name);
struct json_object *parsed_response = json_tokener_parse(response);
write_to_ubus(parsed_response, ctx, req);
-fail:
free(response);
- json_object_put(apn_profiles);
return 0;
}
diff --git a/libmobile.c b/libmobile.c
index 7e52a0c9939e5e6b8ebcc9693ca01bef5c922821..fe6be73313f60749fceec827fa59e347772a5655 100644
--- a/libmobile.c
+++ b/libmobile.c
@@ -191,24 +191,27 @@ 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 *mobile_create_apn_profile(char *apn)
+char *mobile_create_apn_profile(char *name)
{
char query[1024] = {0};
strncpy(query, "isTest=false&goformId=APN_PROC_EX&apn_action=save&apn_mode=manual&profile_name=", 1023);
- strncat(query + strlen(query), apn, 1023);
+ strncat(query + strlen(query), name, 1023);
strncat(query + strlen(query), "&wan_dial=*99%23&apn_select=manual&pdp_type=IP&pdp_select=auto&pdp_addr=&index=", 1023);
sprintf(query + strlen(query), "%d", get_apn_profiles_len());
strncat(query + strlen(query), "&wan_apn=", 1023);
- strncat(query + strlen(query), apn, 1023);
+ strncat(query + strlen(query), name, 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);
return mobile_post_request(query);
}
-char *mobile_set_apn_profile(int idx)
+char *mobile_set_apn_profile(char *name)
{
+ char *apn_profiles = mobile_get_apn_profiles();
+ struct json_object *apn_profiles_json = json_object_tokener(apn_profiles);
+ int idx = apn_profile_idx(apn_profiles_json, name);
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);
diff --git a/libmobile.h b/libmobile.h
index 8979ef32b4638131097f4bcba2772b11782a6035..5947d4cbb53d249a7d327e49918203dace5d7b6b 100644
--- a/libmobile.h
+++ b/libmobile.h
@@ -96,7 +96,8 @@ int get_apn_profiles_len(void);
* Connects the dongle's network.
*
* Returns:
- * A string containing the servers response (a json string containing {"result": "success"/"failure"}), indicating whether the call was successful or not.
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
* NULL on failure.
*/
char *mobile_connect_network(void);
@@ -106,7 +107,8 @@ char *mobile_connect_network(void);
* Disconnects the dongle's network.
*
* Returns:
- * A string containing the servers response (a json string containing {"result": "success"/"failure"}), indicating whether the call was successful or not.
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
* NULL on failure.
*/
char *mobile_disconnect_network(void);
@@ -120,7 +122,8 @@ char *mobile_disconnect_network(void);
* name - The name of the APN profile to be removed.
*
* Returns:
- * A string containing the servers response (a json string containing {"result": "success"/"failure"}), indicating whether the call was successful or not.
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
* NULL on failure.
*/
char *mobile_delete_apn(char *name);
@@ -130,26 +133,194 @@ char *mobile_delete_apn(char *name);
*
* Enables the roaming option on the dongle.
*
- * Parameters:
- * name - The name of the APN profile to be removed.
- *
* Returns:
- * A string containing the servers response (a json string containing {"result": "success"/"failure"}), indicating whether the call was successful or not.
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
* NULL on failure.
*/
char *mobile_enable_roaming(void);
+
+/**
+ * Function: mobile_disable_roaming
+ *
+ * Disables the roaming option on the dongle.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
char *mobile_disable_roaming(void);
+
+/**
+ * Function: mobile_disable_roaming
+ *
+ * Gets the current roam status of the dongle.
+ *
+ * Returns:
+ * A string containing the servers response in JSON format, {"roam_setting_option": "on"/"off" }
+ * NULL on failure.
+ */
char *mobile_get_roam_status(void);
+
+/**
+ * Function: mobile_get_wan_apn
+ *
+ * Gets the currently active APN profile's WAN name.
+ *
+ * Returns:
+ * A string containing the servers response in JSON format, {"wan_apn": "<name>" } on success.
+ * NULL on failure.
+ */
char *mobile_get_wan_apn(void);
+
+/**
+ * Function: mobile_get_pinnumber
+ *
+ * Gets the pinnumber, indicating how many tries are remaining before the SIM card is locked.
+ *
+ * Returns:
+ * A string containing the servers response in JSON format, {"pinnumber": {1..3} } on success.
+ * NULL on failure.
+ */
char *mobile_get_pinnumber(void);
+
+/**
+ * Function: mobile_get_pin_status
+ *
+ * Gets the pinnumber, indicating whether pin is enabled or not.
+ *
+ * Returns:
+ * A string containing the servers response in JSON format, {"pinnumber": {0..1} } on success.
+ * NULL on failure.
+ */
char *mobile_get_pin_status(void);
+
+/**
+ * Function: mobile_get_modem_state
+ *
+ * Gets a variety of variables related to the modems state, i.e. network.
+ *
+ * Returns:
+ * A string containing the servers response in JSON format on success.
+ * NULL on failure.
+ */
char *mobile_get_modem_state(void);
+
+/**
+ * Function: mobile_get_apn_profiles
+ *
+ * Gets all available APN profile names.
+ *
+ * Returns:
+ * A string containing the servers response in JSON format on success.
+ * NULL on failure.
+ */
char *mobile_get_apn_profiles(void);
-char *mobile_create_apn_profile(char *apn);
-char *mobile_set_apn_profile(int idx);
+
+/**
+ * Function: mobile_create_apn_profile
+ *
+ * Creates a new APN profile.
+ *
+ * Parameter:
+ * name - Name of the APN (and WAN) profile to create.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
+char *mobile_create_apn_profile(char *name);
+
+/**
+ * Function: mobile_set_apn_profile
+ *
+ * Sets a name APN profile to be activate.
+ *
+ * Parameter:
+ * name - Name of the APN profile to activate.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
+char *mobile_set_apn_profile(char *name);
+
+/**
+ * Function: mobile_enable_pin
+ *
+ * Enables pin on the SIM card.
+ *
+ * Parameter:
+ * pin - The current pin card of the SIM.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
char *mobile_enable_pin(char *pin);
+
+/**
+ * Function: mobile_set_pin
+ *
+ * Sets a new pin for the SIM card.
+ *
+ * Parameter:
+ * current_pin - The currently active pin for the SIM card.
+ * new_pin - The pin code which to set as the active pin for the SIM card.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
char *mobile_set_pin(char *current_pin, char *new_pin);
+
+/**
+ * Function: mobile_disable_pin
+ *
+ * Disables pin for the SIM card.
+ *
+ * Parameter:
+ * pin - Currently active pin.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
char *mobile_disable_pin(char *pin);
+
+/**
+ * Function: mobile_post_request
+ *
+ * Function that prepares curl environment and final POST query, then executes said query.
+ *
+ * Parameter:
+ * query - The POST query content to execute.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
char *mobile_post_request(char *query);
+
+/**
+ * Function: mobile_get_request
+ *
+ * Function that prepares curl environment and final GET query, then executes said query.
+ *
+ * Parameter:
+ * vars - A string of comma separated values which to get from the server.
+ *
+ * Returns:
+ * A string containing the servers response (a json string containing {"result": "success"/"failure" }),
+ indicating whether the server successfully executed the query.
+ * NULL on failure.
+ */
char *mobile_get_request(char *vars);
#endif
\ No newline at end of file