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
ece696c9
Commit
ece696c9
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
rearrange, move a lot of strings to library
parent
8cbe63a1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
dongle_apn.c
+10
-9
10 additions, 9 deletions
dongle_apn.c
dongle_network.c
+11
-8
11 additions, 8 deletions
dongle_network.c
dongle_pin.c
+13
-9
13 additions, 9 deletions
dongle_pin.c
libmobile.c
+75
-41
75 additions, 41 deletions
libmobile.c
libmobile.h
+20
-13
20 additions, 13 deletions
libmobile.h
with
129 additions
and
80 deletions
dongle_apn.c
+
10
−
9
View file @
ece696c9
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
dongle_network.c
+
11
−
8
View file @
ece696c9
...
@@ -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¬Callback=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¬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
);
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¬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
);
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
);
...
...
This diff is collapsed.
Click to expand it.
dongle_pin.c
+
13
−
9
View file @
ece696c9
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
libmobile.c
+
75
−
41
View file @
ece696c9
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
libmobile.h
+
20
−
13
View file @
ece696c9
...
@@ -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
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