Newer
Older
#ifndef LIBMOBILE_H
#define LIBMOBILE_H
#include <curl/curl.h>
#include <json-c/json.h>
#include <string.h>
int debug;
//#define DEBUG 1 //how to define from some sort of config? there is no main?
#define debug_print(...) \
do \
{ \
fprintf(stderr, __VA_ARGS__); \
} while (0)
Jakob Olsson
committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/***************************************************
* Libmobile - A 4G Dongle library
*
* Libmobile provides a library to perform basic functionality for a 4G dongle through
* the use of HTTP GET/POST.
*
* All library calls will prepare the GET or POST query, and send the request to the dongle.
* The response from the server is parsed through a callback, <write_func>. The dongle's response
* is then returned. For POST requests the dongle responds with {"result": "success"} on a
* successful query execution, and with {"result": failure"} on an unsuccessful query execution,
* note that an unsuccessful query execution can mean a variety of things such as: incorrect pin,
* wrong input format, value already set, etc. For a GET request the variable's requested for with
* their corresponding values are returned, important to note that even variables that are not
* available within the system will be returned, but with no value set. The return string for all
* calls is the servers response pointed to by a char pointer.
*
*
* How to extend libmobile
*
* To extend this library add a new function with the corresponding documentation. The naming scheme
* should follow the format <mobile_get_{variables}> for GET requests and <mobile_{action_performed}>
* for POST requests. The structure of the calls are that the <mobile_...> functions prepare the query,
* for GET this means providing the variables to request from the dongle, provided as an input to
* <mobile_get_request>, for POST this means providing the POSTFIELDS argument query to the method
* <mobile_post_request>. The dongle's response is parsed through a callback, a pointer is then returned
* pointing to the response.
*
***************************************************/
/***************************************************
* IMPORTANT NOTE
*
* The library calls will allocate memory for the dongle's response and return the pointer to this memory,
* the caller is then responsible for freeing this memory by calling free(returned_pointer).
Jakob Olsson
committed
***************************************************/
Jakob Olsson
committed
/**
* Function: mobile_connect_network
*
* Connects the dongle's network.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_connect_network(void);
Jakob Olsson
committed
/**
* Function: mobile_disconnect_network
*
* Disconnects the dongle's network.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_disconnect_network(void);
Jakob Olsson
committed
/**
* Function: mobile_delete_apn
*
* Deletes an existing APN profile from the APN list.
*
* Parameters:
* name - The name of the APN profile to be removed.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_delete_apn(char *name);
Jakob Olsson
committed
/**
* Function: mobile_enable_roaming
*
* Enables the roaming option on the dongle.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_enable_roaming(void);
Jakob Olsson
committed
/**
* Function: mobile_disable_roaming
*
* Disables the roaming option on the dongle.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_disable_roaming(void);
Jakob Olsson
committed
/**
* Function: mobile_disable_roaming
*
* Gets the current roam status of the dongle.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"roam_setting_option": "on"/"off" }
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_get_roam_status(void);
Jakob Olsson
committed
/**
* Function: mobile_get_current_apn
*
* Gets the currently active APN profile.
*
* Returns:
* A pointer to a json_object containing the JSON profile on success.
* NULL on failure.
*/
struct json_object *mobile_get_current_apn(void);
Jakob Olsson
committed
/**
* Function: mobile_get_wan_apn
*
* Gets the currently active APN profile's WAN name.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"wan_apn": "<name>" } on success.
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_get_wan_apn(void);
Jakob Olsson
committed
/**
* Function: mobile_get_remaining_tries
Jakob Olsson
committed
*
* Gets the pinnumber variable, indicating how many tries are remaining before the SIM card is locked.
Jakob Olsson
committed
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"pinnumber": {1..3} } on success.
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_get_remaining_tries(void);
Jakob Olsson
committed
/**
* Function: mobile_get_pin_status
*
* Gets the pinnumber, indicating whether pin is enabled or not.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"pinnumber": {0..1} } on success.
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_get_pin_status(void);
Jakob Olsson
committed
/**
* Function: mobile_get_rssi
*
* Gets the rssi, indicating the signal strength.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"rssi": {} } on success.
struct json_object *mobile_get_rssi(void);
Jakob Olsson
committed
/**
* Function: mobile_get_modem_state
*
* Gets a variety of variables related to the modems state, i.e. network.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_get_modem_state(void);
Jakob Olsson
committed
/**
* Function: mobile_get_apn_profiles
*
* Gets all available APN profile names.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_get_apn_profiles(void);
Jakob Olsson
committed
/**
* Function: mobile_create_apn_profile
*
* Creates a new APN profile.
*
* Parameter:
Jakob Olsson
committed
* name - Name of the APN profile to create.
* wan_apn - Name of the wan.
* pdp_type - The pdp type to use IPv4/IPv6.
Jakob Olsson
committed
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
Jakob Olsson
committed
struct json_object *mobile_create_apn_profile(char *profile_name, char *wan_apn, char *pdp_type);
Jakob Olsson
committed
/**
* Function: mobile_set_apn_profile
*
* Sets a name APN profile to be activate.
*
* Parameter:
* name - Name of the APN profile to activate.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_set_apn_profile(char *name);
Jakob Olsson
committed
/**
* Function: mobile_enable_pin
*
* Enables pin on the SIM card.
*
* Parameter:
* pin - The current pin card of the SIM.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_enable_pin(char *pin);
Jakob Olsson
committed
/**
* 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 pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_set_pin(char *current_pin, char *new_pin);
Jakob Olsson
committed
/**
* Function: mobile_disable_pin
*
* Disables pin for the SIM card.
*
* Parameter:
* pin - Currently active pin.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
Jakob Olsson
committed
* NULL on failure.
*/
struct json_object *mobile_disable_pin(char *pin);