Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
3af5e3e3
Commit
3af5e3e3
authored
8 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys: net: uhcpc: port to sock
parent
e4b33315
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile.dep
+1
-1
1 addition, 1 deletion
Makefile.dep
sys/net/application_layer/uhcp/uhcpc.c
+14
-34
14 additions, 34 deletions
sys/net/application_layer/uhcp/uhcpc.c
with
15 additions
and
35 deletions
Makefile.dep
+
1
−
1
View file @
3af5e3e3
...
@@ -36,7 +36,7 @@ endif
...
@@ -36,7 +36,7 @@ endif
ifneq
(,$(filter gnrc_uhcpc,$(USEMODULE)))
ifneq
(,$(filter gnrc_uhcpc,$(USEMODULE)))
USEMODULE
+=
uhcpc
USEMODULE
+=
uhcpc
USEMODULE
+=
gnrc_
conn
_udp
USEMODULE
+=
gnrc_
sock
_udp
USEMODULE
+=
fmt
USEMODULE
+=
fmt
endif
endif
...
...
This diff is collapsed.
Click to expand it.
sys/net/application_layer/uhcp/uhcpc.c
+
14
−
34
View file @
3af5e3e3
...
@@ -6,21 +6,13 @@
...
@@ -6,21 +6,13 @@
* directory for more details.
* directory for more details.
*/
*/
#include
"net/uhcp
.h
"
#include
<arpa/inet
.h
>
#include
"net/af.h"
#include
"net/af.h"
#include
"net/
conn
/udp.h"
#include
"net/
sock
/udp.h"
#include
"net/
ipv6/addr
.h"
#include
"net/
uhcp
.h"
#include
"xtimer.h"
#include
"xtimer.h"
static
void
_timeout
(
void
*
arg
)
{
kernel_pid_t
pid
=
*
(
kernel_pid_t
*
)
arg
;
msg_t
msg
;
msg_send_int
(
&
msg
,
pid
);
msg_send_int
(
&
msg
,
pid
);
msg_send_int
(
&
msg
,
pid
);
}
/**
/**
* @brief Request prefix from uhcp server
* @brief Request prefix from uhcp server
*
*
...
@@ -31,8 +23,12 @@ static void _timeout(void *arg) {
...
@@ -31,8 +23,12 @@ static void _timeout(void *arg) {
*/
*/
void
uhcp_client
(
uhcp_iface_t
iface
)
void
uhcp_client
(
uhcp_iface_t
iface
)
{
{
ipv6_addr_t
target
;
sock_udp_t
sock
;
ipv6_addr_from_str
(
&
target
,
"ff15::abcd"
);
sock_udp_ep_t
local
=
{
.
family
=
AF_INET6
,
.
port
=
UHCP_PORT
,
.
netif
=
iface
};
sock_udp_ep_t
req_target
=
{
.
family
=
AF_INET6
,
.
port
=
UHCP_PORT
,
.
netif
=
iface
};
sock_udp_ep_t
remote
;
inet_pton
(
AF_INET6
,
"ff15::abcd"
,
req_target
.
addr
.
ipv6
);
/* prepare UHCP header */
/* prepare UHCP header */
uhcp_req_t
req
;
uhcp_req_t
req
;
...
@@ -40,36 +36,20 @@ void uhcp_client(uhcp_iface_t iface)
...
@@ -40,36 +36,20 @@ void uhcp_client(uhcp_iface_t iface)
req
.
prefix_len
=
64
;
req
.
prefix_len
=
64
;
/* create listening socket */
/* create listening socket */
ipv6_addr_t
zero
=
{{
0
}};
int
res
=
sock_udp_create
(
&
sock
,
&
local
,
NULL
,
0
);
conn_udp_t
conn
;
int
res
=
conn_udp_create
(
&
conn
,
&
zero
,
16
,
AF_INET6
,
UHCP_PORT
);
uint8_t
srv_addr
[
16
];
size_t
srv_addr_len
;
uint16_t
srv_port
;
uint8_t
buf
[
sizeof
(
uhcp_push_t
)
+
16
];
uint8_t
buf
[
sizeof
(
uhcp_push_t
)
+
16
];
kernel_pid_t
pid
=
thread_getpid
();
xtimer_t
timeout
;
timeout
.
callback
=
_timeout
;
timeout
.
arg
=
&
pid
;
while
(
1
)
{
while
(
1
)
{
xtimer_set
(
&
timeout
,
10U
*
SEC_IN_USEC
);
puts
(
"uhcp_client(): sending REQ..."
);
puts
(
"uhcp_client(): sending REQ..."
);
conn
_udp_send
to
(
&
req
,
sizeof
(
uhcp_req_t
),
NULL
,
0
,
&
target
,
16
,
AF_INET6
,
12345
,
12345
);
sock
_udp_send
(
&
sock
,
&
req
,
sizeof
(
uhcp_req_t
),
&
req_target
);
res
=
conn
_udp_recv
from
(
&
conn
,
buf
,
sizeof
(
buf
),
srv_addr
,
&
srv_addr_len
,
&
srv_port
);
res
=
sock
_udp_recv
(
&
sock
,
buf
,
sizeof
(
buf
),
10U
*
SEC_IN_USEC
,
&
remote
);
if
(
res
>
0
)
{
if
(
res
>
0
)
{
xtimer_remove
(
&
timeout
);
uhcp_handle_udp
(
buf
,
res
,
remote
.
addr
.
ipv6
,
remote
.
port
,
iface
);
uhcp_handle_udp
(
buf
,
res
,
srv_addr
,
srv_port
,
iface
);
xtimer_sleep
(
60
);
xtimer_sleep
(
60
);
}
}
else
{
else
{
msg_t
msg
;
puts
(
"uhcp_client(): no reply received"
);
msg_try_receive
(
&
msg
);
msg_try_receive
(
&
msg
);
msg_try_receive
(
&
msg
);
puts
(
"uhcp_client(): timeout waiting for reply"
);
}
}
}
}
}
}
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