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
4c7d1ccf
Commit
4c7d1ccf
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
update to get ip address from router.net
parent
a0a0baf2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+5
-5
5 additions, 5 deletions
Makefile
common.c
+4
-3
4 additions, 3 deletions
common.c
common.h
+3
-2
3 additions, 2 deletions
common.h
dongle_network.c
+74
-1
74 additions, 1 deletion
dongle_network.c
with
86 additions
and
11 deletions
Makefile
+
5
−
5
View file @
4c7d1ccf
CC
=
gcc
CC
=
gcc
CFLAGS
=
-g
-Wall
CFLAGS
=
-g
-Wall
LIBS
=
-ljson-c
-lubox
-lubus
-lcurl
-lmobile
LIBS
=
-ljson-c
-lubox
-lubus
-lcurl
-lmobile
-lblobmsg_json
all
:
libmobile1 libmobile2 common dongle_apn dongle_pin dongle_network dongle
all
:
libmobile1 libmobile2 common dongle_apn dongle_pin dongle_network dongle
...
@@ -22,20 +22,20 @@ common: ${COBJS}
...
@@ -22,20 +22,20 @@ common: ${COBJS}
DAOBJS
=
dongle_apn.o
DAOBJS
=
dongle_apn.o
DASRCS
=
dongle_apn.c
DASRCS
=
dongle_apn.c
dongle_apn
:
${DAOBJS}
dongle_apn
:
${DAOBJS}
${
CC
}
-c
${
CFLAGS
}
${
DASRCS
}
${
COBJS
}
-o
${
DAOBJS
}
-L
.
${
LIBS
}
#
${
MOBJS
}
${
CC
}
-c
${
CFLAGS
}
${
DASRCS
}
${
COBJS
}
-o
${
DAOBJS
}
-L
.
${
LIBS
}
DPOBJS
=
dongle_pin.o
DPOBJS
=
dongle_pin.o
DPSRCS
=
dongle_pin.c
DPSRCS
=
dongle_pin.c
dongle_pin
:
${DPOBJS}
dongle_pin
:
${DPOBJS}
${
CC
}
-c
${
CFLAGS
}
${
DPSRCS
}
${
COBJS
}
-o
${
DPOBJS
}
-L
.
${
LIBS
}
#
${
MOBJS
}
${
CC
}
-c
${
CFLAGS
}
${
DPSRCS
}
${
COBJS
}
-o
${
DPOBJS
}
-L
.
${
LIBS
}
DNOBJS
=
dongle_network.o
DNOBJS
=
dongle_network.o
DNSRCS
=
dongle_network.c
DNSRCS
=
dongle_network.c
dongle_network
:
${DNOBJS}
dongle_network
:
${DNOBJS}
${
CC
}
-c
${
CFLAGS
}
${
DNSRCS
}
${
COBJS
}
-o
${
DNOBJS
}
-L
.
${
LIBS
}
#
${
MOBJS
}
${
CC
}
-c
${
CFLAGS
}
${
DNSRCS
}
${
COBJS
}
-o
${
DNOBJS
}
-L
.
${
LIBS
}
dongle
:
dongle.o
dongle
:
dongle.o
${
CC
}
${
CFLAGS
}
dongle.o
${
COBJS
}
${
DNOBJS
}
${
DPOBJS
}
${
DAOBJS
}
-o
dongle
-L
.
${
LIBS
}
#
${
MOBJS
}
${
CC
}
${
CFLAGS
}
dongle.o
${
COBJS
}
${
DNOBJS
}
${
DPOBJS
}
${
DAOBJS
}
-o
dongle
-L
.
${
LIBS
}
clean
:
clean
:
rm
-f
dongle_apn dongle_pin dongle_network
*
.o
*
.so
rm
-f
dongle_apn dongle_pin dongle_network
*
.o
*
.so
...
...
This diff is collapsed.
Click to expand it.
common.c
+
4
−
3
View file @
4c7d1ccf
...
@@ -12,17 +12,18 @@ TODO:
...
@@ -12,17 +12,18 @@ TODO:
1. Implement by invoking ubus
1. Implement by invoking ubus
*/
*/
int
get_ip
(
char
*
if_name
)
char
*
get_ip
(
char
*
if_name
)
{
{
char
response
[
1024
]
=
{
0
};
char
response
[
1024
]
=
{
0
};
size_t
filesize
;
int
rv
;
FILE
*
fp
=
popen
(
"ubus call router.net ipv4_routes | grep -B 7
\"
usb0
\"
| grep
\"
flag.*H
\"
-B 4 | grep destination | cut -d ' ' -f2 | cut -d '
\"
' -f2"
,
"r"
);
FILE
*
fp
=
popen
(
"ubus call router.net ipv4_routes | grep -B 7
\"
usb0
\"
| grep
\"
flag.*H
\"
-B 4 | grep destination | cut -d ' ' -f2 | cut -d '
\"
' -f2"
,
"r"
);
fscanf
(
fp
,
"%s"
,
response
);
fscanf
(
fp
,
"%s"
,
response
);
pclose
(
fp
);
pclose
(
fp
);
printf
(
"%s
\n
"
,
response
);
printf
(
"%s
\n
"
,
response
);
return
strdup
(
response
);
return
0
;
}
}
int
print_to_ubus
(
struct
json_object
*
parsed_response
,
struct
ubus_context
*
ctx
,
struct
ubus_request_data
*
req
)
int
print_to_ubus
(
struct
json_object
*
parsed_response
,
struct
ubus_context
*
ctx
,
struct
ubus_request_data
*
req
)
...
...
This diff is collapsed.
Click to expand it.
common.h
+
3
−
2
View file @
4c7d1ccf
...
@@ -16,7 +16,8 @@
...
@@ -16,7 +16,8 @@
#include
"libmobile.h"
#include
"libmobile.h"
#include
<json-c/json.h>
#include
<json-c/json.h>
#include
<string.h>
#include
<string.h>
#include
<libubox/blobmsg.h>
//#include <libubox/blobmsg.h>
#include
<libubox/blobmsg_json.h>
#include
<libubus.h>
#include
<libubus.h>
extern
int
debug
;
extern
int
debug
;
...
@@ -27,7 +28,7 @@ extern int debug;
...
@@ -27,7 +28,7 @@ extern int debug;
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
} while (0)
int
get_ip
(
char
*
if_name
);
char
*
get_ip
(
char
*
if_name
);
/**
/**
* Function: print_to_ubus
* Function: print_to_ubus
*
*
...
...
This diff is collapsed.
Click to expand it.
dongle_network.c
+
74
−
1
View file @
4c7d1ccf
#include
"dongle_network.h"
#include
"dongle_network.h"
char
*
dongle_ip
;
static
enum
{
static
enum
{
IP
,
IP
,
DEV
,
DEV
,
...
@@ -217,6 +219,76 @@ int test_get_ip(struct ubus_context *ctx, struct ubus_object *obj,
...
@@ -217,6 +219,76 @@ int test_get_ip(struct ubus_context *ctx, struct ubus_object *obj,
return
0
;
return
0
;
}
}
static
void
parse_devices
(
struct
ubus_request
*
req
,
int
type
,
struct
blob_attr
*
msg
)
{
char
*
json_str
,
*
flags
,
*
ip
;
struct
json_object
*
json_msg
,
*
routes
,
*
route
,
*
json_ip
,
*
json_flags
;
int
i
;
json_str
=
blobmsg_format_json
(
msg
,
true
);
if
(
!
json_str
)
return
;
json_msg
=
json_tokener_parse
(
json_str
);
if
(
!
json_msg
)
goto
out_str
;
if
(
!
json_object_is_type
(
json_msg
,
json_type_object
))
goto
out_json
;
json_object_object_get_ex
(
json_msg
,
"routes"
,
&
routes
);
if
(
!
routes
)
goto
out_json
;
for
(
i
=
0
;
i
<
json_object_array_length
(
routes
);
i
++
)
{
route
=
json_object_array_get_idx
(
routes
,
i
);
json_object_object_get_ex
(
route
,
"flags"
,
&
json_flags
);
flags
=
json_object_get_string
(
json_flags
);
if
(
!
strchr
(
flags
,
'H'
))
continue
;
json_object_object_get_ex
(
route
,
"destination"
,
&
json_ip
);
ip
=
json_object_get_string
(
json_ip
);
goto
out
;
}
goto
out_json
;
out:
dongle_ip
=
strdup
(
ip
);
out_json:
json_object_put
(
json_msg
);
out_str:
free
(
json_str
);
}
int
get_ip_invoke
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_buf
buf
;
int
obj_id
,
rv
;
memset
(
&
buf
,
0
,
sizeof
(
buf
));
if
(
!
ctx
)
{
debug_print
(
"No ubus context!
\n
"
);
goto
fail
;
}
ubus_lookup_id
(
ctx
,
"router.net"
,
&
obj_id
);
if
(
!
obj_id
)
{
debug_print
(
"%s: ubus_lookup_id error
\n
"
,
__func__
);
goto
fail
;
}
rv
=
ubus_invoke
(
ctx
,
obj_id
,
"ipv4_routes"
,
NULL
,
parse_devices
,
NULL
,
5000
);
if
(
rv
>
0
)
printf
(
"ubus_invoke error code %d
\n
"
,
rv
);
fail:
return
0
;
}
struct
ubus_method
network_object_methods
[]
=
{
struct
ubus_method
network_object_methods
[]
=
{
UBUS_METHOD
(
"signal_strength"
,
get_signal_strength
,
ip_policy
),
UBUS_METHOD
(
"signal_strength"
,
get_signal_strength
,
ip_policy
),
UBUS_METHOD
(
"connect"
,
connect_network
,
ip_policy
),
UBUS_METHOD
(
"connect"
,
connect_network
,
ip_policy
),
...
@@ -225,7 +297,8 @@ struct ubus_method network_object_methods[] = {
...
@@ -225,7 +297,8 @@ struct ubus_method network_object_methods[] = {
UBUS_METHOD
(
"enable_roaming"
,
enable_roaming
,
ip_policy
),
UBUS_METHOD
(
"enable_roaming"
,
enable_roaming
,
ip_policy
),
UBUS_METHOD
(
"disable_roaming"
,
disable_roaming
,
ip_policy
),
UBUS_METHOD
(
"disable_roaming"
,
disable_roaming
,
ip_policy
),
UBUS_METHOD
(
"roam_status"
,
roam_status
,
ip_policy
),
UBUS_METHOD
(
"roam_status"
,
roam_status
,
ip_policy
),
UBUS_METHOD
(
"get_ip"
,
test_get_ip
,
ip_policy
)
UBUS_METHOD
(
"get_ip"
,
test_get_ip
,
ip_policy
),
UBUS_METHOD_NOARG
(
"get_ip_invoke"
,
get_ip_invoke
)
};
};
struct
ubus_object_type
network_object_type
=
UBUS_OBJECT_TYPE
(
"dongle"
,
network_object_methods
);
struct
ubus_object_type
network_object_type
=
UBUS_OBJECT_TYPE
(
"dongle"
,
network_object_methods
);
...
...
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