Skip to content

Commit

Permalink
ng_sixlowpan: initial import of IP header compression
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Apr 21, 2015
1 parent f96fdab commit dd3e461
Show file tree
Hide file tree
Showing 8 changed files with 934 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ ifneq (,$(filter sixlowpan,$(USEMODULE)))
USEMODULE += vtimer
endif

ifneq (,$(filter ng_sixlowpan_iphc,$(USEMODULE)))
USEMODULE += ng_sixlowpan
USEMODULE += ng_sixlowpan_ctx
endif

ifneq (,$(filter ng_sixlowpan,$(USEMODULE)))
USEMODULE += ng_sixlowpan_netif
USEMODULE += ng_netbase
Expand Down
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ endif
ifneq (,$(filter ng_sixlowpan_ctx,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/ctx
endif
ifneq (,$(filter ng_sixlowpan_iphc,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/iphc
endif
ifneq (,$(filter ng_sixlowpan_netif,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/netif
endif
Expand Down
2 changes: 2 additions & 0 deletions sys/include/net/ng_sixlowpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "kernel_types.h"

#include "net/ng_sixlowpan/iphc.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
163 changes: 163 additions & 0 deletions sys/include/net/ng_sixlowpan/iphc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright (C) 2015 Martine Lenders <[email protected]>
*
* 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_ng_sixlowpan_iphc IPv6 header compression (IPHC)
* @ingroup net_ng_sixlowpan
* @brief IPv6 header compression for 6LoWPAN.
* @{
*
* @file
* @brief 6LoWPAN IPHC definitions
*
* @author Martine Lenders <[email protected]>
*/
#ifndef NG_SIXLOWPAN_IPHC_H_
#define NG_SIXLOWPAN_IPHC_H_

#include <stdbool.h>

#include "net/ng_pkt.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)

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.
*
* @param[in,out] pkt A received 6LoWPAN IPHC frame. Will be translated
* into an IPv6 packet.
*
* @return true, on success
* @return false, on error.
*/
bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt);

/**
* @brief Compresses a 6LoWPAN for IPHC.
*
* @param[in,out] pkt A 6LoWPAN frame with an uncompressed IPv6 header to
* send. Will be translated to an 6LoWPAN IPHC frame.
*
* @return true, on success
* @return false, on error.
*/
bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt);

#ifdef __cplusplus
}
#endif

#endif /* NG_SIXLOWPAN_IPHC_H_ */
/** @} */
5 changes: 5 additions & 0 deletions sys/include/net/ng_sixlowpan/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef NG_SIXLOWPAN_NETIF_H_
#define NG_SIXLOWPAN_NETIF_H_

#include <stdbool.h>

#include "kernel_types.h"

#ifdef __cplusplus
Expand All @@ -32,6 +34,9 @@ extern "C" {
typedef struct {
kernel_pid_t pid; /**< PID of the interface */
uint16_t max_frag_size; /**< Maximum fragment size for this interface */
#ifdef MODULE_NG_SIXLOWPAN_IPHC
bool iphc_enabled; /**< enable or disable IPHC */
#endif
} ng_sixlowpan_netif_t;

/**
Expand Down
3 changes: 3 additions & 0 deletions sys/net/network_layer/ng_sixlowpan/iphc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = ng_sixlowpan_iphc

include $(RIOTBASE)/Makefile.base
Loading

0 comments on commit dd3e461

Please sign in to comment.