Skip to content
Snippets Groups Projects
Commit 320aa472 authored by Martine Lenders's avatar Martine Lenders
Browse files

Merge pull request #3876 from authmillenon/nhdp/enh/use-conn

nhdp: use conn instead of socket_base
parents ed451247 9ce1c6df
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,13 @@ ifneq (,$(filter libcoap,$(USEPKG))) ...@@ -2,6 +2,13 @@ ifneq (,$(filter libcoap,$(USEPKG)))
USEMODULE += posix_sockets USEMODULE += posix_sockets
endif endif
ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += conn_udp
USEMODULE += vtimer
USEMODULE += oonf_common
USEMODULE += oonf_rfc5444
endif
ifneq (,$(filter gnrc_%,$(filter-out gnrc_netapi gnrc_netreg gnrc_netif% gnrc_pktbuf,$(USEMODULE)))) ifneq (,$(filter gnrc_%,$(filter-out gnrc_netapi gnrc_netreg gnrc_netif% gnrc_pktbuf,$(USEMODULE))))
USEMODULE += gnrc USEMODULE += gnrc
endif endif
...@@ -295,12 +302,6 @@ ifneq (,$(filter libfixmath-unittests,$(USEMODULE))) ...@@ -295,12 +302,6 @@ ifneq (,$(filter libfixmath-unittests,$(USEMODULE)))
USEPKG += libfixmath USEPKG += libfixmath
endif endif
ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += vtimer
USEMODULE += oonf_common
USEMODULE += oonf_rfc5444
endif
ifneq (,$(filter fib,$(USEMODULE))) ifneq (,$(filter fib,$(USEMODULE)))
USEMODULE += universal_address USEMODULE += universal_address
USEMODULE += xtimer USEMODULE += xtimer
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* @} * @}
*/ */
#include "conn/udp.h"
#include "msg.h" #include "msg.h"
#include "netapi.h" #include "netapi.h"
#include "net/gnrc/netif.h" #include "net/gnrc/netif.h"
...@@ -35,6 +36,10 @@ ...@@ -35,6 +36,10 @@
#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
char nhdp_stack[NHDP_STACK_SIZE]; char nhdp_stack[NHDP_STACK_SIZE];
char nhdp_rcv_stack[NHDP_STACK_SIZE]; char nhdp_rcv_stack[NHDP_STACK_SIZE];
...@@ -44,8 +49,7 @@ static kernel_pid_t nhdp_rcv_pid = KERNEL_PID_UNDEF; ...@@ -44,8 +49,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 sockaddr6_t sa_bcast; static conn_udp_t conn;
static int sock_rcv;
#if (NHDP_METRIC_NEEDS_TIMER) #if (NHDP_METRIC_NEEDS_TIMER)
static vtimer_t metric_timer; static vtimer_t metric_timer;
...@@ -85,12 +89,6 @@ kernel_pid_t nhdp_start(void) ...@@ -85,12 +89,6 @@ kernel_pid_t nhdp_start(void)
{ {
if (nhdp_pid == KERNEL_PID_UNDEF) { if (nhdp_pid == KERNEL_PID_UNDEF) {
/* Init destination address for NHDP's packets */ /* Init destination address for NHDP's packets */
sa_bcast.sin6_family = AF_INET6;
sa_bcast.sin6_port = HTONS(MANET_PORT);
ipv6_addr_set_all_nodes_addr(&sa_bcast.sin6_addr);
/* Configure sending/receiving UDP socket */
sock_rcv = socket_base_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
/* Start the NHDP thread */ /* Start the NHDP thread */
nhdp_pid = thread_create(nhdp_stack, sizeof(nhdp_stack), THREAD_PRIORITY_MAIN - 1, nhdp_pid = thread_create(nhdp_stack, sizeof(nhdp_stack), THREAD_PRIORITY_MAIN - 1,
...@@ -293,20 +291,20 @@ static void *_nhdp_receiver(void *arg __attribute__((unused))) ...@@ -293,20 +291,20 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
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 */ /* Configure socket address for the manet port 269 */
sockaddr6_t sa_rcv = {.sin6_family = AF_INET6, ipv6_addr_t unspec = IPV6_ADDR_UNSPECIFIED;
.sin6_port = HTONS(MANET_PORT)
};
/* Bind UDP socket to socket address */ /* Bind UDP socket to socket address */
if (socket_base_bind(sock_rcv, &sa_rcv, sizeof(sa_rcv)) == -1) { if (conn_udp_create(&conn, &unspec, sizeof(unspec), AF_INET6, MANET_PORT) == -1) {
/* Failed binding the socket */ /* Failed creating the connection */
socket_base_close(sock_rcv);
return 0; return 0;
} }
while (1) { while (1) {
int32_t rcv_size = socket_base_recvfrom(sock_rcv, (void *)nhdp_rcv_buf, ipv6_addr_t rcv_addr;
NHDP_MAX_RFC5444_PACKET_SZ, 0, &sa_rcv, &fromlen); uint16_t rcv_port;
int32_t rcv_size = conn_udp_recvfrom(&conn, (void *)nhdp_rcv_buf,
NHDP_MAX_RFC5444_PACKET_SZ, &rcv_addr,
sizeof(rcv_addr), &rcv_port);
if (rcv_size > 0) { if (rcv_size > 0) {
/* Packet received, let the reader handle it */ /* Packet received, let the reader handle it */
...@@ -316,7 +314,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused))) ...@@ -316,7 +314,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
} }
} }
socket_base_close(sock_rcv); gnrc_udp_close(&conn);
return 0; return 0;
} }
...@@ -328,5 +326,8 @@ static void write_packet(struct rfc5444_writer *wr __attribute__((unused)), ...@@ -328,5 +326,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)
{ {
socket_base_sendto(sock_rcv, buffer, length, 0, &sa_bcast, sizeof(sa_bcast)); ipv6_addr_t src, dst = IPV6_ADDR_ALL_NODES_LINK_LOCAL;
uint16_t sport, dport = MANET_PORT;
conn_udp_getlocaladdr(&conn, &src, &sport);
conn_udp_sendto(buffer, length, &src, sizeof(src), &dst, sizeof(dst), AF_INET, sport, dport);
} }
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "timex.h" #include "timex.h"
#include "kernel_types.h" #include "kernel_types.h"
#include "socket_base/socket.h"
#include "nhdp_metric.h" #include "nhdp_metric.h"
#include "rfc5444/rfc5444_writer.h" #include "rfc5444/rfc5444_writer.h"
......
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