Skip to content
Snippets Groups Projects
Commit 3af5e3e3 authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

sys: net: uhcpc: port to sock

parent e4b33315
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
...@@ -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_sendto(&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_recvfrom(&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");
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment