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 #404

Closed
wants to merge 1 commit 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
11 changes: 0 additions & 11 deletions sys/net/include/sixlowpan/lowpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,6 @@ void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
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.
*
* @param[in] dest EUI-64 of destination node.
* @param[in] data Data to send to destination node (may be
* manipulated).
* @param[in] data_len Length of data.
*/
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
uint8_t *data, uint16_t data_len);

/**
* @brief Set header compression status for 6LoWPAN.
*
Expand Down
51 changes: 35 additions & 16 deletions sys/net/network_layer/sixlowpan/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ void icmpv6_send_echo_request(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq,
printf("INFO: send echo request to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4], (uint8_t *)ipv6_buf, packet_length);

radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &ipv6_buf->destaddr;
ipv6_send_next_layer(&p);
}

void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data, size_t data_len)
Expand Down Expand Up @@ -313,9 +318,12 @@ void icmpv6_send_echo_reply(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, ch
printf("INFO: send echo request to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4],
(uint8_t *)ipv6_buf,
packet_length);

radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &ipv6_buf->destaddr;
ipv6_send_next_layer(&p);
}

/* send router solicitation message - RFC4861 section 4.1 */
Expand Down Expand Up @@ -362,9 +370,12 @@ void icmpv6_send_router_sol(uint8_t sllao)
printf("INFO: send router solicitation to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4],
(uint8_t *)ipv6_buf,
packet_length);

radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &ipv6_buf->destaddr;
ipv6_send_next_layer(&p);
}

void recv_echo_req(void)
Expand Down Expand Up @@ -467,10 +478,12 @@ void recv_rtr_sol(void)
printf("INFO: send router advertisment to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4],
(uint8_t *)ipv6_buf,
IPV6_HDR_LEN + NTOHS(ipv6_buf->length));

radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = IPV6_HDR_LEN + NTOHS(ipv6_buf->length);
p.dst = (ieee_802154_long_t *) &ipv6_buf->destaddr;
ipv6_send_next_layer(&p);
}

uint8_t set_opt_6co_flags(uint8_t compression_flag, uint8_t cid)
Expand Down Expand Up @@ -853,9 +866,12 @@ void recv_rtr_adv(void)
printf("INFO: send neighbor solicitation to: %s\n",
ipv6_addr_to_str(addr_str, &(ipv6_buf->destaddr)));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4],
(uint8_t *)ipv6_buf,
packet_length);

radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &ipv6_buf->destaddr;
ipv6_send_next_layer(&p);
}
}

Expand Down Expand Up @@ -1114,9 +1130,12 @@ void recv_nbr_sol(void)
printf("INFO: send neighbor advertisment to: %s\n",
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
#endif
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &ipv6_buf->destaddr.uint16[4],
(uint8_t *)ipv6_buf,
packet_length);

radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &ipv6_buf->destaddr;
ipv6_send_next_layer(&p);
}
}

Expand Down
69 changes: 61 additions & 8 deletions sys/net/network_layer/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 "hwtimer.h"
#include "vtimer.h"
#include "mutex.h"
#include "msg.h"
Expand All @@ -40,6 +41,8 @@ char addr_str[IPV6_MAX_ADDR_STR_LEN];
#endif
#include "debug.h"

#define USE_SIXLOWPAN (0)

#define IP_PKT_RECV_BUF_SIZE (64)
#define LLHDR_IPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN)

Expand All @@ -49,6 +52,7 @@ msg_t msg_queue[IP_PKT_RECV_BUF_SIZE];
ipv6_hdr_t *ipv6_buf;
icmpv6_hdr_t *icmp_buf;
uint8_t *nextheader;
transceiver_type_t ipv6_transceiver_type;

uint8_t iface_addr_list_count = 0;
int udp_packet_handler_pid = 0;
Expand All @@ -59,6 +63,42 @@ ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t*) = 0;
/* registered upper layer threads */
int sixlowip_reg[SIXLOWIP_MAX_REGISTERED];

#if USE_SIXLOWPAN
static void ipv6_send_to_lowpan(radio_packet_t *p)
{
msg_t m, rep;
m.content.ptr = (char *) p;
msg_send_receive(&m, &rep, sixlowpan_lowpan_pid);
}
#else
static void ipv6_send_to_transceiver(radio_packet_t *p)
{
/* TODO: use p->dest.uint16[4]; */
msg_t transceiver_rsp;

static transceiver_command_t tcmd;
tcmd.transceivers = ipv6_transceiver_type;
tcmd.data = p;

msg_t mesg;
mesg.type = SND_PKT;
mesg.content.ptr = (char *) &tcmd;

msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid);

hwtimer_wait(5000);
}
#endif

void ipv6_send_next_layer(radio_packet_t *p)
{
#if USE_SIXLOWPAN
ipv6_send_to_lowpan(p);
#else
ipv6_send_to_transceiver(p);
#endif
}

void ipv6_send_bytes(ipv6_hdr_t *bytes)
{
uint16_t offset = IPV6_HDR_LEN + HTONS(bytes->length);
Expand All @@ -69,9 +109,11 @@ 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);
radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = offset;
p.dst = (ieee_802154_long_t *) &bytes->destaddr.uint16[4];
ipv6_send_next_layer(&p);
}

ipv6_hdr_t *ipv6_get_buf_send(void)
Expand Down Expand Up @@ -140,8 +182,11 @@ 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);
radio_packet_t p;
p.data = (uint8_t *) ipv6_buf;
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &dest->uint16[4];
ipv6_send_next_layer(&p);
}

/* Register an upper layer thread */
Expand Down Expand Up @@ -259,6 +304,11 @@ uint8_t ipv6_get_addr_match(const ipv6_addr_t *src,
return val;
}

void ipv6_init(transceiver_type_t trans)
{
ipv6_transceiver_type = trans;
}

void ipv6_process(void)
{
msg_t m_recv_lowpan, m_send_lowpan;
Expand Down Expand Up @@ -307,9 +357,12 @@ 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);

radio_packet_t p;
p.data = (uint8_t *) ipv6_get_buf_send();
p.length = packet_length;
p.dst = (ieee_802154_long_t *) &dest->uint16[4];
ipv6_send_next_layer(&p);
}
/* destination is our address */
else {
Expand Down
3 changes: 3 additions & 0 deletions sys/net/network_layer/sixlowpan/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "timex.h"
#include "mutex.h"
#include "transceiver.h"

#include "sixlowpan/ip.h"
#include "sixlowpan/types.h"
Expand Down Expand Up @@ -76,12 +77,14 @@ extern iface_t iface;

/* function prototypes */
void ipv6_send_bytes(ipv6_hdr_t *bytes);
void ipv6_send_next_layer(radio_packet_t *p);
icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len);
uint8_t *get_payload_buf(uint8_t ext_len);
uint8_t *get_payload_buf_send(uint8_t ext_len);

int icmpv6_demultiplex(const icmpv6_hdr_t *hdr);
void ipv6_init_iface_as_router(void);
void ipv6_init(transceiver_type_t trans);
void ipv6_process(void);
addr_list_t *ipv6_iface_addr_prefix_eq(ipv6_addr_t *addr);
addr_list_t *ipv6_iface_addr_match(const ipv6_addr_t *addr);
Expand Down
28 changes: 27 additions & 1 deletion sys/net/network_layer/sixlowpan/lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ unsigned int ip_process_pid;
unsigned int nd_nbr_cache_rem_pid = 0;
unsigned int contexts_rem_pid = 0;
unsigned int transfer_pid = 0;
unsigned int sixlowpan_lowpan_pid = 0;

iface_t iface;
ipv6_addr_t lladdr;
Expand Down Expand Up @@ -154,7 +155,7 @@ lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr);
void lowpan_ipv6_set_dispatch(uint8_t *data);

/* deliver packet to mac*/
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
static void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
uint8_t *data, uint16_t data_len)
{
uint8_t mcast = 0;
Expand Down Expand Up @@ -249,6 +250,27 @@ void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
tag++;
}

void sixlowpan_lowpan_process(void)
{
static msg_t m;
while (1) {
msg_receive(&m);

switch (m.type) {
case (SND_PKT): {
radio_packet_t *p = (radio_packet_t *) m.content.ptr;
sixlowpan_lowpan_sendto(p->dst, p->data, p->length);
msg_reply(&m, &m);
break;
}
default: {
DEBUG("unknown msg: dropping msg\n");
break;
}
}
}
}

void sixlowpan_lowpan_set_iphc_status(
sixlowpan_lowpan_iphc_status_t status)
{
Expand Down Expand Up @@ -1653,6 +1675,8 @@ void lowpan_init(transceiver_type_t trans, uint8_t r_addr,
ipv6_addr_t tmp;
short i;

sixlowpan_lowpan_pid = thread_pid;

/* init mac-layer and radio transceiver */
sixlowpan_mac_init(trans);

Expand Down Expand Up @@ -1706,6 +1730,8 @@ void lowpan_init(transceiver_type_t trans, uint8_t r_addr,
ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_LOOPBACK,
NDP_ADDR_STATE_PREFERRED, 0, 0);

ipv6_init(trans);

if (as_border) {
ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE,
PRIORITY_MAIN - 1, CREATE_STACKTEST,
Expand Down
1 change: 1 addition & 0 deletions sys/net/network_layer/sixlowpan/lowpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct {

extern uint16_t local_address;
extern mutex_t lowpan_context_mutex;
extern unsigned int sixlowpan_lowpan_pid;

void lowpan_read(uint8_t *data, uint8_t length,
ieee_802154_long_t *s_laddr,
Expand Down
29 changes: 18 additions & 11 deletions sys/net/network_layer/sixlowpan/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ static uint8_t r_src_addr;
uint8_t buf[PAYLOAD_SIZE];
static uint8_t macdsn;

static radio_packet_t p;
static msg_t mesg;
int transceiver_type;
static transceiver_command_t tcmd;
static msg_t mesg;

uint8_t sixlowpan_mac_get_radio_address(void)
{
Expand Down Expand Up @@ -204,20 +203,29 @@ void set_ieee802154_frame_values(ieee802154_frame_t *frame)
macdsn++;
}

void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
const uint8_t *payload,
uint8_t length, uint8_t mcast)
void sixlowpan_mac_send_to_transceiver(radio_packet_t *p)
{
uint16_t daddr;
/* TODO: check if dedicated response struct is necessary */
msg_t transceiver_rsp;
r_src_addr = local_address;

mesg.type = SND_PKT;
mesg.content.ptr = (char *) &tcmd;

tcmd.transceivers = transceiver_type;
tcmd.data = &p;
tcmd.data = p;

msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid);

hwtimer_wait(5000);
}

void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
const uint8_t *payload,
uint8_t length, uint8_t mcast)
{
uint16_t daddr;

r_src_addr = local_address;
ieee802154_frame_t frame;

memset(&frame, 0, sizeof(frame));
Expand All @@ -243,6 +251,7 @@ void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
buf[frame.payload_len+hdrlen+1] = 0x80;
DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", buf[0], buf[1], frame.dest_pan_id, frame.src_pan_id, frame.seq_nr);

radio_packet_t p;
p.length = hdrlen + frame.payload_len + IEEE_802154_FCS_LEN;

if (mcast == 0) {
Expand All @@ -253,9 +262,7 @@ void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
}

p.data = buf;
msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid);

hwtimer_wait(5000);
sixlowpan_mac_send_to_transceiver(&p);
}

void sixlowpan_mac_init(transceiver_type_t type)
Expand Down