From b1d6e7d639eb1e9824b7f3333549e068792bfdd7 Mon Sep 17 00:00:00 2001
From: authmillenon <mlenders@inf.fu-berlin.de>
Date: Mon, 12 Aug 2013 11:08:19 +0200
Subject: [PATCH] Refactor border.h

---
 Makefile                                      |  1 +
 sys/net/sixlowpan/border.c                    | 20 +++-------------
 sys/net/sixlowpan/border.h                    |  2 --
 sys/net/sixlowpan/bordermultiplex.c           | 10 ++++----
 sys/net/sixlowpan/bordermultiplex.h           | 12 +++++-----
 sys/net/sixlowpan/flowcontrol.h               | 12 +++++-----
 sys/net/sixlowpan/include/sixlowpan.h         |  3 ---
 .../include/sixlowpan/borderrouter.h          | 24 -------------------
 sys/net/sixlowpan/include/sixlowpan/lowpan.h  | 16 +++++++++++++
 sys/net/sixlowpan/ip.c                        | 15 ++++++++++++
 sys/net/sixlowpan/ip.h                        |  1 +
 11 files changed, 53 insertions(+), 63 deletions(-)
 delete mode 100644 sys/net/sixlowpan/include/sixlowpan/borderrouter.h

diff --git a/Makefile b/Makefile
index d6744bed3c..cd5bd421c3 100644
--- a/Makefile
+++ b/Makefile
@@ -14,3 +14,4 @@ clean:
 
 doc:
 	make -BC doc/doxygen	
+
diff --git a/sys/net/sixlowpan/border.c b/sys/net/sixlowpan/border.c
index 2de368cb38..ecd82907ae 100644
--- a/sys/net/sixlowpan/border.c
+++ b/sys/net/sixlowpan/border.c
@@ -37,7 +37,7 @@
 #include "sys/net/ieee802154/ieee802154_frame.h"
 #include "sys/net/net_help/net_help.h"
 
-#define READER_STACK_SIZE   512
+#define READER_STACK_SIZE   (KERNEL_CONF_STACKSIZE_IDLE)
 
 ipv6_addr_t abr_addr;
 
@@ -120,7 +120,8 @@ void serial_reader_f(void)
     }
 }
 
-uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_addr)
+uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans, 
+        const ipv6_addr_t *border_router_addr)
 {
     ipv6_addr_t addr;
 
@@ -160,21 +161,6 @@ uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_a
     return SUCCESS;
 }
 
-void border_send_ipv6_over_lowpan(ipv6_hdr_t *packet, uint8_t aro_flag, uint8_t sixco_flag)
-{
-    uint16_t offset = IPV6_HDR_LEN + HTONS(packet->length);
-
-    packet->flowlabel = HTONS(packet->flowlabel);
-    packet->length = HTONS(packet->length);
-
-    memset(buffer, 0, BUFFER_SIZE);
-    memcpy(buffer + LL_HDR_LEN, packet, offset);
-
-    sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (packet->destaddr.uint16[4]),
-                            (uint8_t *)packet,
-                            offset);
-}
-
 void border_process_lowpan(void)
 {
     msg_t m;
diff --git a/sys/net/sixlowpan/border.h b/sys/net/sixlowpan/border.h
index 7828295ea9..6ee70b8dc4 100644
--- a/sys/net/sixlowpan/border.h
+++ b/sys/net/sixlowpan/border.h
@@ -36,8 +36,6 @@ uint16_t border_get_serial_reader(void);
 uint8_t *get_serial_out_buffer(int offset);
 uint8_t *get_serial_in_buffer(int offset);
 
-uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_addr);
-void border_send_ipv6_over_lowpan(ipv6_hdr_t *packet, uint8_t aro_flag, uint8_t sixco_flag);
 void border_process_lowpan(void);
 
 #endif /* _SIXLOWPAN_BORDER_H*/
diff --git a/sys/net/sixlowpan/bordermultiplex.c b/sys/net/sixlowpan/bordermultiplex.c
index ae3d29fbd9..e02d6f7b39 100644
--- a/sys/net/sixlowpan/bordermultiplex.c
+++ b/sys/net/sixlowpan/bordermultiplex.c
@@ -29,10 +29,10 @@
 
 #include "bordermultiplex.h"
 
-#define END         0xC0
-#define ESC         0xDB
-#define END_ESC     0xDC
-#define ESC_ESC     0xDD
+#define END         (0xC0)
+#define ESC         (0xDB)
+#define END_ESC     (0xDC)
+#define ESC_ESC     (0xDD)
 
 void demultiplex(border_packet_t *packet, int len)
 {
@@ -48,7 +48,7 @@ void demultiplex(border_packet_t *packet, int len)
             switch (l3_header_buf->ethertype) {
                 case (BORDER_ETHERTYPE_IPV6): {
                     ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
-                    border_send_ipv6_over_lowpan(ipv6_buf, 1, 1);
+                    ipv6_send_buf(ipv6_buf);
                     break;
                 }
 
diff --git a/sys/net/sixlowpan/bordermultiplex.h b/sys/net/sixlowpan/bordermultiplex.h
index c284953b30..b2d84299af 100644
--- a/sys/net/sixlowpan/bordermultiplex.h
+++ b/sys/net/sixlowpan/bordermultiplex.h
@@ -25,16 +25,16 @@
 #include "ip.h"
 
 /* packet types of uart-packets */
-#define BORDER_PACKET_RAW_TYPE    0
-#define BORDER_PACKET_CONF_TYPE   2
-#define BORDER_PACKET_L3_TYPE     3
+#define BORDER_PACKET_RAW_TYPE    (0)
+#define BORDER_PACKET_CONF_TYPE   (2)
+#define BORDER_PACKET_L3_TYPE     (3)
 
 /* configuration types */
-#define BORDER_CONF_CONTEXT       2
-#define BORDER_CONF_IPADDR        3
+#define BORDER_CONF_CONTEXT       (2)
+#define BORDER_CONF_IPADDR        (3)
 
 /* ethertypes for L3 packets */
-#define BORDER_ETHERTYPE_IPV6     0x86DD
+#define BORDER_ETHERTYPE_IPV6     (0x86DD)
 
 typedef struct __attribute__((packed)) {
     uint8_t empty;
diff --git a/sys/net/sixlowpan/flowcontrol.h b/sys/net/sixlowpan/flowcontrol.h
index f17a80c48e..cf7f811248 100644
--- a/sys/net/sixlowpan/flowcontrol.h
+++ b/sys/net/sixlowpan/flowcontrol.h
@@ -29,15 +29,15 @@
 #include "bordermultiplex.h"
 
 /* packet types for flowcontrol */
-#define BORDER_PACKET_ACK_TYPE    1
+#define BORDER_PACKET_ACK_TYPE    (1)
 
 /* configuration types for flowcontrol */
-#define BORDER_CONF_SYN           0
-#define BORDER_CONF_SYNACK        1
+#define BORDER_CONF_SYN           (0)
+#define BORDER_CONF_SYNACK        (1)
 
-#define BORDER_SWS                1
-#define BORDER_RWS                1
-#define BORDER_SL_TIMEOUT         500 // microseconds, maybe smaller
+#define BORDER_SWS                (1)
+#define BORDER_RWS                (1)
+#define BORDER_SL_TIMEOUT         (500) // microseconds, maybe smaller
 
 #define SENDING_SLOT_STACK_SIZE     (256)
 
diff --git a/sys/net/sixlowpan/include/sixlowpan.h b/sys/net/sixlowpan/include/sixlowpan.h
index eeb1634a70..f7a5e6df8b 100644
--- a/sys/net/sixlowpan/include/sixlowpan.h
+++ b/sys/net/sixlowpan/include/sixlowpan.h
@@ -43,12 +43,9 @@
 
 #include "sixlowpan/error.h"
 #include "sixlowpan/types.h"
-#include "sixlowpan/borderrouter.h"
 #include "sixlowpan/lowpan.h"
 #include "sixlowpan/mac.h"
 
-#include "../border.h"      /* TODO: remove if not needed anymore */
-
 /**
  * @}
  */
diff --git a/sys/net/sixlowpan/include/sixlowpan/borderrouter.h b/sys/net/sixlowpan/include/sixlowpan/borderrouter.h
deleted file mode 100644
index 2f40ee84af..0000000000
--- a/sys/net/sixlowpan/include/sixlowpan/borderrouter.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * 6LoWPAN constants, data structs, and prototypes for 6LoWPAN border router
- *
- * 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/borderrouter.h
- * @brief   6LoWPAN borderrouter 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>
- * @}
- */
-
-#ifndef SIXLOWPAN_BORDERROUTER_H
-#define SIXLOWPAN_BORDERROUTER_H
-
-#endif /* SIXLOWPAN_BORDERROUTER_H */
diff --git a/sys/net/sixlowpan/include/sixlowpan/lowpan.h b/sys/net/sixlowpan/include/sixlowpan/lowpan.h
index a2c7122d0d..2cda25b58d 100644
--- a/sys/net/sixlowpan/include/sixlowpan/lowpan.h
+++ b/sys/net/sixlowpan/include/sixlowpan/lowpan.h
@@ -193,6 +193,22 @@ void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
                                  const ipv6_addr_t *prefix, 
                                  uint8_t r_addr);
 
+/**
+ * @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.
+ *
+ * @param[in] trans    transceiver to use with 6LoWPAN.
+ * @param[in] border_router_addr    Address of this border router.
+ *
+ * @return  SUCCESS on success, otherwise SIXLOWERROR_ADDRESS if
+ *          address was not generated from IEEE 802.15.4 16-bit short
+ *          address.
+ */
+uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans,
+        const ipv6_addr_t *border_router_addr);
+
 /**
  * @brief   Send data via 6LoWPAN to destination node dest.
  *
diff --git a/sys/net/sixlowpan/ip.c b/sys/net/sixlowpan/ip.c
index 40d60e40cf..cd1d4b0e98 100644
--- a/sys/net/sixlowpan/ip.c
+++ b/sys/net/sixlowpan/ip.c
@@ -50,6 +50,21 @@ int rpl_process_pid = 0;
 /* registered upper layer threads */
 int sixlowip_reg[SIXLOWIP_MAX_REGISTERED];
 
+void ipv6_send_buf(ipv6_hdr_t *buffer)
+{
+    uint16_t offset = IPV6_HDR_LEN + HTONS(buffer->length);
+
+    buffer->flowlabel = HTONS(buffer->flowlabel);
+    buffer->length = HTONS(buffer->length);
+
+    memset(buffer, 0, BUFFER_SIZE);
+    memcpy(buffer + LL_HDR_LEN, buffer, offset);
+
+    sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (buffer->destaddr.uint16[4]),
+                            (uint8_t *)buffer,
+                            offset);
+}
+
 ipv6_hdr_t *get_ipv6_buf_send(void)
 {
     return ((ipv6_hdr_t *) & (ip_send_buffer[LL_HDR_LEN]));
diff --git a/sys/net/sixlowpan/ip.h b/sys/net/sixlowpan/ip.h
index 7baa7a2744..c6fa20ef45 100644
--- a/sys/net/sixlowpan/ip.h
+++ b/sys/net/sixlowpan/ip.h
@@ -134,6 +134,7 @@ typedef struct __attribute__((packed)) {
 
 extern iface_t iface;
 
+void ipv6_send_buf(ipv6_hdr_t *buffer);
 /* function prototypes */
 struct icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len);
 ipv6_hdr_t *get_ipv6_buf(void);
-- 
GitLab