From 79ff4f1cfcce2b02e2ee26d6561e5df72a72f5b3 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 24 Jun 2013 22:12:04 +0200 Subject: [PATCH] updated sixlowpan configuration and minor coding style --- sys/net/sixlowpan/sixlownd.h | 136 +++++++++--------- sys/net/sixlowpan/sixlowpan.c | 10 -- sys/net/sixlowpan/sixlowpan.h | 255 ++++++++++++++++++---------------- 3 files changed, 202 insertions(+), 199 deletions(-) diff --git a/sys/net/sixlowpan/sixlownd.h b/sys/net/sixlowpan/sixlownd.h index f59517e52c..597ce2a794 100644 --- a/sys/net/sixlowpan/sixlownd.h +++ b/sys/net/sixlowpan/sixlownd.h @@ -26,90 +26,90 @@ #include "sixlowip.h" /* parameter problem [rfc4443] */ -#define PARA_PROB_LEN 8 -#define PARA_PROB_CODE_ERR 0 /* Erroneous header field encountered */ -#define PARA_PROB_NXT_HDR_UNREC 1 /* Unrecognized Next Header type encountered */ -#define PARA_PROB_IPV6_OPT_UNREC 2 /* Unrecognized IPv6 option encountered */ +#define PARA_PROB_LEN (8) +#define PARA_PROB_CODE_ERR (0) /* Erroneous header field encountered */ +#define PARA_PROB_NXT_HDR_UNREC (1) /* Unrecognized Next Header type encountered */ +#define PARA_PROB_IPV6_OPT_UNREC (2) /* Unrecognized IPv6 option encountered */ /* router solicitation */ -#define RTR_SOL_LEN 4 -#define RTR_SOL_INTERVAL 4 -#define RTR_SOL_MAX 3 +#define RTR_SOL_LEN (4) +#define RTR_SOL_INTERVAL (4) +#define RTR_SOL_MAX (3) /* router advertisment */ -#define RTR_ADV_M_FLAG 0 -#define RTR_ADV_O_FLAG 0 -#define RTR_ADV_MAX 3 -#define RTR_ADV_MAX_INTERVAL 600 -#define RTR_ADV_LEN 12 +#define RTR_ADV_M_FLAG (0) +#define RTR_ADV_O_FLAG (0) +#define RTR_ADV_MAX (3) +#define RTR_ADV_MAX_INTERVAL (600) +#define RTR_ADV_LEN (12) /* neighbour solicitation */ -#define NBR_SOL_LEN 20 +#define NBR_SOL_LEN (20) /* neighbour advertisement */ -#define NBR_ADV_LEN 20 -#define NBR_ADV_FLAG_R 0x80 -#define NBR_ADV_FLAG_S 0x40 -#define NBR_ADV_FLAG_O 0x20 +#define NBR_ADV_LEN (20) +#define NBR_ADV_FLAG_R (0x80) +#define NBR_ADV_FLAG_S (0x40) +#define NBR_ADV_FLAG_O (0x20) /* icmp message types rfc4443 */ -#define ICMP_PARA_PROB 4 +#define ICMP_PARA_PROB (4) /* icmp message types rfc4861 4.*/ -#define ICMP_RTR_ADV 134 -#define ICMP_RTR_SOL 133 -#define ICMP_NBR_ADV 136 -#define ICMP_NBR_SOL 135 -#define ICMP_REDIRECT 137 /* will be filtered out by the border router */ +#define ICMP_RTR_ADV (134) +#define ICMP_RTR_SOL (133) +#define ICMP_NBR_ADV (136) +#define ICMP_NBR_SOL (135) +#define ICMP_REDIRECT (137) /* will be filtered out by the border router */ /* stllao option rfc4861 4.6.1 */ -#define OPT_STLLAO_MIN_LEN 8 -#define OPT_STLLAO_MAX_LEN 16 -#define OPT_SLLAO_TYPE 1 -#define OPT_TLLAO_TYPE 2 +#define OPT_STLLAO_MIN_LEN (8) +#define OPT_STLLAO_MAX_LEN (16) +#define OPT_SLLAO_TYPE (1) +#define OPT_TLLAO_TYPE (2) /* prefix info option rfc 4.6.2 */ -#define OPT_PI_LIST_LEN 5 //TODO: initalwert suchen -#define OPT_PI_TYPE 3 -#define OPT_PI_LEN 4 -#define OPT_PI_HDR_LEN 32 -#define OPT_PI_FLAG_A 0x40 -#define OPT_PI_FLAG_L 0x80 -#define OPT_PI_VLIFETIME_INFINITE 0xffffffff +#define OPT_PI_LIST_LEN (5) //TODO: initalwert suchen +#define OPT_PI_TYPE (3) +#define OPT_PI_LEN (4) +#define OPT_PI_HDR_LEN (32) +#define OPT_PI_FLAG_A (0x40) +#define OPT_PI_FLAG_L (0x80) +#define OPT_PI_VLIFETIME_INFINITE (0xffffffff) /* mtu option rfc4861 4.6.4 */ -#define OPT_MTU_TYPE 5 -#define OPT_MTU_LEN 1 -#define OPT_MTU_HDR_LEN 8 +#define OPT_MTU_TYPE (5) +#define OPT_MTU_LEN (1) +#define OPT_MTU_HDR_LEN (8) /* aro - address registration option draft-ietf-6lowpan-nd-14 4.2 */ -#define OPT_ARO_TYPE 31 /* TBD1 */ -#define OPT_ARO_LEN 2 -#define OPT_ARO_HDR_LEN 16 -#define OPT_ARO_LTIME 300 /* geeigneten wert finden */ -#define OPT_ARO_STATE_SUCCESS 0 -#define OPT_ARO_STATE_DUP_ADDR 1 -#define OPT_ARO_STATE_NBR_CACHE_FULL 2 +#define OPT_ARO_TYPE (31) /* TBD1 */ +#define OPT_ARO_LEN (2) +#define OPT_ARO_HDR_LEN (16) +#define OPT_ARO_LTIME (300) /* geeigneten wert finden */ +#define OPT_ARO_STATE_SUCCESS (0) +#define OPT_ARO_STATE_DUP_ADDR (1) +#define OPT_ARO_STATE_NBR_CACHE_FULL (2) /* 6lowpan context option */ -#define OPT_6CO_TYPE 32 -#define OPT_6CO_MIN_LEN 2 -#define OPT_6CO_MAX_LEN 3 -#define OPT_6CO_HDR_LEN 8 -#define OPT_6CO_LTIME 5 /* geeigneten Wert finden */ -#define OPT_6CO_FLAG_C 0x10 -#define OPT_6CO_FLAG_CID 0x0F -#define OPT_6CO_FLAG_C_VALUE_SET 1 -#define OPT_6CO_FLAG_C_VALUE_UNSET 0 +#define OPT_6CO_TYPE (32) +#define OPT_6CO_MIN_LEN (2) +#define OPT_6CO_MAX_LEN (3) +#define OPT_6CO_HDR_LEN (8) +#define OPT_6CO_LTIME (5) /* geeigneten Wert finden */ +#define OPT_6CO_FLAG_C (0x10) +#define OPT_6CO_FLAG_CID (0x0F) +#define OPT_6CO_FLAG_C_VALUE_SET (1) +#define OPT_6CO_FLAG_C_VALUE_UNSET (0) /* authoritative border router option */ -#define OPT_ABRO_TYPE 33 -#define OPT_ABRO_LEN 3 -#define OPT_ABRO_HDR_LEN 24 +#define OPT_ABRO_TYPE (33) +#define OPT_ABRO_LEN (3) +#define OPT_ABRO_HDR_LEN (24) /* authoritive border router cache size */ -#define ABR_CACHE_SIZE 2 +#define ABR_CACHE_SIZE (2) /* neighbor cache size */ -#define NBR_CACHE_SIZE 8 -#define NBR_CACHE_TYPE_GC 1 -#define NBR_CACHE_TYPE_REG 2 -#define NBR_CACHE_TYPE_TEN 3 -#define NBR_CACHE_LTIME_TEN 20 +#define NBR_CACHE_SIZE (8) +#define NBR_CACHE_TYPE_GC (1) +#define NBR_CACHE_TYPE_REG (2) +#define NBR_CACHE_TYPE_TEN (3) +#define NBR_CACHE_LTIME_TEN (20) /* neighbor status values */ -#define NBR_STATUS_INCOMPLETE 0 -#define NBR_STATUS_REACHABLE 1 -#define NBR_STATUS_STALE 2 -#define NBR_STATUS_DELAY 3 -#define NBR_STATUS_PROBE 4 +#define NBR_STATUS_INCOMPLETE (0) +#define NBR_STATUS_REACHABLE (1) +#define NBR_STATUS_STALE (2) +#define NBR_STATUS_DELAY (3) +#define NBR_STATUS_PROBE (4) /* default router list size */ -#define DEF_RTR_LST_SIZE 3 /* geeigneten wert finden */ +#define DEF_RTR_LST_SIZE (3) /* geeigneten wert finden */ extern unsigned int nd_nbr_cache_rem_pid; diff --git a/sys/net/sixlowpan/sixlowpan.c b/sys/net/sixlowpan/sixlowpan.c index e6bb8f0439..29a81b0b03 100644 --- a/sys/net/sixlowpan/sixlowpan.c +++ b/sys/net/sixlowpan/sixlowpan.c @@ -80,7 +80,6 @@ char con_buf[CON_STACKSIZE]; char lowpan_transfer_buf[LOWPAN_TRANSFER_BUF_STACKSIZE]; lowpan_context_t contexts[LOWPAN_CONTEXT_MAX]; uint8_t context_len = 0; -uint8_t static_route = 0; uint16_t local_address = 0; void lowpan_context_auto_remove(void); @@ -103,15 +102,6 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data) data = &comp_buf[0]; packet_length = comp_len; - if(static_route == 1) { - if(laddr.uint8[7] < local_address) { - laddr.uint8[7] = local_address - 1; - } - else { - laddr.uint8[7] = local_address + 1; - } - } - /* check if packet needs to be fragmented */ if(packet_length + header_size > PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN) { uint8_t fragbuf[packet_length + header_size]; diff --git a/sys/net/sixlowpan/sixlowpan.h b/sys/net/sixlowpan/sixlowpan.h index 98034ee989..880dbd3fa5 100644 --- a/sys/net/sixlowpan/sixlowpan.h +++ b/sys/net/sixlowpan/sixlowpan.h @@ -1,121 +1,134 @@ -/* - * 6lowpan constants, data structs, and prototypes - * - * Copyright (C) 2013 INRIA. - * - * This file subject to the terms and conditions of the GNU Lesser General - * Public License. See the file LICENSE in the top level directory for more - * details. - * - * @ingroup sixlowpan - * @{ - * @file sixlowpan.h - * @brief 6lowpan header - * @author Stephan Zeisberg - * @author Martin Lenders - * @author Oliver Gesch - * @author Eric Engel - * @} - */ - -#ifndef SIXLOWPAN_H -#define SIXLOWPAN_H - -#define IP_PROCESS_STACKSIZE 3072 -#define NC_STACKSIZE 512 -#define CON_STACKSIZE 512 -#define LOWPAN_TRANSFER_BUF_STACKSIZE 512 - -/* fragment size in bytes*/ -#define FRAG_PART_ONE_HDR_LEN 4 -#define FRAG_PART_N_HDR_LEN 5 - -#define LOWPAN_IPHC_DISPATCH 0x60 -#define LOWPAN_IPHC_FL_C 0x10 -#define LOWPAN_IPHC_TC_C 0x08 -#define LOWPAN_IPHC_CID 0x80 -#define LOWPAN_IPHC_SAC 0x40 -#define LOWPAN_IPHC_SAM 0x30 -#define LOWPAN_IPHC_DAC 0x04 -#define LOWPAN_IPHC_DAM 0x03 -#define LOWPAN_IPHC_M 0x08 -#define LOWPAN_IPHC_NH 0x04 -#define LOWPAN_IPV6_DISPATCH 0x41 -#define LOWPAN_CONTEXT_MAX 16 - -#define LOWPAN_REAS_BUF_TIMEOUT 15 * 1000 * 1000 /* TODO: Set back to 3 * 1000 * 1000 */ - -#include "transceiver.h" -#include "sixlowip.h" -#include -#include -#include - -extern mutex_t lowpan_context_mutex; -extern uint8_t static_route; -extern uint16_t local_address; - -typedef struct { - uint8_t num; - ipv6_addr_t prefix; - uint8_t length; - uint8_t comp; - uint16_t lifetime; -} lowpan_context_t; - -typedef struct lowpan_interval_list_t { - uint8_t start; - uint8_t end; - struct lowpan_interval_list_t *next; -} lowpan_interval_list_t; - -typedef struct lowpan_reas_buf_t { - /* Source Address */ - ieee_802154_long_t s_laddr; - /* Destination Address */ - ieee_802154_long_t d_laddr; - /* Identification Number */ - uint16_t ident_no; - /* Timestamp of last packet fragment */ - long timestamp; - /* Size of reassembled packet with possible IPHC header */ - uint16_t packet_size; - /* Additive size of currently already received fragments */ - uint16_t current_packet_size; - /* Pointer to allocated memory for reassembled packet + 6LoWPAN Dispatch Byte */ - uint8_t *packet; - /* Pointer to list of intervals of received packet fragments (if any) */ - lowpan_interval_list_t *interval_list_head; - /* Pointer to next reassembly buffer (if any) */ - struct lowpan_reas_buf_t *next; -} lowpan_reas_buf_t; - -extern lowpan_reas_buf_t *head; - -void sixlowpan_init(transceiver_type_t trans, uint8_t r_addr, int as_border); -void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, - uint8_t r_addr); -void lowpan_init(ieee_802154_long_t *addr, uint8_t *data); -void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, - ieee_802154_long_t *d_laddr); -void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, uint8_t *ptr); -void lowpan_iphc_decoding(uint8_t *data, uint8_t length, - ieee_802154_long_t *s_laddr, - ieee_802154_long_t *d_laddr); -uint8_t lowpan_context_len(void); -void add_fifo_packet(lowpan_reas_buf_t *current_packet); -lowpan_context_t *lowpan_context_update( - uint8_t num, const ipv6_addr_t *prefix, - uint8_t length, uint8_t comp, - uint16_t lifetime); -lowpan_context_t *lowpan_context_get(void); -lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr); -lowpan_context_t *lowpan_context_num_lookup(uint8_t num); -lowpan_reas_buf_t *collect_garbage_fifo(lowpan_reas_buf_t *current_buf); -lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf); -void check_timeout(void); -void lowpan_ipv6_set_dispatch(uint8_t *data); -void init_reas_bufs(lowpan_reas_buf_t *buf); -void printReasBuffers(void); -void printFIFOBuffers(void); -#endif +/* + * 6lowpan constants, data structs, and prototypes + * + * Copyright (C) 2013 INRIA. + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * @ingroup sixlowpan + * @{ + * @file sixlowpan.h + * @brief 6lowpan header + * @author Stephan Zeisberg + * @author Martin Lenders + * @author Oliver Gesch + * @author Eric Engel + * @} + */ + +#ifndef SIXLOWPAN_H +#define SIXLOWPAN_H + +#define IP_PROCESS_STACKSIZE (3072) +#define NC_STACKSIZE (512) +#define CON_STACKSIZE (512) +#define LOWPAN_TRANSFER_BUF_STACKSIZE (512) + +/* fragment size in bytes*/ +#define FRAG_PART_ONE_HDR_LEN (4) +#define FRAG_PART_N_HDR_LEN (5) + +#define LOWPAN_IPHC_DISPATCH (0x60) +#define LOWPAN_IPHC_FL_C (0x10) +#define LOWPAN_IPHC_TC_C (0x08) +#define LOWPAN_IPHC_CID (0x80) +#define LOWPAN_IPHC_SAC (0x40) +#define LOWPAN_IPHC_SAM (0x30) +#define LOWPAN_IPHC_DAC (0x04) +#define LOWPAN_IPHC_DAM (0x03) +#define LOWPAN_IPHC_M (0x08) +#define LOWPAN_IPHC_NH (0x04) +#define LOWPAN_IPV6_DISPATCH (0x41) +#define LOWPAN_CONTEXT_MAX (16) + +#define LOWPAN_REAS_BUF_TIMEOUT (15 * 1000 * 1000) /* TODO: Set back to 3 * 1000 * (1000) */ + +#include "transceiver.h" +#include "sixlowip.h" +#include "vtimer.h" +#include "mutex.h" + +extern mutex_t lowpan_context_mutex; +extern uint16_t local_address; + +typedef struct { + uint8_t num; + ipv6_addr_t prefix; + uint8_t length; + uint8_t comp; + uint16_t lifetime; +} lowpan_context_t; + +typedef struct lowpan_interval_list_t { + uint8_t start; + uint8_t end; + struct lowpan_interval_list_t *next; +} lowpan_interval_list_t; + +typedef struct lowpan_reas_buf_t { + /* Source Address */ + ieee_802154_long_t s_laddr; + /* Destination Address */ + ieee_802154_long_t d_laddr; + /* Identification Number */ + uint16_t ident_no; + /* Timestamp of last packet fragment */ + long timestamp; + /* Size of reassembled packet with possible IPHC header */ + uint16_t packet_size; + /* Additive size of currently already received fragments */ + uint16_t current_packet_size; + /* Pointer to allocated memory for reassembled packet + 6LoWPAN Dispatch Byte */ + uint8_t *packet; + /* Pointer to list of intervals of received packet fragments (if any) */ + lowpan_interval_list_t *interval_list_head; + /* Pointer to next reassembly buffer (if any) */ + struct lowpan_reas_buf_t *next; +} lowpan_reas_buf_t; + +extern lowpan_reas_buf_t *head; + +/** + * @brief Initializes 6lowpan + * + * @param[in] trans transceiver to use with 6lowpan + * @param[in] r_addr phy layer address + * @param[in] as_border 1 if node shoud act as border router, 0 otherwise + */ +void sixlowpan_init(transceiver_type_t trans, uint8_t r_addr, int as_border); + +/** + * @brief Initializes a 6lowpan router with address prefix + * + * @param[in] trans transceiver to use with 6lowpan + * @param[in] prefix the address prefix to advertise + * @param[in] r_addr phy layer address + */ +void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, + uint8_t r_addr); +void lowpan_init(ieee_802154_long_t *addr, uint8_t *data); +void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, + ieee_802154_long_t *d_laddr); +void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, uint8_t *ptr); +void lowpan_iphc_decoding(uint8_t *data, uint8_t length, + ieee_802154_long_t *s_laddr, + ieee_802154_long_t *d_laddr); +uint8_t lowpan_context_len(void); +void add_fifo_packet(lowpan_reas_buf_t *current_packet); +lowpan_context_t *lowpan_context_update( + uint8_t num, const ipv6_addr_t *prefix, + uint8_t length, uint8_t comp, + uint16_t lifetime); +lowpan_context_t *lowpan_context_get(void); +lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr); +lowpan_context_t *lowpan_context_num_lookup(uint8_t num); +lowpan_reas_buf_t *collect_garbage_fifo(lowpan_reas_buf_t *current_buf); +lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf); +void check_timeout(void); +void lowpan_ipv6_set_dispatch(uint8_t *data); +void init_reas_bufs(lowpan_reas_buf_t *buf); +void printReasBuffers(void); +void printFIFOBuffers(void); +#endif