Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate IPv6 and 6LoWPAN #357

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions sys/net/include/sixlowpan/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*
Expand Down
52 changes: 44 additions & 8 deletions sys/net/sixlowpan/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string.h>
#include <errno.h>

#include "transceiver.h"
#include "vtimer.h"
#include "mutex.h"
#include "msg.h"
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 {
Expand Down