From 1f7770da5c9fea471525a67127b827dae60bed1f Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Fri, 27 Sep 2019 18:17:07 +0200 Subject: [PATCH] gnrc_sixlowpan_frag: move public rbuf functions to their own module --- Makefile.dep | 1 + sys/Makefile.include | 3 + sys/net/gnrc/Makefile | 3 + .../sixlowpan/frag/gnrc_sixlowpan_frag.c | 57 ------------ .../network_layer/sixlowpan/frag/rb/Makefile | 3 + .../frag/rb/gnrc_sixlowpan_frag_rb.c | 86 +++++++++++++++++++ 6 files changed, 96 insertions(+), 57 deletions(-) create mode 100644 sys/net/gnrc/network_layer/sixlowpan/frag/rb/Makefile create mode 100644 sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c diff --git a/Makefile.dep b/Makefile.dep index b910e8f8a3..59ebed0eba 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -212,6 +212,7 @@ endif ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE))) USEMODULE += gnrc_sixlowpan + USEMODULE += gnrc_sixlowpan_frag_rb USEMODULE += xtimer endif diff --git a/sys/Makefile.include b/sys/Makefile.include index bdc8147ff8..80fd4b458e 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -5,6 +5,9 @@ endif ifneq (,$(filter gnrc_netif,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/gnrc/netif/include endif +ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE))) + USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/gnrc/network_layer/sixlowpan/frag +endif ifneq (,$(filter gnrc_sock,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/gnrc/sock/include ifneq (,$(filter gnrc_ipv6,$(USEMODULE))) diff --git a/sys/net/gnrc/Makefile b/sys/net/gnrc/Makefile index d26036d5af..31da5312a0 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -91,6 +91,9 @@ endif ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE))) DIRS += network_layer/sixlowpan/frag endif +ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE))) + DIRS += network_layer/sixlowpan/frag/rb +endif ifneq (,$(filter gnrc_sixlowpan_frag_vrb,$(USEMODULE))) DIRS += network_layer/sixlowpan/frag/vrb endif 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 3f454a3099..7efec5945f 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 @@ -368,61 +368,4 @@ uint16_t gnrc_sixlowpan_frag_next_tag(void) return (++_current_tag); } -void gnrc_sixlowpan_frag_rbuf_base_rm(gnrc_sixlowpan_rbuf_base_t *entry) -{ - while (entry->ints != NULL) { - gnrc_sixlowpan_rbuf_int_t *next = entry->ints->next; - - entry->ints->start = 0; - entry->ints->end = 0; - entry->ints->next = NULL; - entry->ints = next; - } - entry->datagram_size = 0; -} - -void gnrc_sixlowpan_frag_rbuf_gc(void) -{ - rbuf_gc(); -} - -void gnrc_sixlowpan_frag_rbuf_remove(gnrc_sixlowpan_rbuf_t *rbuf) -{ - assert(rbuf != NULL); - rbuf_rm(rbuf); -} - -void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf, - gnrc_netif_hdr_t *netif_hdr) -{ - assert(rbuf); - assert(netif_hdr); - if (rbuf->super.current_size == rbuf->super.datagram_size) { - gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(rbuf->super.src, - rbuf->super.src_len, - rbuf->super.dst, - rbuf->super.dst_len); - - if (netif == NULL) { - DEBUG("6lo rbuf: error allocating netif header\n"); - gnrc_pktbuf_release(rbuf->pkt); - gnrc_sixlowpan_frag_rbuf_remove(rbuf); - return; - } - - /* copy the transmit information of the latest fragment into the newly - * created header to have some link_layer information. The link_layer - * info of the previous fragments is discarded. - */ - gnrc_netif_hdr_t *new_netif_hdr = netif->data; - new_netif_hdr->if_pid = netif_hdr->if_pid; - new_netif_hdr->flags = netif_hdr->flags; - new_netif_hdr->lqi = netif_hdr->lqi; - new_netif_hdr->rssi = netif_hdr->rssi; - LL_APPEND(rbuf->pkt, netif); - gnrc_sixlowpan_dispatch_recv(rbuf->pkt, NULL, 0); - gnrc_sixlowpan_frag_rbuf_remove(rbuf); - } -} - /** @} */ diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rb/Makefile b/sys/net/gnrc/network_layer/sixlowpan/frag/rb/Makefile new file mode 100644 index 0000000000..80d869fe14 --- /dev/null +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rb/Makefile @@ -0,0 +1,3 @@ +MODULE := gnrc_sixlowpan_frag_rb + +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c new file mode 100644 index 0000000000..646a04ee7c --- /dev/null +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rb/gnrc_sixlowpan_frag_rb.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2019 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @author Martine Lenders + */ + +#include "net/ieee802154.h" +#include "net/gnrc/netif/hdr.h" +#include "net/gnrc/pkt.h" +#include "net/gnrc/sixlowpan.h" + +#include "net/gnrc/sixlowpan/frag/rb.h" + +#include "rbuf.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +void gnrc_sixlowpan_frag_rbuf_base_rm(gnrc_sixlowpan_rbuf_base_t *entry) +{ + while (entry->ints != NULL) { + gnrc_sixlowpan_rbuf_int_t *next = entry->ints->next; + + entry->ints->start = 0; + entry->ints->end = 0; + entry->ints->next = NULL; + entry->ints = next; + } + entry->datagram_size = 0; +} + +void gnrc_sixlowpan_frag_rbuf_gc(void) +{ + rbuf_gc(); +} + +void gnrc_sixlowpan_frag_rbuf_remove(gnrc_sixlowpan_rbuf_t *rbuf) +{ + assert(rbuf != NULL); + rbuf_rm(rbuf); +} + +void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf, + gnrc_netif_hdr_t *netif_hdr) +{ + assert(rbuf); + assert(netif_hdr); + if (rbuf->super.current_size == rbuf->super.datagram_size) { + gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(rbuf->super.src, + rbuf->super.src_len, + rbuf->super.dst, + rbuf->super.dst_len); + + if (netif == NULL) { + DEBUG("6lo rbuf: error allocating netif header\n"); + gnrc_pktbuf_release(rbuf->pkt); + gnrc_sixlowpan_frag_rbuf_remove(rbuf); + return; + } + + /* copy the transmit information of the latest fragment into the newly + * created header to have some link_layer information. The link_layer + * info of the previous fragments is discarded. + */ + gnrc_netif_hdr_t *new_netif_hdr = netif->data; + new_netif_hdr->if_pid = netif_hdr->if_pid; + new_netif_hdr->flags = netif_hdr->flags; + new_netif_hdr->lqi = netif_hdr->lqi; + new_netif_hdr->rssi = netif_hdr->rssi; + LL_APPEND(rbuf->pkt, netif); + gnrc_sixlowpan_dispatch_recv(rbuf->pkt, NULL, 0); + gnrc_sixlowpan_frag_rbuf_remove(rbuf); + } +} + + +/** @} */