Skip to content
Snippets Groups Projects
Unverified Commit 53a9dc36 authored by Martine Lenders's avatar Martine Lenders
Browse files

nhdp: port to sock

parent c23d624d
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ifneq (,$(filter csma_sender,$(USEMODULE))) ...@@ -14,7 +14,7 @@ ifneq (,$(filter csma_sender,$(USEMODULE)))
endif endif
ifneq (,$(filter nhdp,$(USEMODULE))) ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += conn_udp USEMODULE += sock_udp
USEMODULE += xtimer USEMODULE += xtimer
USEMODULE += oonf_rfc5444 USEMODULE += oonf_rfc5444
endif endif
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
* @} * @}
*/ */
#include "net/gnrc/conn.h" #include "net/sock/udp.h"
#include "net/conn/udp.h"
#include "msg.h" #include "msg.h"
#include "net/gnrc/netapi.h" #include "net/gnrc/netapi.h"
#include "net/gnrc/netif.h" #include "net/gnrc/netif.h"
...@@ -38,10 +37,6 @@ ...@@ -38,10 +37,6 @@
#include "nhdp_writer.h" #include "nhdp_writer.h"
#include "nhdp_reader.h" #include "nhdp_reader.h"
#ifndef MODULE_CONN_UDP
#error "nhdp needs a conn_udp implementation to work"
#endif
#define HELLO_TIMER (12345) #define HELLO_TIMER (12345)
char nhdp_stack[NHDP_STACK_SIZE]; char nhdp_stack[NHDP_STACK_SIZE];
...@@ -53,7 +48,7 @@ static kernel_pid_t nhdp_rcv_pid = KERNEL_PID_UNDEF; ...@@ -53,7 +48,7 @@ static kernel_pid_t nhdp_rcv_pid = KERNEL_PID_UNDEF;
static kernel_pid_t helper_pid = KERNEL_PID_UNDEF; static kernel_pid_t helper_pid = KERNEL_PID_UNDEF;
static nhdp_if_entry_t nhdp_if_table[GNRC_NETIF_NUMOF]; static nhdp_if_entry_t nhdp_if_table[GNRC_NETIF_NUMOF];
static mutex_t send_rcv_mutex = MUTEX_INIT; static mutex_t send_rcv_mutex = MUTEX_INIT;
static conn_udp_t conn; static sock_udp_t sock;
#if (NHDP_METRIC_NEEDS_TIMER) #if (NHDP_METRIC_NEEDS_TIMER)
static xtimer_t metric_timer; static xtimer_t metric_timer;
...@@ -295,27 +290,24 @@ static void *_nhdp_runner(void *arg) ...@@ -295,27 +290,24 @@ static void *_nhdp_runner(void *arg)
*/ */
static void *_nhdp_receiver(void *arg __attribute__((unused))) static void *_nhdp_receiver(void *arg __attribute__((unused)))
{ {
static const sock_udp_ep_t ep = { .family = AF_INET6,
.netif = SOCK_ADDR_ANY_NETIF,
.port = MANET_PORT };
char nhdp_rcv_buf[NHDP_MAX_RFC5444_PACKET_SZ]; char nhdp_rcv_buf[NHDP_MAX_RFC5444_PACKET_SZ];
msg_t msg_q[NHDP_MSG_QUEUE_SIZE]; msg_t msg_q[NHDP_MSG_QUEUE_SIZE];
msg_init_queue(msg_q, NHDP_MSG_QUEUE_SIZE); msg_init_queue(msg_q, NHDP_MSG_QUEUE_SIZE);
/* Configure socket address for the manet port 269 */
ipv6_addr_t unspec = IPV6_ADDR_UNSPECIFIED;
/* Bind UDP socket to socket address */ /* Bind UDP socket to socket address */
if (conn_udp_create(&conn, &unspec, sizeof(unspec), AF_INET6, MANET_PORT) == -1) { if (sock_udp_create(&sock, &ep, NULL, 0) < 0) {
/* Failed creating the connection */ /* Failed creating the connection */
return 0; return 0;
} }
while (1) { while (1) {
ipv6_addr_t rcv_addr; int32_t rcv_size = sock_udp_recv(&sock, (void *)nhdp_rcv_buf,
uint16_t rcv_port; NHDP_MAX_RFC5444_PACKET_SZ,
size_t addr_len = sizeof(rcv_addr); SOCK_NO_TIMEOUT, NULL);
int32_t rcv_size = conn_udp_recvfrom(&conn, (void *)nhdp_rcv_buf,
NHDP_MAX_RFC5444_PACKET_SZ, &rcv_addr,
&addr_len, &rcv_port);
if (rcv_size > 0) { if (rcv_size > 0) {
/* Packet received, let the reader handle it */ /* Packet received, let the reader handle it */
...@@ -325,7 +317,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused))) ...@@ -325,7 +317,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
} }
} }
conn_udp_close(&conn); sock_udp_close(&sock);
return 0; return 0;
} }
...@@ -337,8 +329,8 @@ static void write_packet(struct rfc5444_writer *wr __attribute__((unused)), ...@@ -337,8 +329,8 @@ static void write_packet(struct rfc5444_writer *wr __attribute__((unused)),
struct rfc5444_writer_target *iface __attribute__((unused)), struct rfc5444_writer_target *iface __attribute__((unused)),
void *buffer, size_t length) void *buffer, size_t length)
{ {
ipv6_addr_t src, dst = IPV6_ADDR_ALL_NODES_LINK_LOCAL; sock_udp_ep_t ep = { .family = AF_INET6, .netif = SOCK_ADDR_ANY_NETIF,
uint16_t sport, dport = MANET_PORT; .port = MANET_PORT };
conn_udp_getlocaladdr(&conn, &src, &sport); memcpy(ep.addr.ipv6, &ipv6_addr_all_nodes_link_local, sizeof(ep.addr.ipv6));
conn_udp_sendto(buffer, length, &src, sizeof(src), &dst, sizeof(dst), AF_INET, sport, dport); sock_udp_send(&sock, buffer, length, &ep);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment