diff --git a/sys/net/include/sixlowpan/ip.h b/sys/net/include/sixlowpan/ip.h index 5799ee627af6..cb3e7fd397e9 100644 --- a/sys/net/include/sixlowpan/ip.h +++ b/sys/net/include/sixlowpan/ip.h @@ -25,6 +25,14 @@ #include "sixlowpan/types.h" +/** + * @brief Data type to configure usage of 6LoWPAN + */ +typedef enum __attribute__((packed)) { + IPV6_6LOWPAN_DISABLE = 0, ///< 6LoWPAN disabled + IPV6_6LOWPAN_ENABLE = 1, ///< 6LoWPAN enabled +} ipv6_6lowpan_status_t; + /** * @brief IPv6 maximum transmission unit. */ @@ -60,6 +68,20 @@ */ #define IPV6_PROTO_NUM_IPV6_OPTS (60) +/** + * @brief Disable or enable 6LoWPAN compression layer (enabled by default). + * + * @param[in] status Status to set 6LoWPAN compression layer to. + */ +void ipv6_set_6lowpan_status(ipv6_6lowpan_status_t status); + +/** + * @brief Get current status of the 6LoWPAN compression layer. + * + * @return Status of the 6LoWPAN compression layer. + */ +ipv6_6lowpan_status_t ipv6_get_6lowpan_status(void); + /** * @brief Get IPv6 send/receive buffer. * diff --git a/sys/net/sixlowpan/ip.c b/sys/net/sixlowpan/ip.c index 7203e79e2294..7aa3e56cce78 100644 --- a/sys/net/sixlowpan/ip.c +++ b/sys/net/sixlowpan/ip.c @@ -22,6 +22,7 @@ #include #include +#include "transceiver.h" #include "vtimer.h" #include "mutex.h" #include "msg.h" @@ -40,6 +41,8 @@ #define IP_PKT_RECV_BUF_SIZE (64) #define LLHDR_IPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN) +static ipv6_6lowpan_status_t sixlowpan_enabled = IPV6_6LOWPAN_ENABLE; + uint8_t ip_send_buffer[BUFFER_SIZE]; uint8_t buffer[BUFFER_SIZE]; msg_t msg_queue[IP_PKT_RECV_BUF_SIZE]; @@ -56,6 +59,24 @@ ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t*) = 0; /* registered upper layer threads */ int sixlowip_reg[SIXLOWIP_MAX_REGISTERED]; +void ipv6_set_6lowpan_status(ipv6_6lowpan_status_t status) { + sixlowpan_enabled = status; +} + +ipv6_6lowpan_status_t ipv6_get_6lowpan_status(void) { + return IPV6_6LOWPAN_ENABLE; +} + +/** + * @brief Send IPv6 packets directly over the transceiver (with no 6LoWPAN + * or IEEE 802.15.4 in between). + * + * @param[in] bytes An IPv6 packet + */ +void ipv6_send_bytes_directly(ipv6_hdr_t *bytes, uint16_t packet_length) { + +} + void ipv6_send_bytes(ipv6_hdr_t *bytes) { uint16_t offset = IPV6_HDR_LEN + HTONS(bytes->length); @@ -66,9 +87,14 @@ void ipv6_send_bytes(ipv6_hdr_t *bytes) memset(bytes, 0, BUFFER_SIZE); memcpy(bytes + LL_HDR_LEN, bytes, offset); - sixlowpan_lowpan_sendto((ieee_802154_long_t *) &bytes->destaddr.uint16[4], - (uint8_t *)bytes, - offset); + if (sixlowpan_enable) { + sixlowpan_lowpan_sendto((ieee_802154_long_t *) &bytes->destaddr.uint16[4], + (uint8_t *)bytes, + offset); + } + else { + ipv6_send_bytes_directly(bytes, offset); + } } ipv6_hdr_t *ipv6_get_buf_send(void) @@ -137,8 +163,13 @@ void ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header, return; } - sixlowpan_lowpan_sendto((ieee_802154_long_t *) &dest->uint16[4], - (uint8_t *)ipv6_buf, packet_length); + if (sixlowpan_enable) { + sixlowpan_lowpan_sendto((ieee_802154_long_t *) &dest->uint16[4], + (uint8_t *)ipv6_buf, packet_length); + } + else { + ipv6_send_bytes_directly(ipv6_buf, packet_length); + } } /* Register an upper layer thread */ @@ -295,9 +326,14 @@ void ipv6_process(void) /* copy received packet to send buffer */ memcpy(ipv6_get_buf_send(), ipv6_get_buf(), packet_length); /* send packet to node ID derived from dest IP */ - sixlowpan_lowpan_sendto((ieee_802154_long_t *) &dest->uint16[4], - (uint8_t *)ipv6_get_buf_send(), - packet_length); + if (sixlowpan_enable) { + sixlowpan_lowpan_sendto((ieee_802154_long_t *) &dest->uint16[4], + (uint8_t *)ipv6_get_buf_send(), + packet_length); + } + else { + ipv6_send_bytes_directly(ipv6_get_buf_send(), packet_length); + } } /* destination is our address */ else {