Skip to content
Snippets Groups Projects
Commit 9a989264 authored by Martine Lenders's avatar Martine Lenders
Browse files

ng_sixlowpan: initial import of IP header compression

parent 5b5ff583
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,11 @@ ifneq (,$(filter ng_sixlowpan_frag,$(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_ipv6
USEMODULE += ng_sixlowpan_netif
......
......@@ -116,6 +116,9 @@ endif
ifneq (,$(filter ng_sixlowpan_frag,$(USEMODULE)))
DIRS += net/network_layer/ng_sixlowpan/frag
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
......
......@@ -25,6 +25,7 @@
#include "kernel_types.h"
#include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/iphc.h"
#ifdef __cplusplus
extern "C" {
......
/*
* 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_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 <mlenders@inf.fu-berlin.de>
*/
#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)
/**
* @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.
*
* @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_ */
/** @} */
......@@ -20,6 +20,8 @@
#ifndef NG_SIXLOWPAN_NETIF_H_
#define NG_SIXLOWPAN_NETIF_H_
#include <stdbool.h>
#include "kernel_types.h"
#ifdef __cplusplus
......@@ -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;
/**
......
MODULE = ng_sixlowpan_iphc
include $(RIOTBASE)/Makefile.base
This diff is collapsed.
......@@ -49,6 +49,9 @@ void ng_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size)
free_entry->pid = pid;
free_entry->max_frag_size = max_frag_size;
#ifdef MODULE_NG_SIXLOWPAN_IPHC
free_entry->iphc_enabled = true;
#endif
return;
}
......
......@@ -19,6 +19,7 @@
#include "net/ng_sixlowpan.h"
#include "net/ng_sixlowpan/frag.h"
#include "net/ng_sixlowpan/iphc.h"
#include "net/ng_sixlowpan/netif.h"
#define ENABLE_DEBUG (0)
......@@ -101,6 +102,18 @@ void _receive(ng_pktsnip_t *pkt)
return;
}
#ifdef MODULE_NG_SIXLOWPAN_IPHC
if (ng_sixlowpan_iphc_is(payload->data)) {
if (!ng_sixlowpan_iphc_decode(pkt)) {
DEBUG("6lo: error on IPHC decoding\n");
ng_pktbuf_release(pkt);
return;
}
LL_SEARCH_SCALAR(pkt, payload, type, NG_NETTYPE_IPV6);
}
#endif
payload->type = NG_NETTYPE_IPV6;
entry = ng_netreg_lookup(NG_NETTYPE_IPV6, NG_NETREG_DEMUX_CTX_ALL);
......@@ -151,6 +164,8 @@ void _send(ng_pktsnip_t *pkt)
* length is the length of the IPv6 datagram + 6LoWPAN dispatches,
* while the datagram size is the size of only the IPv6 datagram */
payload_len = ng_pkt_len(ipv6);
/* cppcheck: datagram_size will be read by ng_sixlowpan_frag implementation */
/* cppcheck-suppress unreadVariable */
datagram_size = (uint16_t)payload_len;
/* use sixlowpan packet snip as temporary one */
......@@ -163,23 +178,6 @@ void _send(ng_pktsnip_t *pkt)
}
pkt = sixlowpan;
DEBUG("6lo: Send uncompressed\n");
sixlowpan = ng_pktbuf_add(NULL, NULL, sizeof(uint8_t), NG_NETTYPE_SIXLOWPAN);
if (sixlowpan == NULL) {
DEBUG("6lo: no space left in packet buffer\n");
ng_pktbuf_release(pkt);
return;
}
sixlowpan->next = ipv6;
pkt->next = sixlowpan;
disp = sixlowpan->data;
disp[0] = NG_SIXLOWPAN_UNCOMPRESSED;
payload_len++;
iface = ng_sixlowpan_netif_get(hdr->if_pid);
if (iface == NULL) {
......@@ -192,11 +190,56 @@ void _send(ng_pktsnip_t *pkt)
}
ng_sixlowpan_netif_add(hdr->if_pid, max_frag_size);
iface = ng_sixlowpan_netif_get(hdr->if_pid);
}
else {
max_frag_size = iface->max_frag_size;
}
#ifdef MODULE_NG_SIXLOWPAN_IPHC
if (iface->iphc_enabled) {
if (!ng_sixlowpan_iphc_encode(pkt)) {
DEBUG("6lo: error on IPHC encoding\n");
ng_pktbuf_release(pkt);
return;
}
}
else {
DEBUG("6lo: Send uncompressed\n");
sixlowpan = ng_pktbuf_add(NULL, NULL, sizeof(uint8_t),
NG_NETTYPE_SIXLOWPAN);
if (sixlowpan == NULL) {
DEBUG("6lo: no space left in packet buffer\n");
ng_pktbuf_release(pkt);
return;
}
sixlowpan->next = ipv6;
pkt->next = sixlowpan;
disp = sixlowpan->data;
disp[0] = NG_SIXLOWPAN_UNCOMPRESSED;
payload_len++;
}
#else
DEBUG("6lo: Send uncompressed\n");
sixlowpan = ng_pktbuf_add(NULL, NULL, sizeof(uint8_t), NG_NETTYPE_SIXLOWPAN);
if (sixlowpan == NULL) {
DEBUG("6lo: no space left in packet buffer\n");
ng_pktbuf_release(pkt);
return;
}
sixlowpan->next = ipv6;
pkt->next = sixlowpan;
disp = sixlowpan->data;
disp[0] = NG_SIXLOWPAN_UNCOMPRESSED;
payload_len++;
#endif
DEBUG("6lo: max_frag_size = %" PRIu16 " for interface %"
PRIkernel_pid "\n", max_frag_size, hdr->if_pid);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment