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

304 lines
8.4 KiB
C
Raw Normal View History

2013-11-28 13:25:33 +01:00
/*
2013-08-05 16:10:54 +02:00
* Copyright (C) 2013 INRIA.
*
2013-11-22 20:47:05 +01:00
* This file is subject to the terms and conditions of the GNU Lesser General
2013-08-05 16:10:54 +02:00
* Public License. See the file LICENSE in the top level directory for more
* details.
2013-11-28 13:25:33 +01:00
*/
/**
* @ingroup net_sixlowpan
2013-08-05 16:10:54 +02:00
* @{
2013-11-28 13:25:33 +01:00
*
* @file sixlowpan/lowpan.h
* @brief 6LoWPAN LoWPAN layer header
*
* @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de>
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Oliver Gesch <oliver.gesch@googlemail.com>
2013-08-05 16:10:54 +02:00
*/
#ifndef SIXLOWPAN_LOWPAN_H
#define SIXLOWPAN_LOWPAN_H
2013-08-09 03:13:37 +02:00
#include <stdint.h>
#include "transceiver.h"
2014-02-13 15:54:42 +01:00
#include "net_help.h"
#include "net_if.h"
2013-08-09 03:13:37 +02:00
#include "sixlowpan/types.h"
/**
* @brief 6LoWPAN dispatch value for uncompressed IPv6 packets.
* @see <a href="http://tools.ietf.org/html/rfc4944#section-5.1">
* RFC 4944, section 5.1
* </a>
*/
#define SIXLOWPAN_IPV6_DISPATCH (0x41)
/**
* @brief 6LoWPAN dispatch value for IPv6 header compression (part of
* first byte of LOWPAN_IPHC).
* @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.1">
* RFC 4944, section 3.1.1
* </a>
*/
#define SIXLOWPAN_IPHC1_DISPATCH (0x60)
/**
* @brief Flag for 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_FL_C (0x10)
/**
* @brief Flag for Traffic Class 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_TC_C (0x08)
/**
* @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 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 (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)
/**
* 6LoWPAN dispatch value for fragmentation header (first fragment)
* @see <a href="http://tools.ietf.org/html/rfc4944#section-5.1">
* RFC 4944, section 5.1
* </a>
*/
#define SIXLOWPAN_FRAG1_DISPATCH (0xc0)
/**
* 6LoWPAN dispatch value for fragmentation header (subsequent fragment)
* @see <a href="http://tools.ietf.org/html/rfc4944#section-5.1">
* RFC 4944, section 5.1
* </a>
*/
#define SIXLOWPAN_FRAGN_DISPATCH (0xe0)
/**
* 6LoWPAN fragmentation header length (first fragment)
*/
#define SIXLOWPAN_FRAG1_HDR_LEN (4)
/**
* 6LoWPAN fragmentation header length (subsequent fragment)
*/
#define SIXLOWPAN_FRAGN_HDR_LEN (5)
/**
* @brief message type for notification
*
* @see sixlowpan_lowpan_register()
*/
#define LOWPAN_FRAME_RECEIVED (UPPER_LAYER_1)
2013-08-09 03:13:37 +02:00
/**
* @brief Data type to configure 6LoWPAN IPv6 header compression.
*/
typedef enum __attribute__((packed)) {
2013-08-09 03:13:37 +02:00
LOWPAN_IPHC_DISABLE = 0, ///< header compression disabled
LOWPAN_IPHC_ENABLE = 1 ///< header compression enabled
} sixlowpan_lowpan_iphc_status_t;
2013-08-09 03:13:37 +02:00
/**
* @brief Data type to represent an 6LoWPAN frame as byte stream.
*/
typedef struct __attribute__((packed)) {
uint8_t length; ///< length of the byte stream.
uint8_t *data; ///< the byte stream representing the 6LoWPAN frame.
} sixlowpan_lowpan_frame_t;
/**
2014-02-13 15:54:42 +01:00
* @brief Initializes all addresses on an interface needed for 6LoWPAN.
2013-08-09 03:13:37 +02:00
*
2014-02-13 15:54:42 +01:00
* @param[in] if_id The interface to use with 6LoWPAN.
*
* @return 1 on success, 0 on failure.
2013-08-09 03:13:37 +02:00
*/
2014-02-13 15:54:42 +01:00
int sixlowpan_lowpan_init_interface(int if_id);
/**
* @brief Checks if an EUI-64 was set from a short address. If so
* it returns this address, else 0
*
* @param[in] iid An EUI-64.
*
* @return The short address on success, 0 on failure.
*/
static inline uint16_t sixlowpan_lowpan_eui64_to_short_addr(const net_if_eui64_t *iid)
{
if (iid->uint32[0] == HTONL(0x000000ff) &&
iid->uint16[2] == HTONS(0xfe00)) {
return NTOHS(iid->uint16[3]);
}
return 0;
}
2013-08-09 03:13:37 +02:00
/**
2014-02-13 15:54:42 +01:00
* @brief Initializes all addresses and prefixes on an interface needed
* for 6LoWPAN. Calling this function together with
* sixlowpan_lowpan_init_interface() is not necessary.
2013-08-09 03:13:37 +02:00
*
2014-02-13 15:54:42 +01:00
* @param[in] if_id The interface to use with 6LoWPAN.
2013-08-09 03:13:37 +02:00
* @param[in] prefix the address prefix to advertise.
2014-02-13 15:54:42 +01:00
*
* @return 1 on success, 0 on failure.
2013-08-09 03:13:37 +02:00
*/
2014-02-13 15:54:42 +01:00
int sixlowpan_lowpan_init_adhoc_interface(int if_id,
const ipv6_addr_t *prefix);
2013-08-09 03:13:37 +02:00
2013-08-12 11:08:19 +02:00
/**
* @brief Initializes a 6LoWPAN border router with an address
*
* @note Currently only working with addresses generated from
* IEEE 802.15.4 16-bit short addresses.
*
2014-02-13 15:54:42 +01:00
* @param[in] if_id The interface to use with 6LoWPAN.
2013-08-12 11:08:19 +02:00
*
2014-02-13 15:54:42 +01:00
* @return 1 on success, 0 on failure.
2013-08-12 11:08:19 +02:00
*/
2014-02-13 15:54:42 +01:00
int sixlowpan_lowpan_border_init(int if_id);
2013-08-12 11:08:19 +02:00
2013-08-09 03:13:37 +02:00
/**
2014-02-13 15:54:42 +01:00
* @brief Send data via 6LoWPAN to destination node or next hop dest.
2013-08-09 03:13:37 +02:00
*
2014-02-13 15:54:42 +01:00
* @param[in] if_id The interface to send the data over.
* @param[in] dest Hardware address of the next hop or destination node.
* @param[in] dest_len Length of the destination address in byte.
2013-08-13 06:41:05 +02:00
* @param[in] data Data to send to destination node (may be
2013-08-09 03:13:37 +02:00
* manipulated).
* @param[in] data_len Length of data.
2014-02-13 15:54:42 +01:00
*
* @return length of transmitted data on success, -1 on failure.
2013-08-09 03:13:37 +02:00
*/
2014-02-13 15:54:42 +01:00
int sixlowpan_lowpan_sendto(int if_id, const void *dest, int dest_len,
uint8_t *data, uint16_t data_len);
2013-08-09 03:13:37 +02:00
/**
* @brief Set header compression status for 6LoWPAN.
*
* @param[in] status Header compression status to set to.
*/
void sixlowpan_lowpan_set_iphc_status(
sixlowpan_lowpan_iphc_status_t status);
2013-08-13 06:41:05 +02:00
/**
* @brief Initialize 6LoWPAN neighbor discovery (i.e. send
* router advertisement with Source Link-Layer Address Option)
*
* @see <a href="http://tools.ietf.org/html/rfc4861">
* RFC 4861
* </a>, <a href="http://tools.ietf.org/html/rfc6775">
* RFC 6775
* </a>
*
*/
void sixlowpan_lowpan_bootstrapping(void);
2013-08-09 03:13:37 +02:00
/**
* @brief Registers a thread to read received 6LoWPAN frames. The
* 6LoWPAN frames are delivered as sixlowpan_lowpan_frame_t
* structs.
*
* @param[in] pid The PID of the receiver thread.
*
* @return 1 on success, ENOMEM if maximum number of registrable
* threads is exceeded.
*/
uint8_t sixlowpan_lowpan_register(int pid);
#if ENABLE_DEBUG
/**
* @brief Print current buffer of assembled (i. e. not fragmented)
* 6LoWPAN packages.
*/
void sixlowpan_lowpan_print_fifo_buffers(void);
/**
* @brief Print current buffer for 6LoWPAN fragmentation reassembly.
*/
void sixlowpan_lowpan_print_reassembly_buffers(void);
#endif
2014-02-13 15:54:42 +01:00
/**
* @brief Initializes 6LoWPAN module.
*
* @return 1 on success, 0 on failure.
*/
int sixlowpan_lowpan_init(void);
2013-11-28 13:25:33 +01:00
/** @} */
2013-08-05 16:10:54 +02:00
#endif /* SIXLOWPAN_LOWPAN_H */