1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

nhdp: port to sock

This commit is contained in:
Martine Lenders 2017-04-26 14:41:45 +02:00
parent c23d624d27
commit 53a9dc36ed
No known key found for this signature in database
GPG Key ID: 8E97A9FE55F25D62
2 changed files with 15 additions and 23 deletions

View File

@ -14,7 +14,7 @@ ifneq (,$(filter csma_sender,$(USEMODULE)))
endif
ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += conn_udp
USEMODULE += sock_udp
USEMODULE += xtimer
USEMODULE += oonf_rfc5444
endif

View File

@ -18,8 +18,7 @@
* @}
*/
#include "net/gnrc/conn.h"
#include "net/conn/udp.h"
#include "net/sock/udp.h"
#include "msg.h"
#include "net/gnrc/netapi.h"
#include "net/gnrc/netif.h"
@ -38,10 +37,6 @@
#include "nhdp_writer.h"
#include "nhdp_reader.h"
#ifndef MODULE_CONN_UDP
#error "nhdp needs a conn_udp implementation to work"
#endif
#define HELLO_TIMER (12345)
char nhdp_stack[NHDP_STACK_SIZE];
@ -53,7 +48,7 @@ static kernel_pid_t nhdp_rcv_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 mutex_t send_rcv_mutex = MUTEX_INIT;
static conn_udp_t conn;
static sock_udp_t sock;
#if (NHDP_METRIC_NEEDS_TIMER)
static xtimer_t metric_timer;
@ -295,27 +290,24 @@ static void *_nhdp_runner(void *arg)
*/
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];
msg_t 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 */
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 */
return 0;
}
while (1) {
ipv6_addr_t rcv_addr;
uint16_t rcv_port;
size_t addr_len = sizeof(rcv_addr);
int32_t rcv_size = conn_udp_recvfrom(&conn, (void *)nhdp_rcv_buf,
NHDP_MAX_RFC5444_PACKET_SZ, &rcv_addr,
&addr_len, &rcv_port);
int32_t rcv_size = sock_udp_recv(&sock, (void *)nhdp_rcv_buf,
NHDP_MAX_RFC5444_PACKET_SZ,
SOCK_NO_TIMEOUT, NULL);
if (rcv_size > 0) {
/* Packet received, let the reader handle it */
@ -325,7 +317,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
}
}
conn_udp_close(&conn);
sock_udp_close(&sock);
return 0;
}
@ -337,8 +329,8 @@ static void write_packet(struct rfc5444_writer *wr __attribute__((unused)),
struct rfc5444_writer_target *iface __attribute__((unused)),
void *buffer, size_t length)
{
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);
sock_udp_ep_t ep = { .family = AF_INET6, .netif = SOCK_ADDR_ANY_NETIF,
.port = MANET_PORT };
memcpy(ep.addr.ipv6, &ipv6_addr_all_nodes_link_local, sizeof(ep.addr.ipv6));
sock_udp_send(&sock, buffer, length, &ep);
}