Contiki-NG

Data Structures

struct  sicslowpan_addr_context
 The header for fragments. More...
 
struct  sicslowpan_nh_compressor
 The structure of a next header compressor. More...
 

Macros

#define LOG_MODULE   "6LoWPAN"
 FOR RFC 6282 COMPLIANCE TODO: -Add compression options to UDP, currently only supports both ports compressed or both ports elided. More...
 

Functions

static void add_paging_dispatch (uint8_t page)
 Adds Paging dispatch byte.
 
static void add_6lorh_hdr (void)
 Adds 6lorh headers before IPHC.
 
static void digest_paging_dispatch (void)
 Digest 6lorh headers before IPHC.
 
static void digest_6lorh_hdr (void)
 Digest 6lorh headers before IPHC.
 

General variables

static uint8_t * packetbuf_ptr
 A pointer to the packetbuf buffer. More...
 
static uint8_t packetbuf_hdr_len
 packetbuf_hdr_len is the total length of (the processed) 6lowpan headers (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed fields).
 
static int packetbuf_payload_len
 The length of the payload in the Packetbuf buffer. More...
 
static uint8_t uncomp_hdr_len
 uncomp_hdr_len is the length of the headers before compression (if HC2 is used this includes the UDP header in addition to the IP header).
 
static int mac_max_payload
 mac_max_payload is the maimum payload space on the MAC frame.
 
static uint8_t curr_page
 The current page (RFC 4944)
 
static int last_tx_status
 the result of the last transmitted fragment
 

variables specific to RFC 6282

static struct sicslowpan_addr_contextcontext
 Addresses contexts for IPHC. More...
 
static uint8_t * iphc_ptr
 pointer to the byte where to write next inline field.
 
const uint8_t unc_llconf [] = {0x0f,0x28,0x22,0x20}
 
const uint8_t unc_ctxconf [] = {0x00,0x88,0x82,0x80}
 
const uint8_t unc_mxconf [] = {0x0f, 0x25, 0x23, 0x21}
 
const uint8_t llprefix [] = {0xfe, 0x80}
 
static const uint8_t ttl_values [] = {0, 1, 64, 255}
 

IPHC related functions


static struct sicslowpan_addr_contextaddr_context_lookup_by_prefix (uip_ipaddr_t *ipaddr)
 find the context corresponding to prefix ipaddr
 
static struct sicslowpan_addr_contextaddr_context_lookup_by_number (uint8_t number)
 find the context with the given number
 
static uint8_t compress_addr_64 (uint8_t bitpos, uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr)
 
static void uncompress_addr (uip_ipaddr_t *ipaddr, uint8_t const prefix[], uint8_t pref_post_count, uip_lladdr_t *lladdr)
 
static int compress_hdr_iphc (void)
 Compress IP/UDP header. More...
 
static bool uncompress_hdr_iphc (uint8_t *buf, uint16_t buf_size, uint16_t ip_len)
 Uncompress IPHC (i.e., IPHC and LOWPAN_UDP) headers and put them in sicslowpan_buf. More...
 

IPv6 dispatch "compression" function


static void compress_hdr_ipv6 (void)
 

Input/output functions common to all compression schemes


static void packet_sent (void *ptr, int status, int transmissions)
 Callback function for the MAC packet sent callback.
 
static void send_packet (void)
 This function is called by the 6lowpan code to send out a packet.
 
static uint8_t output (const linkaddr_t *localdest)
 Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan. More...
 
static void input (void)
 Process a received 6lowpan packet. More...
 

Pointers in the packetbuf buffer

#define PACKETBUF_FRAG_PTR   (packetbuf_ptr)
 
#define PACKETBUF_FRAG_DISPATCH_SIZE   0 /* 16 bit */
 
#define PACKETBUF_FRAG_TAG   2 /* 16 bit */
 
#define PACKETBUF_FRAG_OFFSET   4 /* 8 bit */
 
#define PACKETBUF_IPHC_BUF   ((uint8_t *)(packetbuf_ptr + packetbuf_hdr_len))
 
#define PACKETBUF_PAYLOAD_END   ((uint8_t *)(packetbuf_ptr + mac_max_payload))
 
#define PACKETBUF_6LO_PTR   (packetbuf_ptr + packetbuf_hdr_len)
 
#define PACKETBUF_6LO_DISPATCH   0 /* 8 bit */
 
#define PACKETBUF_6LO_ENCODING   1 /* 8 bit */
 
#define PACKETBUF_6LO_TTL   2 /* 8 bit */
 
#define PACKETBUF_6LO_HC_UDP_PTR   (packetbuf_ptr + packetbuf_hdr_len)
 
#define PACKETBUF_6LO_HC_UDP_DISPATCH   0 /* 8 bit */
 
#define PACKETBUF_6LO_HC_UDP_HC1_ENCODING   1 /* 8 bit */
 
#define PACKETBUF_6LO_HC_UDP_UDP_ENCODING   2 /* 8 bit */
 
#define PACKETBUF_6LO_HC_UDP_TTL   3 /* 8 bit */
 
#define PACKETBUF_6LO_HC_UDP_PORTS   4 /* 8 bit */
 
#define PACKETBUF_6LO_HC_UDP_CHKSUM   5 /* 16 bit */
 

Pointers in the sicslowpan and uip buffer

#define SICSLOWPAN_IP_BUF(buf)   ((struct uip_ip_hdr *)buf)
 
#define SICSLOWPAN_UDP_BUF(buf)   ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN])
 
#define SICSLOWPAN_IPPAYLOAD_BUF(buf)   (&buf[UIP_IPH_LEN])
 
#define UIP_IPPAYLOAD_BUF_POS(pos)   (&uip_buf[UIP_IPH_LEN + (pos)])
 
#define UIP_UDP_BUF_POS(pos)   ((struct uip_udp_hdr *)UIP_IPPAYLOAD_BUF_POS(pos))
 
#define UIP_EXT_HDR_LEN   2
 

General sicslowpan defines

#define SICSLOWPAN_UDP_4_BIT_PORT_MIN   0xF0B0
 
#define SICSLOWPAN_UDP_4_BIT_PORT_MAX   0xF0BF /* F0B0 + 15 */
 
#define SICSLOWPAN_UDP_8_BIT_PORT_MIN   0xF000
 
#define SICSLOWPAN_UDP_8_BIT_PORT_MAX   0xF0FF /* F000 + 255 */
 

6lowpan compressions

Note
These are assumed to be in order - so that no compression is 0, then more and more compressed version follow. E.g. they can be used for comparing: if x > COMPRESSION_IPV6 ...
#define SICSLOWPAN_COMPRESSION_IPV6   0 /* No compression */
 
#define SICSLOWPAN_COMPRESSION_IPHC   1 /* RFC 6282 */
 
#define SICSLOWPAN_COMPRESSION_6LORH
 

6lowpan dispatches

#define SICSLOWPAN_DISPATCH_IPV6   0x41 /* 01000001 = 65 */
 
#define SICSLOWPAN_DISPATCH_HC1   0x42 /* 01000010 = 66 */
 
#define SICSLOWPAN_DISPATCH_IPHC   0x60 /* 011xxxxx = ... */
 
#define SICSLOWPAN_DISPATCH_IPHC_MASK   0xe0
 
#define SICSLOWPAN_DISPATCH_FRAG1   0xc0 /* 11000xxx */
 
#define SICSLOWPAN_DISPATCH_FRAGN   0xe0 /* 11100xxx */
 
#define SICSLOWPAN_DISPATCH_FRAG_MASK   0xf8
 
#define SICSLOWPAN_DISPATCH_PAGING   0xf0 /* 1111xxxx */
 
#define SICSLOWPAN_DISPATCH_PAGING_MASK   0xf0
 

HC1 encoding

#define SICSLOWPAN_HC1_NH_UDP   0x02
 
#define SICSLOWPAN_HC1_NH_TCP   0x06
 
#define SICSLOWPAN_HC1_NH_ICMP6   0x04
 

HC_UDP encoding (works together with HC1)

#define SICSLOWPAN_HC_UDP_ALL_C   0xE0
 

IPHC encoding

#define SICSLOWPAN_IPHC_FL_C   0x10
 
#define SICSLOWPAN_IPHC_TC_C   0x08
 
#define SICSLOWPAN_IPHC_NH_C   0x04
 
#define SICSLOWPAN_IPHC_TTL_1   0x01
 
#define SICSLOWPAN_IPHC_TTL_64   0x02
 
#define SICSLOWPAN_IPHC_TTL_255   0x03
 
#define SICSLOWPAN_IPHC_TTL_I   0x00
 
#define SICSLOWPAN_IPHC_CID   0x80
 
#define SICSLOWPAN_IPHC_SAC   0x40
 
#define SICSLOWPAN_IPHC_SAM_00   0x00
 
#define SICSLOWPAN_IPHC_SAM_01   0x10
 
#define SICSLOWPAN_IPHC_SAM_10   0x20
 
#define SICSLOWPAN_IPHC_SAM_11   0x30
 
#define SICSLOWPAN_IPHC_SAM_BIT   4
 
#define SICSLOWPAN_IPHC_M   0x08
 
#define SICSLOWPAN_IPHC_DAC   0x04
 
#define SICSLOWPAN_IPHC_DAM_00   0x00
 
#define SICSLOWPAN_IPHC_DAM_01   0x01
 
#define SICSLOWPAN_IPHC_DAM_10   0x02
 
#define SICSLOWPAN_IPHC_DAM_11   0x03
 
#define SICSLOWPAN_IPHC_DAM_BIT   0
 
#define SICSLOWPAN_IPHC_ADDR_CONTEXT_LL   0
 
#define SICSLOWPAN_IPHC_MCAST_RANGE   0xA0
 

LOWPAN_UDP encoding (works together with IPHC)

#define SICSLOWPAN_NHC_UDP_MASK   0xF8
 
#define SICSLOWPAN_NHC_UDP_ID   0xF0
 
#define SICSLOWPAN_NHC_UDP_CHECKSUMC   0x04
 
#define SICSLOWPAN_NHC_UDP_CHECKSUMI   0x00
 
#define SICSLOWPAN_NHC_UDP_CS_P_00   0xF0 /* all inline */
 
#define SICSLOWPAN_NHC_UDP_CS_P_01   0xF1 /* source 16bit inline, dest = 0xF0 + 8 bit inline */
 
#define SICSLOWPAN_NHC_UDP_CS_P_10   0xF2 /* source = 0xF0 + 8bit inline, dest = 16 bit inline */
 
#define SICSLOWPAN_NHC_UDP_CS_P_11   0xF3 /* source & dest = 0xF0B + 4bit inline */
 

The 6lowpan "headers" length

#define SICSLOWPAN_IPV6_HDR_LEN   1 /*one byte*/
 
#define SICSLOWPAN_HC1_HDR_LEN   3
 
#define SICSLOWPAN_HC1_HC_UDP_HDR_LEN   7
 
#define SICSLOWPAN_FRAG1_HDR_LEN   4
 
#define SICSLOWPAN_FRAGN_HDR_LEN   5
 

Address compressibility test functions

#define sicslowpan_is_iid_16_bit_compressable(a)
 check whether we can compress the IID in address 'a' to 16 bits. More...
 
#define sicslowpan_is_mcast_addr_decompressable(a)
 check whether the 9-bit group-id of the compressed multicast address is known. More...
 
#define sicslowpan_is_mcast_addr_compressable(a)
 check whether the 112-bit group-id of the multicast address is mappable to a 9-bit group-id It is true if the group is the all nodes or all routers group.
 
#define sicslowpan_is_mcast_addr_compressable48(a)
 
#define sicslowpan_is_mcast_addr_compressable32(a)
 
#define sicslowpan_is_mcast_addr_compressable8(a)
 

Detailed Description

Macro Definition Documentation

◆ LOG_MODULE

#define LOG_MODULE   "6LoWPAN"

FOR RFC 6282 COMPLIANCE TODO: -Add compression options to UDP, currently only supports both ports compressed or both ports elided.

-Verify TC/FL compression works

-Add stateless multicast option

Definition at line 81 of file sicslowpan.c.

◆ sicslowpan_is_iid_16_bit_compressable

#define sicslowpan_is_iid_16_bit_compressable (   a)
Value:
((((a)->u16[4]) == 0) && \
(((a)->u8[10]) == 0)&& \
(((a)->u8[11]) == 0xff)&& \
(((a)->u8[12]) == 0xfe)&& \
(((a)->u8[13]) == 0))

check whether we can compress the IID in address 'a' to 16 bits.

This is used for unicast addresses only, and is true if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX NOTE: we currently assume 64-bits prefixes

Definition at line 251 of file sicslowpan.h.

◆ sicslowpan_is_mcast_addr_decompressable

#define sicslowpan_is_mcast_addr_decompressable (   a)
Value:
(((*a & 0x01) == 0) && \
((*(a + 1) == 0x01) || (*(a + 1) == 0x02)))

check whether the 9-bit group-id of the compressed multicast address is known.

It is true if the 9-bit group is the all nodes or all routers group.

Parameters
ais typed uint8_t *

Definition at line 265 of file sicslowpan.h.

Function Documentation

◆ compress_hdr_iphc()

static int compress_hdr_iphc ( void  )
static

Compress IP/UDP header.

This function is called by the 6lowpan code to create a compressed 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the uip_buf buffer.

IPHC (RFC 6282)
http://tools.ietf.org/html/

Note
We do not support ISA100_UDP header compression

For LOWPAN_UDP compression, we either compress both ports or none. General format with LOWPAN_UDP compression is

*                      1                   2                   3
*  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |0|1|1|TF |N|HLI|C|S|SAM|M|D|DAM| SCI   | DCI   | comp. IPv6 hdr|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | compressed IPv6 fields .....                                  |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | LOWPAN_UDP    | non compressed UDP fields ...                 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | L4 data ...                                                   |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* 
Note
The context number 00 is reserved for the link local prefix. For unicast addresses, if we cannot compress the prefix, we neither compress the IID.
Returns
1 if success, else 0

Definition at line 683 of file sicslowpan.c.

◆ input()

static void input ( void  )
static

Process a received 6lowpan packet.

The 6lowpan packet is put in packetbuf by the MAC. If its a frag1 or a non-fragmented packet we first uncompress the IP header. The 6lowpan payload and possibly the uncompressed IP header are then copied in siclowpan_buf. If the IP packet is complete it is copied to uip_buf and the IP layer is called.

Note
We do not check for overlapping sicslowpan fragments (it is a SHALL in the RFC 4944 and should never happen)

Definition at line 1833 of file sicslowpan.c.

◆ output()

static uint8_t output ( const linkaddr_t *  localdest)
static

Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.

Parameters
localdestThe MAC address of the destination

The IP packet is initially in uip_buf. Its header is compressed and if necessary it is fragmented. The resulting packet/fragments are put in packetbuf and delivered to the 802.15.4 MAC.

Definition at line 1606 of file sicslowpan.c.

References packetbuf_clear(), packetbuf_dataptr(), packetbuf_hdr_len, packetbuf_ptr, and uncomp_hdr_len.

◆ uncompress_hdr_iphc()

static bool uncompress_hdr_iphc ( uint8_t *  buf,
uint16_t  buf_size,
uint16_t  ip_len 
)
static

Uncompress IPHC (i.e., IPHC and LOWPAN_UDP) headers and put them in sicslowpan_buf.

This function is called by the input function when the dispatch is IPHC. We process the packet in the packetbuf buffer, uncompress the header fields, and copy the result in the sicslowpan buffer. At the end of the decompression, packetbuf_hdr_len and uncompressed_hdr_len are set to the appropriate values

Parameters
bufPointer to the buffer to uncompress the packet into.
buf_sizeThe size of the buffer to uncompress the packet into.
ip_lenEqual to 0 if the packet is not a fragment (IP length is then inferred from the L2 length), non 0 if the packet is a 1st fragment.
Returns
A boolean value indicating whether the uncompression succeeded.

Definition at line 1072 of file sicslowpan.c.

Variable Documentation

◆ context

struct sicslowpan_addr_context* context
static

Addresses contexts for IPHC.

pointer to an address context.

Definition at line 514 of file sicslowpan.c.

◆ packetbuf_payload_len

int packetbuf_payload_len
static

The length of the payload in the Packetbuf buffer.

The payload is what comes after the compressed or uncompressed headers (can be the IP payload if the IP header only is compressed or the UDP payload if the UDP header is also compressed)

Definition at line 174 of file sicslowpan.c.

◆ packetbuf_ptr

uint8_t* packetbuf_ptr
static

A pointer to the packetbuf buffer.

We initialize it to the beginning of the packetbuf buffer, then access different fields by updating the offset packetbuf_hdr_len.

Definition at line 159 of file sicslowpan.c.

Referenced by output().