Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdmngr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IOPSYS
mdmngr
Commits
74d44110
Commit
74d44110
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Plain Diff
Merge branch 'zte-mf823-shared-lib' of public.inteno.se:mobile-api into zte-mf823-shared-lib
parents
5dd68203
4ebaf41d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libmobile.c
+81
-10
81 additions, 10 deletions
libmobile.c
with
81 additions
and
10 deletions
libmobile.c
+
81
−
10
View file @
74d44110
/**
* TODO:
* 1. Add parsing for displaying APN profiles available to make sense of them
* 2. Add more input options when creating APN profile
* 3. Seperate "set default" and "apply" APN profiles (what is the difference anyway?)
* 4. Make the APN parsed fields more dynamic
*/
#include
"libmobile.h"
#include
"libmobile.h"
struct
string
{
struct
string
{
...
@@ -9,6 +18,7 @@ void curl_cleaner(CURLcode *curl);
...
@@ -9,6 +18,7 @@ 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
);
int
apn_profile_idx
(
struct
json_object
*
apn_profiles
,
char
*
name
);
int
apn_profile_idx
(
struct
json_object
*
apn_profiles
,
char
*
name
);
int
get_apn_profiles_len
(
void
);
int
get_apn_profiles_len
(
void
);
struct
json_object
*
parse_apn_profiles
(
char
*
apn_profiles
);
/**
/**
* Function: curl_cleaner
* Function: curl_cleaner
...
@@ -123,27 +133,88 @@ free_response:
...
@@ -123,27 +133,88 @@ free_response:
free
(
response
);
free
(
response
);
fail:
fail:
return
-
1
;
return
-
1
;
success:
success:
json_object_put
(
parsed_response
);
json_object_put
(
parsed_response
);
free
(
response
);
free
(
response
);
return
len
;
return
len
;
}
}
char
*
mobile_connect_network
(
void
)
/**
* Function: parse_apn_profiles
*
* Takes a string of APN profile configurations provided by zte-mf823 (which is in an awkward, difficult to read format)
* and transforms them into a more easily read and worked with JSON format.
*
* Parameters:
* apn_profiles - A character string containing the APN profiles.
* Returns:
* The newly generated JSON on success.
* NULL on failure.
*/
struct
json_object
*
parse_apn_profiles
(
char
*
apn_profiles
)
{
{
char
query
[
1024
]
=
{
0
};
if
(
strlen
(
apn_profiles
)
<=
0
)
{
DEBUG
(
"No APN profiles provided!
\n
"
);
goto
fail
;
}
struct
json_object
*
apn_profiles_json
=
json_tokener_parse
(
apn_profiles
);
strncpy
(
query
,
"isTest=false&goformId=CONNECT_NETWORK"
,
1023
);
if
(
!
apn_profiles_json
)
{
return
mobile_post_request
(
query
);
DEBUG
(
"Not valid json!
\n
"
);
goto
fail
;
}
struct
json_object
*
parsed_profiles
=
json_object_new_object
();
int
apn_counter
=
0
;
char
field_names
[
13
]
=
{
"profile_name"
,
"apn_name"
,
"mode"
,
"dunno"
,
"authentication"
,
"username?"
,
"password?"
,
"IPdunno"
,
"ddnunno?"
,
"dno"
,
"DNS_mode"
,
"IPv_username"
,
"IPv_password"
};
int
rv
;
json_object_object_foreach
(
apn_profiles_json
,
key
,
val
)
{
char
*
apn_string
=
json_object_get_string
(
val
);
if
(
strlen
(
apn_string
)
<=
0
)
goto
finished
;
int
i
;
struct
json_object
*
apn_profile
=
json_object_new_object
();
for
(
i
=
0
;
i
<
13
;
i
++
)
{
char
*
field_val
=
strtok
(
apn_string
,
"($)"
);
json_object_object_add
(
apn_profile
,
field_names
[
i
],
field_val
);
}
rv
=
json_object_object_add
(
parsed_profiles
,
sprintf
(
"%d"
,
apn_counter
),
apn_profile
);
//be careful here, do we need json_object_get(apn_profile)?
json_object_put
(
apn_profile
);
if
(
!
rv
)
{
DEBUG
(
"Error adding object!
\n
"
);
goto
free_objects
;
}
apn_counter
++
;
//json_put what??
printf
(
"FREE THEM CORRECTLY HERE!
\n
"
);
//best guess, free: apn_profile
}
goto
finished
;
free_objects:
json_object_put
(
apn_profiles
);
json_object_put
(
parsed_profiles
);
fail:
return
NULL
;
finished:
printf
(
"probably need to free apn_profiles_json!
\n
"
);
//best guess, free: apn_profiles_json
json_object_put
(
apn_profiles
);
json_object_put
(
parsed_profiles
);
return
parsed_profiles
;
}
char
*
mobile_connect_network
(
void
)
{
return
mobile_post_request
(
"isTest=false&goformId=CONNECT_NETWORK"
);
}
}
char
*
mobile_disconnect_network
(
void
)
char
*
mobile_disconnect_network
(
void
)
{
{
char
query
[
1024
]
=
{
0
};
return
mobile_post_request
(
"isTest=false&goformId=DISCONNECT_NETWORK"
);
// removed notcallback, why have it?
strncpy
(
query
,
"isTest=false&goformId=DISCONNECT_NETWORK"
,
1023
);
return
mobile_post_request
(
query
);
}
}
char
*
mobile_delete_apn
(
char
*
name
)
char
*
mobile_delete_apn
(
char
*
name
)
...
@@ -222,6 +293,7 @@ char *mobile_get_modem_state(void)
...
@@ -222,6 +293,7 @@ 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"
);
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
)
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"
);
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"
);
...
@@ -279,7 +351,6 @@ fail:
...
@@ -279,7 +351,6 @@ fail:
return
NULL
;
return
NULL
;
}
}
char
*
mobile_enable_pin
(
char
*
pin
)
char
*
mobile_enable_pin
(
char
*
pin
)
{
{
char
query
[
1024
]
=
{
0
};
char
query
[
1024
]
=
{
0
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment