From 931b179d14d3749e9fbcc722eefced5bf23bdfed Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 25 Feb 2019 17:08:30 +0100 Subject: [PATCH] gnrc_sixlowpan_frag: encapsulate msg_send_to_self() This makes it easier to access this functionality for test cases e.g. from the `main` thread. --- sys/include/net/gnrc/sixlowpan/frag.h | 26 ++++++++++++++++++- sys/include/net/gnrc/sixlowpan/internal.h | 8 ++++++ .../sixlowpan/frag/gnrc_sixlowpan_frag.c | 5 +--- .../network_layer/sixlowpan/gnrc_sixlowpan.c | 5 ++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/sys/include/net/gnrc/sixlowpan/frag.h b/sys/include/net/gnrc/sixlowpan/frag.h index ff6a7c4987a3..cf5ab60a5cad 100644 --- a/sys/include/net/gnrc/sixlowpan/frag.h +++ b/sys/include/net/gnrc/sixlowpan/frag.h @@ -29,9 +29,10 @@ #include #include "byteorder.h" -#include "kernel_types.h" +#include "msg.h" #include "net/gnrc/pkt.h" #include "net/gnrc/netif/hdr.h" +#include "net/gnrc/sixlowpan/internal.h" #include "net/ieee802154.h" #include "net/sixlowpan.h" @@ -133,6 +134,29 @@ void gnrc_sixlowpan_frag_recv(gnrc_pktsnip_t *pkt, void *ctx, unsigned page); */ void gnrc_sixlowpan_frag_rbuf_gc(void); +/** + * @brief Sends a message to pass a further fragment down the network stack + * + * @see GNRC_SIXLOWPAN_MSG_FRAG_SND + * + * @param[in] fragment_msg A @ref gnrc_sixlowpan_msg_frag_t object + * + * @return true, when the message was sent + * @return false when sending the message failed. + */ +static inline bool gnrc_sixlowpan_frag_send_msg(gnrc_sixlowpan_msg_frag_t *fragment_msg) +{ + msg_t msg; + + msg.content.ptr = fragment_msg; + msg.type = GNRC_SIXLOWPAN_MSG_FRAG_SND; +#ifdef TEST_SUITES + return (msg_try_send(&msg, gnrc_sixlowpan_get_pid()) > 0); +#else + return (msg_send_to_self(&msg) != 0); +#endif +} + #if defined(MODULE_GNRC_SIXLOWPAN_FRAG) || defined(DOXYGEN) /** * @brief Removes an entry from the reassembly buffer diff --git a/sys/include/net/gnrc/sixlowpan/internal.h b/sys/include/net/gnrc/sixlowpan/internal.h index 19f3f1f0591a..bf95d81caf60 100644 --- a/sys/include/net/gnrc/sixlowpan/internal.h +++ b/sys/include/net/gnrc/sixlowpan/internal.h @@ -27,6 +27,14 @@ extern "C" { #endif +/** + * @brief Returns the PID of the 6Lo thread + * + * @return The PID of the 6Lo thread on success + * @return KERNEL_PID_UNDEF, when 6Lo thread was not started. + */ +kernel_pid_t gnrc_sixlowpan_get_pid(void); + /** * @brief Delegates a packet to the network layer * diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c b/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c index 4a7de40c6cc7..79cb69a5563d 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c @@ -241,7 +241,6 @@ void gnrc_sixlowpan_frag_send(gnrc_pktsnip_t *pkt, void *ctx, unsigned page) /* payload_len: actual size of the packet vs * datagram_size: size of the uncompressed IPv6 packet */ size_t payload_len = gnrc_pkt_len(fragment_msg->pkt->next); - msg_t msg; assert((fragment_msg->pkt == pkt) || (pkt == NULL)); (void)page; @@ -284,9 +283,7 @@ void gnrc_sixlowpan_frag_send(gnrc_pktsnip_t *pkt, void *ctx, unsigned page) goto error; } fragment_msg->offset += res; - msg.type = GNRC_SIXLOWPAN_MSG_FRAG_SND, - msg.content.ptr = fragment_msg; - if (msg_send_to_self(&msg) == 0) { + if (!gnrc_sixlowpan_frag_send_msg(fragment_msg)) { DEBUG("6lo frag: message queue full, can't issue next fragment " "sending\n"); goto error; diff --git a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c index d7be77b5aa04..b192ad1f13b1 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c +++ b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c @@ -55,6 +55,11 @@ kernel_pid_t gnrc_sixlowpan_init(void) return _pid; } +kernel_pid_t gnrc_sixlowpan_get_pid(void) +{ + return _pid; +} + void gnrc_sixlowpan_dispatch_recv(gnrc_pktsnip_t *pkt, void *context, unsigned page) {