Browse Source

sixlowpan: move non-GNRC stuff to its own module

dev/timer
Martine Lenders 8 years ago committed by Martine Lenders
parent
commit
93031c9b60
  1. 5
      Makefile.dep
  2. 3
      sys/Makefile
  3. 27
      sys/include/net/ng_sixlowpan.h
  4. 67
      sys/include/net/ng_sixlowpan/frag.h
  5. 114
      sys/include/net/ng_sixlowpan/iphc.h
  6. 259
      sys/include/net/sixlowpan.h
  7. 4
      sys/net/crosslayer/ng_pktdump/ng_pktdump.c
  8. 33
      sys/net/network_layer/ng_sixlowpan/frag/ng_sixlowpan_frag.c
  9. 15
      sys/net/network_layer/ng_sixlowpan/frag/rbuf.c
  10. 43
      sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c
  11. 9
      sys/net/network_layer/ng_sixlowpan/ng_sixlowpan.c
  12. 1
      sys/net/network_layer/sixlowpan/Makefile
  13. 62
      sys/net/network_layer/sixlowpan/sixlowpan_print.c

5
Makefile.dep

@ -71,6 +71,7 @@ ifneq (,$(filter ng_sixlowpan,$(USEMODULE)))
USEMODULE += ng_ipv6
USEMODULE += ng_sixlowpan_netif
USEMODULE += gnrc
USEMODULE += sixlowpan
endif
ifneq (,$(filter ng_sixlowpan_ctx,$(USEMODULE)))
@ -142,6 +143,10 @@ ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE)))
USEMODULE += ng_pktbuf
endif
ifneq (,$(filter sixlowpan,$(USEMODULE)))
USEMODULE += ipv6_hdr
endif
ifneq (,$(filter ipv6_hdr,$(USEMODULE)))
USEMODULE += inet_csum
endif

3
sys/Makefile

@ -127,6 +127,9 @@ endif
ifneq (,$(filter ng_udp,$(USEMODULE)))
DIRS += net/transport_layer/ng_udp
endif
ifneq (,$(filter sixlowpan,$(USEMODULE)))
DIRS += net/network_layer/sixlowpan
endif
ifneq (,$(filter hwtimer_compat,$(USEMODULE)))
DIRS += compat/hwtimer
endif

27
sys/include/net/ng_sixlowpan.h

@ -26,6 +26,7 @@
#include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/iphc.h"
#include "net/sixlowpan.h"
#ifdef __cplusplus
extern "C" {
@ -52,24 +53,6 @@ extern "C" {
#define NG_SIXLOWPAN_MSG_QUEUE_SIZE (8U)
#endif
/**
* @brief Dispatch for uncompressed 6LoWPAN frame.
*/
#define NG_SIXLOWPAN_UNCOMPRESSED (0x41)
/**
* @brief Checks if dispatch indicates that frame is not a 6LoWPAN (NALP) frame.
*
* @param[in] disp The first byte of a frame.
*
* @return true, if frame is a NALP.
* @return false, if frame is not a NALP.
*/
static inline bool ng_sixlowpan_nalp(uint8_t disp)
{
return (disp & 0x3f);
}
/**
* @brief Initialization of the 6LoWPAN thread.
*
@ -83,14 +66,6 @@ static inline bool ng_sixlowpan_nalp(uint8_t disp)
*/
kernel_pid_t ng_sixlowpan_init(void);
/**
* @brief Prints 6LoWPAN dispatch to stdout.
*
* @param[in] data A 6LoWPAN frame.
* @param[in] size Size of @p data.
*/
void ng_sixlowpan_print(uint8_t *data, size_t size);
#ifdef __cplusplus
}
#endif

67
sys/include/net/ng_sixlowpan/frag.h

@ -29,77 +29,12 @@
#include "byteorder.h"
#include "kernel_types.h"
#include "net/ng_pkt.h"
#include "net/sixlowpan.h"
#ifdef __cplusplus
extern "C" {
#endif
#define NG_SIXLOWPAN_FRAG_DISP_MASK (0xf8) /**< mask for fragmentation
* dispatch */
#define NG_SIXLOWPAN_FRAG_1_DISP (0xc0) /**< dispatch for 1st fragment */
#define NG_SIXLOWPAN_FRAG_N_DISP (0xe0) /**< dispatch for subsequent
* fragments */
#define NG_SIXLOWPAN_FRAG_SIZE_MASK (0x07ff) /**< mask for datagram size */
/**
* @brief General and 1st 6LoWPAN fragmentation header
*
* @note The general 6LoWPAN fragmentation header refers to the first 4
* bytes of a \c FRAG0 or \c FRAGN fragmentation header, which are
* identical.
*
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
* RFC 4944, section 5.3
* </a>
*/
typedef struct __attribute__((packed)) {
/**
* @brief Dispatch and datagram size.
*
* @details The 5 most significant bits are the dispatch, the remaining
* bits are the size.
*/
network_uint16_t disp_size;
network_uint16_t tag; /**< datagram tag */
} ng_sixlowpan_frag_t;
/**
* @brief Subsequent 6LoWPAN fragmentation header
*
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
* RFC 4944, section 5.3
* </a>
*
* @extends ng_sixlowpan_frag_t
*/
typedef struct __attribute__((packed)) {
/**
* @brief Dispatch and datagram size.
*
* @details The 5 most significant bits are the dispatch, the remaining
* bits are the size.
*/
network_uint16_t disp_size;
network_uint16_t tag; /**< datagram tag */
uint8_t offset; /**< offset */
} ng_sixlowpan_frag_n_t;
/**
* @brief Checks if a given fragment is a 6LoWPAN fragment.
*
* @param[in] hdr A 6LoWPAN fragmentation header.
*
* @return true, if given fragment is a 6LoWPAN fragment.
* @return false, if given fragment is not a 6LoWPAN fragment.
*/
static inline bool ng_sixlowpan_frag_is(ng_sixlowpan_frag_t *hdr)
{
return ((hdr->disp_size.u8[0] & NG_SIXLOWPAN_FRAG_DISP_MASK) ==
NG_SIXLOWPAN_FRAG_1_DISP) ||
((hdr->disp_size.u8[0] & NG_SIXLOWPAN_FRAG_DISP_MASK) ==
NG_SIXLOWPAN_FRAG_N_DISP);
}
/**
* @brief Sends a packet fragmented.
*

114
sys/include/net/ng_sixlowpan/iphc.h

@ -23,124 +23,12 @@
#include <stdbool.h>
#include "net/ng_pkt.h"
#include "net/sixlowpan.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Dispatch mask for LOWPAN_IPHC.
*/
#define NG_SIXLOWPAN_IPHC1_DISP_MASK (0xe0)
/**
* @brief Dispatch for LOWPAN_IPHC.
*/
#define NG_SIXLOWPAN_IPHC1_DISP (0x60)
/**
* @brief Flag for Traffic Class & Flow Label elision (part of first byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC1_TF (0x18)
/**
* @brief Flag for Next Header Compression (part of first byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC1_NH (0x04)
/**
* @brief Flag for Hop Limit elision (part of first byte of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC1_HL (0x03)
/**
* @brief Flag for Context Identifier Extention (part of second byte
* of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC2_CID_EXT (0x80)
/**
* @brief Flag for Source Address Compression (part of second byte
* of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC2_SAC (0x40)
/**
* @brief Bits for Source Address Mode (part of second byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC2_SAM (0x30)
/**
* @brief Flag for Destination Address Compression (part of second
* byte of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC2_DAC (0x04)
/**
* @brief Bits for Destination Address Mode (part of second byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC2_DAM (0x03)
/**
* @brief Flag for Multicast Compression (part of second byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define NG_SIXLOWPAN_IPHC2_M (0x08)
/**
* @brief 6LoWPAN IPHC header length
*/
#define NG_SIXLOWPAN_IPHC_HDR_LEN (2)
/**
* @brief 6LoWPAN context idendifier extension header length
*/
#define NG_SIXLOWPAN_IPHC_CID_EXT_LEN (1)
/**
* @brief Checks if datagram is an IPHC datagram.
*
* @param[in] data Data of a datagram, may not be NULL.
*
* @return true, if datagram is an IPHC datagram.
* @return false, if datagram is not an IPHC datagram.
*/
static inline bool ng_sixlowpan_iphc_is(uint8_t *data)
{
return ((*data & NG_SIXLOWPAN_IPHC1_DISP_MASK) == NG_SIXLOWPAN_IPHC1_DISP);
}
/**
* @brief Decompresses a received 6LoWPAN IPHC frame.
*

259
sys/include/net/sixlowpan.h

@ -0,0 +1,259 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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.
*/
/**
* @defgroup net_sixlowpan 6LoWPAN
* @ingroup net
* @brief Generic 6LoWPAN types and helper functions
* @{
*
* @file
* @brief 6LoWPAN type and helper function definitons.
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef SIXLOWPAN_H_
#define SIXLOWPAN_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name 6LoWPAN dispatch definition
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.1">
* RFC 4944, section 5.1
* </a>
* @{
*/
#define SIXLOWPAN_UNCOMP (0x41) /**< uncompressed 6LoWPAN frame dispatch. */
#define SIXLOWPAN_FRAG_DISP_MASK (0xf8) /**< mask for fragmentation
* dispatch */
#define SIXLOWPAN_FRAG_1_DISP (0xc0) /**< dispatch for 1st fragment */
#define SIXLOWPAN_FRAG_N_DISP (0xe0) /**< dispatch for subsequent
* fragments */
/**
* @brief Dispatch mask for LOWPAN_IPHC.
* @see <a href="https://tools.ietf.org/html/rfc6282#section-3.1">
* RFC 6282, section 3.1
* </a>
*/
#define SIXLOWPAN_IPHC1_DISP_MASK (0xe0)
/**
* @brief Dispatch for LOWPAN_IPHC.
* @see <a href="https://tools.ietf.org/html/rfc6282#section-3.1">
* RFC 6282, section 3.1
* </a>
*/
#define SIXLOWPAN_IPHC1_DISP (0x60)
/**
* @brief Checks if dispatch indicates that frame is not a 6LoWPAN (NALP) frame.
*
* @param[in] disp The first byte of a frame.
*
* @return true, if frame is a NALP.
* @return false, if frame is not a NALP.
*/
static inline bool sixlowpan_nalp(uint8_t disp)
{
return (disp & 0x3f);
}
/** @} */
/**
* @name 6LoWPAN fragmentation header definitions
* @{
*/
#define SIXLOWPAN_FRAG_SIZE_MASK (0x07ff) /**< mask for datagram size */
/**
* @brief General and 1st 6LoWPAN fragmentation header
*
* @note The general 6LoWPAN fragmentation header refers to the first 4
* bytes of a \c FRAG0 or \c FRAGN fragmentation header, which are
* identical.
*
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
* RFC 4944, section 5.3
* </a>
*/
typedef struct __attribute__((packed)) {
/**
* @brief Dispatch and datagram size.
*
* @details The 5 most significant bits are the dispatch, the remaining
* bits are the size.
*/
network_uint16_t disp_size;
network_uint16_t tag; /**< datagram tag */
} sixlowpan_frag_t;
/**
* @brief Subsequent 6LoWPAN fragmentation header
*
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
* RFC 4944, section 5.3
* </a>
*
* @extends sixlowpan_frag_t
*/
typedef struct __attribute__((packed)) {
/**
* @brief Dispatch and datagram size.
*
* @details The 5 most significant bits are the dispatch, the remaining
* bits are the size.
*/
network_uint16_t disp_size;
network_uint16_t tag; /**< datagram tag */
uint8_t offset; /**< offset */
} sixlowpan_frag_n_t;
/**
* @brief Checks if a given fragment is a 6LoWPAN fragment.
*
* @param[in] hdr A 6LoWPAN fragmentation header.
*
* @return true, if given fragment is a 6LoWPAN fragment.
* @return false, if given fragment is not a 6LoWPAN fragment.
*/
static inline bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
{
return ((hdr->disp_size.u8[0] & SIXLOWPAN_FRAG_DISP_MASK) ==
SIXLOWPAN_FRAG_1_DISP) ||
((hdr->disp_size.u8[0] & SIXLOWPAN_FRAG_DISP_MASK) ==
SIXLOWPAN_FRAG_N_DISP);
}
/** @} */
/**
* @name 6LoWPAN IPHC dispatch definitions
* @{
*/
/**
* @brief Flag for Traffic Class & Flow Label elision (part of first byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC1_TF (0x18)
/**
* @brief Flag for Next Header Compression (part of first byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC1_NH (0x04)
/**
* @brief Flag for Hop Limit elision (part of first byte of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC1_HL (0x03)
/**
* @brief Flag for Context Identifier Extention (part of second byte
* of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC2_CID_EXT (0x80)
/**
* @brief Flag for Source Address Compression (part of second byte
* of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC2_SAC (0x40)
/**
* @brief Bits for Source Address Mode (part of second byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC2_SAM (0x30)
/**
* @brief Flag for Destination Address Compression (part of second
* byte of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC2_DAC (0x04)
/**
* @brief Bits for Destination Address Mode (part of second byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC2_DAM (0x03)
/**
* @brief Flag for Multicast Compression (part of second byte of
* LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 6282, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC2_M (0x08)
/**
* @brief 6LoWPAN IPHC header length
*/
#define SIXLOWPAN_IPHC_HDR_LEN (2)
/**
* @brief 6LoWPAN context idendifier extension header length
*/
#define SIXLOWPAN_IPHC_CID_EXT_LEN (1)
/**
* @brief Checks if datagram is an IPHC datagram.
*
* @param[in] data Data of a datagram, may not be NULL.
*
* @return true, if datagram is an IPHC datagram.
* @return false, if datagram is not an IPHC datagram.
*/
static inline bool sixlowpan_iphc_is(uint8_t *data)
{
return ((*data & SIXLOWPAN_IPHC1_DISP_MASK) == SIXLOWPAN_IPHC1_DISP);
}
/** @} */
/**
* @brief Prints 6LoWPAN dispatch to stdout.
*
* @param[in] data A 6LoWPAN frame.
* @param[in] size Size of @p data.
*/
void sixlowpan_print(uint8_t *data, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* SIXLOWPAN_H_ */
/** @} */

4
sys/net/crosslayer/ng_pktdump/ng_pktdump.c

@ -30,8 +30,8 @@
#include "net/gnrc.h"
#include "net/ipv6/addr.h"
#include "net/ipv6/hdr.h"
#include "net/ng_sixlowpan.h"
#include "net/udp.h"
#include "net/sixlowpan.h"
#include "od.h"
/**
@ -60,7 +60,7 @@ static void _dump_snip(ng_pktsnip_t *pkt)
#ifdef MODULE_NG_SIXLOWPAN
case NG_NETTYPE_SIXLOWPAN:
printf("NETTYPE_SIXLOWPAN (%i)\n", pkt->type);
ng_sixlowpan_print(pkt->data, pkt->size);
sixlowpan_print(pkt->data, pkt->size);
break;
#endif
#ifdef MODULE_NG_IPV6

33
sys/net/network_layer/ng_sixlowpan/frag/ng_sixlowpan_frag.c

@ -18,6 +18,7 @@
#include "net/ng_netif/hdr.h"
#include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/netif.h"
#include "net/sixlowpan.h"
#include "utlist.h"
#include "rbuf.h"
@ -87,14 +88,14 @@ static uint16_t _send_1st_fragment(ng_sixlowpan_netif_t *iface, ng_pktsnip_t *pk
/* virtually add payload_diff to flooring to account for offset (must be divisable by 8)
* in uncompressed datagram */
uint16_t max_frag_size = _floor8(iface->max_frag_size + payload_diff -
sizeof(ng_sixlowpan_frag_t)) - payload_diff;
ng_sixlowpan_frag_t *hdr;
sizeof(sixlowpan_frag_t)) - payload_diff;
sixlowpan_frag_t *hdr;
uint8_t *data;
DEBUG("6lo frag: determined max_frag_size = %" PRIu16 "\n", max_frag_size);
frag = _build_frag_pkt(pkt, payload_len,
max_frag_size + sizeof(ng_sixlowpan_frag_t));
max_frag_size + sizeof(sixlowpan_frag_t));
if (frag == NULL) {
return 0;
@ -104,7 +105,7 @@ static uint16_t _send_1st_fragment(ng_sixlowpan_netif_t *iface, ng_pktsnip_t *pk
data = (uint8_t *)(hdr + 1);
hdr->disp_size = byteorder_htons((uint16_t)datagram_size);
hdr->disp_size.u8[0] |= NG_SIXLOWPAN_FRAG_1_DISP;
hdr->disp_size.u8[0] |= SIXLOWPAN_FRAG_1_DISP;
hdr->tag = byteorder_htons(_tag);
pkt = pkt->next; /* don't copy netif header */
@ -137,16 +138,16 @@ static uint16_t _send_nth_fragment(ng_sixlowpan_netif_t *iface, ng_pktsnip_t *pk
ng_pktsnip_t *frag;
/* since dispatches aren't supposed to go into subsequent fragments, we need not account
* for payload difference as for the first fragment */
uint16_t max_frag_size = _floor8(iface->max_frag_size - sizeof(ng_sixlowpan_frag_n_t));
uint16_t max_frag_size = _floor8(iface->max_frag_size - sizeof(sixlowpan_frag_n_t));
uint16_t local_offset = 0, offset_count = 0;
ng_sixlowpan_frag_n_t *hdr;
sixlowpan_frag_n_t *hdr;
uint8_t *data;
DEBUG("6lo frag: determined max_frag_size = %" PRIu16 "\n", max_frag_size);
frag = _build_frag_pkt(pkt,
payload_len - offset + sizeof(ng_sixlowpan_frag_n_t),
max_frag_size + sizeof(ng_sixlowpan_frag_n_t));
payload_len - offset + sizeof(sixlowpan_frag_n_t),
max_frag_size + sizeof(sixlowpan_frag_n_t));
if (frag == NULL) {
return 0;
@ -157,7 +158,7 @@ static uint16_t _send_nth_fragment(ng_sixlowpan_netif_t *iface, ng_pktsnip_t *pk
/* XXX: truncation of datagram_size > 4095 may happen here */
hdr->disp_size = byteorder_htons((uint16_t)datagram_size);
hdr->disp_size.u8[0] |= NG_SIXLOWPAN_FRAG_N_DISP;
hdr->disp_size.u8[0] |= SIXLOWPAN_FRAG_N_DISP;
hdr->tag = byteorder_htons(_tag);
/* don't mention payload diff in offset */
hdr->offset = (uint8_t)((offset + (datagram_size - payload_len)) >> 3);
@ -255,18 +256,18 @@ void ng_sixlowpan_frag_send(kernel_pid_t pid, ng_pktsnip_t *pkt,
void ng_sixlowpan_frag_handle_pkt(ng_pktsnip_t *pkt)
{
ng_netif_hdr_t *hdr = pkt->next->data;
ng_sixlowpan_frag_t *frag = pkt->data;
sixlowpan_frag_t *frag = pkt->data;
uint16_t offset = 0;
size_t frag_size;
switch (frag->disp_size.u8[0] & NG_SIXLOWPAN_FRAG_DISP_MASK) {
case NG_SIXLOWPAN_FRAG_1_DISP:
frag_size = (pkt->size - sizeof(ng_sixlowpan_frag_t));
switch (frag->disp_size.u8[0] & SIXLOWPAN_FRAG_DISP_MASK) {
case SIXLOWPAN_FRAG_1_DISP:
frag_size = (pkt->size - sizeof(sixlowpan_frag_t));
break;
case NG_SIXLOWPAN_FRAG_N_DISP:
offset = (((ng_sixlowpan_frag_n_t *)frag)->offset * 8);
frag_size = (pkt->size - sizeof(ng_sixlowpan_frag_n_t));
case SIXLOWPAN_FRAG_N_DISP:
offset = (((sixlowpan_frag_n_t *)frag)->offset * 8);
frag_size = (pkt->size - sizeof(sixlowpan_frag_n_t));
break;
default:

15
sys/net/network_layer/ng_sixlowpan/frag/rbuf.c

@ -16,11 +16,12 @@
#include <stdbool.h>
#include "rbuf.h"
#include "net/ipv6/hdr.h"
#include "net/gnrc.h"
#include "net/ng_ipv6/hdr.h"
#include "net/ng_ipv6/netif.h"
#include "net/ng_sixlowpan.h"
#include "net/ng_sixlowpan/frag.h"
#include "net/sixlowpan.h"
#include "thread.h"
#include "timex.h"
#include "vtimer.h"
@ -66,14 +67,14 @@ void rbuf_add(ng_netif_hdr_t *netif_hdr, ng_pktsnip_t *pkt,
/* cppcheck is clearly wrong here */
/* cppcheck-suppress variableScope */
unsigned int data_offset = 0;
ng_sixlowpan_frag_t *frag = pkt->data;
sixlowpan_frag_t *frag = pkt->data;
rbuf_int_t *ptr;
uint8_t *data = ((uint8_t *)pkt->data) + sizeof(ng_sixlowpan_frag_t);
uint8_t *data = ((uint8_t *)pkt->data) + sizeof(sixlowpan_frag_t);
_rbuf_gc();
entry = _rbuf_get(ng_netif_hdr_get_src_addr(netif_hdr), netif_hdr->src_l2addr_len,
ng_netif_hdr_get_dst_addr(netif_hdr), netif_hdr->dst_l2addr_len,
byteorder_ntohs(frag->disp_size) & NG_SIXLOWPAN_FRAG_SIZE_MASK,
byteorder_ntohs(frag->disp_size) & SIXLOWPAN_FRAG_SIZE_MASK,
byteorder_ntohs(frag->tag));
if (entry == NULL) {
@ -85,15 +86,15 @@ void rbuf_add(ng_netif_hdr_t *netif_hdr, ng_pktsnip_t *pkt,
/* dispatches in the first fragment are ignored */
if (offset == 0) {
if (data[0] == NG_SIXLOWPAN_UNCOMPRESSED) {
if (data[0] == SIXLOWPAN_UNCOMP) {
data++; /* skip 6LoWPAN dispatch */
frag_size--;
}
#ifdef MODULE_NG_SIXLOWPAN_IPHC
else if (ng_sixlowpan_iphc_is(data)) {
else if (sixlowpan_iphc_is(data)) {
size_t iphc_len;
iphc_len = ng_sixlowpan_iphc_decode(entry->pkt, pkt,
sizeof(ng_sixlowpan_frag_t));
sizeof(sixlowpan_frag_t));
if (iphc_len == 0) {
DEBUG("6lo rfrag: could not decode IPHC dispatch\n");
ng_pktbuf_release(entry->pkt);

43
sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c

@ -19,6 +19,7 @@
#include "net/ipv6/hdr.h"
#include "net/gnrc.h"
#include "net/ng_sixlowpan/ctx.h"
#include "net/sixlowpan.h"
#include "utlist.h"
#include "net/ng_sixlowpan/iphc.h"
@ -94,7 +95,7 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
ng_netif_hdr_t *netif_hdr = pkt->next->data;
ipv6_hdr_t *ipv6_hdr;
uint8_t *iphc_hdr = pkt->data;
size_t payload_offset = NG_SIXLOWPAN_IPHC_HDR_LEN;
size_t payload_offset = SIXLOWPAN_IPHC_HDR_LEN;
ng_sixlowpan_ctx_t *ctx = NULL;
assert(ipv6 != NULL);
@ -103,13 +104,13 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
ipv6_hdr = ipv6->data;
iphc_hdr += offset;
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_CID_EXT) {
payload_offset++;
}
ipv6_hdr_set_version(ipv6_hdr);
switch (iphc_hdr[IPHC1_IDX] & NG_SIXLOWPAN_IPHC1_TF) {
switch (iphc_hdr[IPHC1_IDX] & SIXLOWPAN_IPHC1_TF) {
case IPHC_TF_ECN_DSCP_FL:
ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]);
ipv6_hdr->v_tc_fl.u8[1] |= iphc_hdr[payload_offset++] & 0x0f;
@ -136,11 +137,11 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
break;
}
if (!(iphc_hdr[IPHC1_IDX] & NG_SIXLOWPAN_IPHC1_NH)) {
if (!(iphc_hdr[IPHC1_IDX] & SIXLOWPAN_IPHC1_NH)) {
ipv6_hdr->nh = iphc_hdr[payload_offset++];
}
switch (iphc_hdr[IPHC1_IDX] & NG_SIXLOWPAN_IPHC1_HL) {
switch (iphc_hdr[IPHC1_IDX] & SIXLOWPAN_IPHC1_HL) {
case IPHC_HL_INLINE:
ipv6_hdr->hl = iphc_hdr[payload_offset++];
break;
@ -158,14 +159,14 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
break;
}
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAC) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_SAC) {
uint8_t sci = 0;
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_CID_EXT) {
sci = iphc_hdr[CID_EXT_IDX] >> 4;
}
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAM) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_SAM) {
ctx = ng_sixlowpan_ctx_lookup_id(sci);
if (ctx == NULL) {
@ -175,7 +176,7 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
}
}
switch (iphc_hdr[IPHC2_IDX] & (NG_SIXLOWPAN_IPHC2_SAC | NG_SIXLOWPAN_IPHC2_SAM)) {
switch (iphc_hdr[IPHC2_IDX] & (SIXLOWPAN_IPHC2_SAC | SIXLOWPAN_IPHC2_SAM)) {
/* should be asserted by line 168 anyway */
assert(ctx != NULL);
@ -235,14 +236,14 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
break;
}
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAC) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_DAC) {
uint8_t dci = 0;
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_CID_EXT) {
dci = iphc_hdr[CID_EXT_IDX] & 0x0f;
}
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAM) {
if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_DAM) {
ctx = ng_sixlowpan_ctx_lookup_id(dci);
if (ctx == NULL) {
@ -252,8 +253,8 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
}
}
switch (iphc_hdr[IPHC2_IDX] & (NG_SIXLOWPAN_IPHC2_M | NG_SIXLOWPAN_IPHC2_DAC |
NG_SIXLOWPAN_IPHC2_DAM)) {
switch (iphc_hdr[IPHC2_IDX] & (SIXLOWPAN_IPHC2_M | SIXLOWPAN_IPHC2_DAC |
SIXLOWPAN_IPHC2_DAM)) {
case IPHC_M_DAC_DAM_U_FULL:
case IPHC_M_DAC_DAM_M_FULL:
memcpy(&(ipv6_hdr->dst.u8), iphc_hdr + payload_offset, 16);
@ -380,7 +381,7 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
ng_netif_hdr_t *netif_hdr = pkt->data;
ipv6_hdr_t *ipv6_hdr = pkt->next->data;
uint8_t *iphc_hdr;
uint16_t inline_pos = NG_SIXLOWPAN_IPHC_HDR_LEN;
uint16_t inline_pos = SIXLOWPAN_IPHC_HDR_LEN;
bool addr_comp = false;
ng_sixlowpan_ctx_t *src_ctx = NULL, *dst_ctx = NULL;
ng_pktsnip_t *dispatch = ng_pktbuf_add(NULL, NULL, pkt->next->size,
@ -394,7 +395,7 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
iphc_hdr = dispatch->data;
/* set initial dispatch value*/
iphc_hdr[IPHC1_IDX] = NG_SIXLOWPAN_IPHC1_DISP;
iphc_hdr[IPHC1_IDX] = SIXLOWPAN_IPHC1_DISP;
iphc_hdr[IPHC2_IDX] = 0;
/* check for available contexts */
@ -415,11 +416,11 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
((dst_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_CID_MASK) != 0) &&
(dst_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_COMP))) {
/* add context identifier extension */
iphc_hdr[IPHC2_IDX] |= NG_SIXLOWPAN_IPHC2_CID_EXT;
iphc_hdr[IPHC2_IDX] |= SIXLOWPAN_IPHC2_CID_EXT;
iphc_hdr[CID_EXT_IDX] = 0;
/* move position to behind CID extension */
inline_pos += NG_SIXLOWPAN_IPHC_CID_EXT_LEN;
inline_pos += SIXLOWPAN_IPHC_CID_EXT_LEN;
}
/* compress flow label and traffic class */
@ -487,7 +488,7 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
else {
if ((src_ctx != NULL) && (src_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_COMP)) {
/* stateful source address compression */
iphc_hdr[IPHC2_IDX] |= NG_SIXLOWPAN_IPHC2_SAC;
iphc_hdr[IPHC2_IDX] |= SIXLOWPAN_IPHC2_SAC;
if (((src_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_CID_MASK) != 0)) {
iphc_hdr[CID_EXT_IDX] |= ((src_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_CID_MASK) << 4);
@ -546,7 +547,7 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
/* M: Multicast compression */
if (ipv6_addr_is_multicast(&(ipv6_hdr->dst))) {
iphc_hdr[IPHC2_IDX] |= NG_SIXLOWPAN_IPHC2_M;
iphc_hdr[IPHC2_IDX] |= SIXLOWPAN_IPHC2_M;
/* if multicast address is of format ffXX::XXXX:XXXX:XXXX */
if ((ipv6_hdr->dst.u16[1].u16 == 0) &&
@ -598,7 +599,7 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
/* Unicast prefix based IPv6 multicast address
* (https://tools.ietf.org/html/rfc3306) with given context
* for unicast prefix -> context based compression */
iphc_hdr[IPHC2_IDX] |= NG_SIXLOWPAN_IPHC2_DAC;
iphc_hdr[IPHC2_IDX] |= SIXLOWPAN_IPHC2_DAC;
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[1];
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[2];
memcpy(iphc_hdr + inline_pos, ipv6_hdr->dst.u16 + 6, 4);

9
sys/net/network_layer/ng_sixlowpan/ng_sixlowpan.c

@ -22,6 +22,7 @@
#include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/iphc.h"
#include "net/ng_sixlowpan/netif.h"
#include "net/sixlowpan.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
@ -89,7 +90,7 @@ static void _receive(ng_pktsnip_t *pkt)
dispatch = payload->data;
if (dispatch[0] == NG_SIXLOWPAN_UNCOMPRESSED) {
if (dispatch[0] == SIXLOWPAN_UNCOMP) {
ng_pktsnip_t *sixlowpan;
DEBUG("6lo: received uncompressed IPv6 packet\n");
payload = ng_pktbuf_start_write(payload);
@ -115,14 +116,14 @@ static void _receive(ng_pktsnip_t *pkt)
pkt = ng_pktbuf_remove_snip(pkt, sixlowpan);
}
#ifdef MODULE_NG_SIXLOWPAN_FRAG
else if (ng_sixlowpan_frag_is((ng_sixlowpan_frag_t *)dispatch)) {
else if (sixlowpan_frag_is((sixlowpan_frag_t *)dispatch)) {
DEBUG("6lo: received 6LoWPAN fragment\n");
ng_sixlowpan_frag_handle_pkt(pkt);
return;
}
#endif
#ifdef MODULE_NG_SIXLOWPAN_IPHC
else if (ng_sixlowpan_iphc_is(dispatch)) {
else if (sixlowpan_iphc_is(dispatch)) {
size_t dispatch_size;
ng_pktsnip_t *sixlowpan;
ng_pktsnip_t *ipv6 = ng_pktbuf_add(NULL, NULL, sizeof(ipv6_hdr_t),
@ -181,7 +182,7 @@ static inline bool _add_uncompr_disp(ng_pktsnip_t *pkt)
sixlowpan->next = pkt->next;
pkt->next = sixlowpan;
disp = sixlowpan->data;
disp[0] = NG_SIXLOWPAN_UNCOMPRESSED;
disp[0] = SIXLOWPAN_UNCOMP;
return true;
}

1
sys/net/network_layer/sixlowpan/Makefile

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

62
sys/net/network_layer/ng_sixlowpan/ng_sixlowpan_print.c → sys/net/network_layer/sixlowpan/sixlowpan_print.c

@ -17,11 +17,11 @@
#include "od.h"
#include "net/ipv6/hdr.h"
#include "net/ng_sixlowpan.h"
#include "net/sixlowpan.h"
void ng_sixlowpan_print(uint8_t *data, size_t size)
void sixlowpan_print(uint8_t *data, size_t size)
{
if (data[0] == NG_SIXLOWPAN_UNCOMPRESSED) {
if (data[0] == SIXLOWPAN_UNCOMP) {
puts("Uncompressed IPv6 packet");
/* might just be the dispatch (or fragmented) so better check */
@ -32,40 +32,40 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
OD_WIDTH_DEFAULT);
}
}
else if (ng_sixlowpan_nalp(data[0])) {
else if (sixlowpan_nalp(data[0])) {
puts("Not a LoWPAN (NALP) frame");
od_hex_dump(data, size, OD_WIDTH_DEFAULT);
}
else if ((data[0] & NG_SIXLOWPAN_FRAG_DISP_MASK) == NG_SIXLOWPAN_FRAG_1_DISP) {
ng_sixlowpan_frag_t *hdr = (ng_sixlowpan_frag_t *)data;
else if ((data[0] & SIXLOWPAN_FRAG_DISP_MASK) == SIXLOWPAN_FRAG_1_DISP) {
sixlowpan_frag_t *hdr = (sixlowpan_frag_t *)data;
puts("Fragmentation Header (first)");
printf("datagram size: %" PRIu16 "\n",
byteorder_ntohs(hdr->disp_size) & NG_SIXLOWPAN_FRAG_SIZE_MASK);
byteorder_ntohs(hdr->disp_size) & SIXLOWPAN_FRAG_SIZE_MASK);
printf("tag: 0x%" PRIu16 "\n", byteorder_ntohs(hdr->tag));
/* Print next dispatch */
ng_sixlowpan_print(data + sizeof(ng_sixlowpan_frag_t),
size - sizeof(ng_sixlowpan_frag_t));
sixlowpan_print(data + sizeof(sixlowpan_frag_t),
size - sizeof(sixlowpan_frag_t));
}
else if ((data[0] & NG_SIXLOWPAN_FRAG_DISP_MASK) == NG_SIXLOWPAN_FRAG_N_DISP) {
ng_sixlowpan_frag_n_t *hdr = (ng_sixlowpan_frag_n_t *)data;
else if ((data[0] & SIXLOWPAN_FRAG_DISP_MASK) == SIXLOWPAN_FRAG_N_DISP) {
sixlowpan_frag_n_t *hdr = (sixlowpan_frag_n_t *)data;
puts("Fragmentation Header (subsequent)");
printf("datagram size: %" PRIu16 "\n",
byteorder_ntohs(hdr->disp_size) & NG_SIXLOWPAN_FRAG_SIZE_MASK);
byteorder_ntohs(hdr->disp_size) & SIXLOWPAN_FRAG_SIZE_MASK);
printf("tag: 0x%" PRIu16 "\n", byteorder_ntohs(hdr->tag));
printf("offset: 0x%" PRIu8 "\n", hdr->offset);
od_hex_dump(data + sizeof(ng_sixlowpan_frag_n_t),
size - sizeof(ng_sixlowpan_frag_n_t),
od_hex_dump(data + sizeof(sixlowpan_frag_n_t),
size - sizeof(sixlowpan_frag_n_t),
OD_WIDTH_DEFAULT);
}
else if ((data[0] & NG_SIXLOWPAN_IPHC1_DISP_MASK) == NG_SIXLOWPAN_IPHC1_DISP) {
uint8_t offset = NG_SIXLOWPAN_IPHC_HDR_LEN;
else if ((data[0] & SIXLOWPAN_IPHC1_DISP_MASK) == SIXLOWPAN_IPHC1_DISP) {
uint8_t offset = SIXLOWPAN_IPHC_HDR_LEN;
puts("IPHC dispatch");
switch (data[0] & NG_SIXLOWPAN_IPHC1_TF) {
switch (data[0] & SIXLOWPAN_IPHC1_TF) {
case 0x00:
puts("TF: ECN + DSCP + Flow Label (4 bytes)");
break;
@ -83,7 +83,7 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
break;
}
switch (data[0] & NG_SIXLOWPAN_IPHC1_NH) {
switch (data[0] & SIXLOWPAN_IPHC1_NH) {
case 0x00:
puts("NH: inline");
break;
@ -93,7 +93,7 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
break;
}
switch (data[0] & NG_SIXLOWPAN_IPHC1_HL) {
switch (data[0] & SIXLOWPAN_IPHC1_HL) {
case 0x00:
puts("HLIM: inline");
break;
@ -111,10 +111,10 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
break;
}
if (data[1] & NG_SIXLOWPAN_IPHC2_SAC) {
if (data[1] & SIXLOWPAN_IPHC2_SAC) {
printf("Stateful source address compression: ");
switch (data[1] & NG_SIXLOWPAN_IPHC2_SAM) {
switch (data[1] & SIXLOWPAN_IPHC2_SAM) {
case 0x00:
puts("unspecified address (::)");
break;
@ -135,7 +135,7 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
else {
printf("Stateless source address compression: ");
switch (data[1] & NG_SIXLOWPAN_IPHC2_SAM) {
switch (data[1] & SIXLOWPAN_IPHC2_SAM) {
case 0x00:
puts("128 bits inline");
break;
@ -154,11 +154,11 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
}
}
if (data[1] & NG_SIXLOWPAN_IPHC2_M) {
if (data[1] & NG_SIXLOWPAN_IPHC2_DAC) {
if (data[1] & SIXLOWPAN_IPHC2_M) {
if (data[1] & SIXLOWPAN_IPHC2_DAC) {
puts("Stateful destinaton multicast address compression:");
switch (data[1] & NG_SIXLOWPAN_IPHC2_DAM) {
switch (data[1] & SIXLOWPAN_IPHC2_DAM) {
case 0x00:
puts(" 48 bits carried inline (Unicast-Prefix-based)");
break;
@ -173,7 +173,7 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
else {
puts("Stateless destinaton multicast address compression:");
switch (data[1] & NG_SIXLOWPAN_IPHC2_DAM) {
switch (data[1] & SIXLOWPAN_IPHC2_DAM) {
case 0x00:
puts(" 128 bits carried inline");
break;
@ -193,10 +193,10 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
}
}
else {
if (data[1] & NG_SIXLOWPAN_IPHC2_DAC) {
if (data[1] & SIXLOWPAN_IPHC2_DAC) {
printf("Stateful destinaton address compression: ");
switch (data[1] & NG_SIXLOWPAN_IPHC2_DAM) {
switch (data[1] & SIXLOWPAN_IPHC2_DAM) {
case 0x00:
puts("reserved");
break;
@ -217,7 +217,7 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
else {
printf("Stateless destinaton address compression: ");
switch (data[1] & NG_SIXLOWPAN_IPHC2_DAM) {
switch (data[1] & SIXLOWPAN_IPHC2_DAM) {
case 0x00:
puts("128 bits inline");
break;
@ -237,8 +237,8 @@ void ng_sixlowpan_print(uint8_t *data, size_t size)
}
}
if (data[1] & NG_SIXLOWPAN_IPHC2_CID_EXT) {
offset += NG_SIXLOWPAN_IPHC_CID_EXT_LEN;
if (data[1] & SIXLOWPAN_IPHC2_CID_EXT) {
offset += SIXLOWPAN_IPHC_CID_EXT_LEN;
printf("SCI: 0x%" PRIx8 "; DCI: 0x%" PRIx8 "\n",
data[2] >> 4, data[2] & 0xf);
}
Loading…
Cancel
Save