Skip to content

Commit

Permalink
gnrc_sixlowpan_frag: encapsulate msg_send_to_self()
Browse files Browse the repository at this point in the history
This makes it easier to access this functionality for test cases e.g.
from the `main` thread.
  • Loading branch information
miri64 committed Mar 8, 2019
1 parent d562af4 commit 931b179
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
26 changes: 25 additions & 1 deletion sys/include/net/gnrc/sixlowpan/frag.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
#include <stdbool.h>

#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"

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions sys/include/net/gnrc/sixlowpan/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 931b179

Please # to comment.