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

sixlowpan: move non-GNRC stuff to its own module

This commit is contained in:
Martine Lenders 2015-08-17 15:06:44 +02:00 committed by Martine Lenders
parent 87c222d2fa
commit 93031c9b60
13 changed files with 356 additions and 286 deletions

View File

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

View File

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

View File

@ -26,6 +26,7 @@
#include "net/ng_sixlowpan/frag.h" #include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/iphc.h" #include "net/ng_sixlowpan/iphc.h"
#include "net/sixlowpan.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -52,24 +53,6 @@ extern "C" {
#define NG_SIXLOWPAN_MSG_QUEUE_SIZE (8U) #define NG_SIXLOWPAN_MSG_QUEUE_SIZE (8U)
#endif #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. * @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); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -29,77 +29,12 @@
#include "byteorder.h" #include "byteorder.h"
#include "kernel_types.h" #include "kernel_types.h"
#include "net/ng_pkt.h" #include "net/ng_pkt.h"
#include "net/sixlowpan.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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. * @brief Sends a packet fragmented.
* *

View File

@ -23,124 +23,12 @@
#include <stdbool.h> #include <stdbool.h>
#include "net/ng_pkt.h" #include "net/ng_pkt.h"
#include "net/sixlowpan.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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. * @brief Decompresses a received 6LoWPAN IPHC frame.
* *

259
sys/include/net/sixlowpan.h Normal file
View File

@ -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_ */
/** @} */

View File

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

View File

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

View File

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

View File

@ -19,6 +19,7 @@
#include "net/ipv6/hdr.h" #include "net/ipv6/hdr.h"
#include "net/gnrc.h" #include "net/gnrc.h"
#include "net/ng_sixlowpan/ctx.h" #include "net/ng_sixlowpan/ctx.h"
#include "net/sixlowpan.h"
#include "utlist.h" #include "utlist.h"
#include "net/ng_sixlowpan/iphc.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; ng_netif_hdr_t *netif_hdr = pkt->next->data;
ipv6_hdr_t *ipv6_hdr; ipv6_hdr_t *ipv6_hdr;
uint8_t *iphc_hdr = pkt->data; 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; ng_sixlowpan_ctx_t *ctx = NULL;
assert(ipv6 != 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; ipv6_hdr = ipv6->data;
iphc_hdr += offset; iphc_hdr += offset;
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) { if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_CID_EXT) {
payload_offset++; payload_offset++;
} }
ipv6_hdr_set_version(ipv6_hdr); 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: case IPHC_TF_ECN_DSCP_FL:
ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]); ipv6_hdr_set_tc(ipv6_hdr, iphc_hdr[payload_offset++]);
ipv6_hdr->v_tc_fl.u8[1] |= iphc_hdr[payload_offset++] & 0x0f; 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; 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++]; 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: case IPHC_HL_INLINE:
ipv6_hdr->hl = iphc_hdr[payload_offset++]; ipv6_hdr->hl = iphc_hdr[payload_offset++];
break; break;
@ -158,14 +159,14 @@ size_t ng_sixlowpan_iphc_decode(ng_pktsnip_t *ipv6, ng_pktsnip_t *pkt, size_t of
break; break;
} }
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAC) { if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_SAC) {
uint8_t sci = 0; 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; 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); ctx = ng_sixlowpan_ctx_lookup_id(sci);
if (ctx == NULL) { 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 */ /* should be asserted by line 168 anyway */
assert(ctx != NULL); 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; break;
} }
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAC) { if (iphc_hdr[IPHC2_IDX] & SIXLOWPAN_IPHC2_DAC) {
uint8_t dci = 0; 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; 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); ctx = ng_sixlowpan_ctx_lookup_id(dci);
if (ctx == NULL) { 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 | switch (iphc_hdr[IPHC2_IDX] & (SIXLOWPAN_IPHC2_M | SIXLOWPAN_IPHC2_DAC |
NG_SIXLOWPAN_IPHC2_DAM)) { SIXLOWPAN_IPHC2_DAM)) {
case IPHC_M_DAC_DAM_U_FULL: case IPHC_M_DAC_DAM_U_FULL:
case IPHC_M_DAC_DAM_M_FULL: case IPHC_M_DAC_DAM_M_FULL:
memcpy(&(ipv6_hdr->dst.u8), iphc_hdr + payload_offset, 16); 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; ng_netif_hdr_t *netif_hdr = pkt->data;
ipv6_hdr_t *ipv6_hdr = pkt->next->data; ipv6_hdr_t *ipv6_hdr = pkt->next->data;
uint8_t *iphc_hdr; 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; bool addr_comp = false;
ng_sixlowpan_ctx_t *src_ctx = NULL, *dst_ctx = NULL; ng_sixlowpan_ctx_t *src_ctx = NULL, *dst_ctx = NULL;
ng_pktsnip_t *dispatch = ng_pktbuf_add(NULL, NULL, pkt->next->size, 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; iphc_hdr = dispatch->data;
/* set initial dispatch value*/ /* set initial dispatch value*/
iphc_hdr[IPHC1_IDX] = NG_SIXLOWPAN_IPHC1_DISP; iphc_hdr[IPHC1_IDX] = SIXLOWPAN_IPHC1_DISP;
iphc_hdr[IPHC2_IDX] = 0; iphc_hdr[IPHC2_IDX] = 0;
/* check for available contexts */ /* 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_CID_MASK) != 0) &&
(dst_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_COMP))) { (dst_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_COMP))) {
/* add context identifier extension */ /* 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; iphc_hdr[CID_EXT_IDX] = 0;
/* move position to behind CID extension */ /* 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 */ /* compress flow label and traffic class */
@ -487,7 +488,7 @@ bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
else { else {
if ((src_ctx != NULL) && (src_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_COMP)) { if ((src_ctx != NULL) && (src_ctx->flags_id & NG_SIXLOWPAN_CTX_FLAGS_COMP)) {
/* stateful source address compression */ /* 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)) { 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); 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 */ /* M: Multicast compression */
if (ipv6_addr_is_multicast(&(ipv6_hdr->dst))) { 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 multicast address is of format ffXX::XXXX:XXXX:XXXX */
if ((ipv6_hdr->dst.u16[1].u16 == 0) && 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 /* Unicast prefix based IPv6 multicast address
* (https://tools.ietf.org/html/rfc3306) with given context * (https://tools.ietf.org/html/rfc3306) with given context
* for unicast prefix -> context based compression */ * 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[1];
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[2]; iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[2];
memcpy(iphc_hdr + inline_pos, ipv6_hdr->dst.u16 + 6, 4); memcpy(iphc_hdr + inline_pos, ipv6_hdr->dst.u16 + 6, 4);

View File

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

View File

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

View File

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