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
b7a1e38b
Commit
b7a1e38b
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
move stuff related to getting if_name & ip
parent
4c7d1ccf
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dongle.c
+4
-0
4 additions, 0 deletions
dongle.c
dongle_infrastructure.c
+143
-0
143 additions, 0 deletions
dongle_infrastructure.c
dongle_infrastructure.h
+6
-0
6 additions, 0 deletions
dongle_infrastructure.h
with
153 additions
and
0 deletions
dongle.c
+
4
−
0
View file @
b7a1e38b
...
...
@@ -4,6 +4,7 @@
#include
"dongle_apn.h"
#include
"dongle_pin.h"
#include
"dongle_network.h"
#include
"dongle_infrastructure.h"
struct
ubus_context
*
ctx
;
int
debug
;
...
...
@@ -74,6 +75,9 @@ int main(int argc, char **argv)
if
(
rv
<
0
)
goto
fail
;
rv
=
expose_infrastructure_object
(
ctx
);
if
(
rv
<
0
)
goto
fail
;
uloop_run
();
return
0
;
...
...
This diff is collapsed.
Click to expand it.
dongle_infrastructure.c
0 → 100644
+
143
−
0
View file @
b7a1e38b
#include
"dongle_infrastructure.h"
char
*
dongle_ip
,
*
if_name
;
int
test_get_ip
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
struct
blob_attr
*
tb
[
__IP_MAX
];
char
*
dev
;
blobmsg_parse
(
ip_policy
,
__IP_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
if
(
tb
[
DEV
])
{
dev
=
(
char
*
)
blobmsg_data
(
tb
[
DEV
]);
get_ip
(
dev
);
}
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
;
}
int
get_ifname
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
char
*
path
,
device_path
[
1024
],
*
device_name
;
FILE
*
fp
,
inner_fp
;
fp
=
popen
(
"find /sys/devices/platform -type d -name
\"
net
\"
"
,
"r"
);
while
((
fgets
(
path
,
1024
,
fp
)
!=
NULL
)
{
printf
(
"path found %s!
\n
"
,
path
);
snprintf
(
device_path
,
1023
,
"ls %s"
,
path
);
inner_fp
=
popen
(
device_path
,
"r"
);
fscanf
(
inner_fp
,
"%s"
,
device_name
);
printf
(
"device name found %s!
\n
"
,
device_name
);
if
(
!
strstr
(
device_name
,
"eth"
)
||
!
strstr
(
device_name
,
"usb"
))
continue
;
if_name
=
strdup
(
device_name
);
printf
(
"And we have a winner %s!
\n
"
,
if_name
);
}
fail:
return
0
;
}
struct
ubus_method
infrastructure_object_methods
[]
=
{
UBUS_METHOD
(
"get_ip"
,
test_get_ip
,
ip_policy
),
UBUS_METHOD_NOARG
(
"get_ip_invoke"
,
get_ip_invoke
),
UBUS_METHOD_NOARG
(
"get_ifname"
,
get_ifname
);
};
struct
ubus_object_type
infrastructure_object_type
=
UBUS_OBJECT_TYPE
(
"dongle"
,
infrastructure_object_methods
);
struct
ubus_object
infrastructure_object
=
{
.
name
=
"dongle.infrastructure"
,
.
type
=
&
infrastructure_object_type
,
.
methods
=
infrastructure_object_methods
,
.
n_methods
=
ARRAY_SIZE
(
infrastructure_object_methods
),
};
int
expose_infrastructure_object
(
struct
ubus_context
*
ctx
)
{
int
rv
;
rv
=
ubus_add_object
(
ctx
,
&
infrastructure_object
);
if
(
rv
)
{
debug_print
(
"failed to add dongle.pin to ubus!
\n
"
);
return
-
1
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
dongle_infrastructure.h
0 → 100644
+
6
−
0
View file @
b7a1e38b
#ifndef INFRASTRUCTURE_H
#define INFRASTRUCTURE_H
#include
"common.h"
int
expose_infrastructure_object
(
struct
ubus_context
*
ctx
);
#endif
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