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

added nestack-ip layer and completed netstack network #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
458 changes: 458 additions & 0 deletions core/dev/slip.c

Large diffs are not rendered by default.

845 changes: 845 additions & 0 deletions core/net/ip/tcpip.c

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions core/net/ip/uip-split.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/

#include <string.h>

#include "net/ip/uip-split.h"
#include "net/ip/uip.h"
#include "net/ipv4/uip-fw.h"
#include "net/ip/uip_arch.h"

#include "net/ip/tcpip.h"
#include "netstack.h"

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

#ifdef UIP_SPLIT_CONF_SIZE
#define UIP_SPLIT_SIZE UIP_SPLIT_CONF_SIZE
#else /* UIP_SPLIT_CONF_SIZE */
#define UIP_SPLIT_SIZE UIP_TCP_MSS
#endif /* UIP_SPLIT_CONF_SIZE */

/*-----------------------------------------------------------------------------*/
void
uip_split_output(void)
{
#if UIP_TCP
uint16_t tcplen, len1, len2;

/* We only split TCP segments that are larger than or equal to
UIP_SPLIT_SIZE, which is configurable through
UIP_SPLIT_CONF_SIZE. */
if(BUF->proto == UIP_PROTO_TCP &&
uip_len >= UIP_SPLIT_SIZE + UIP_TCPIP_HLEN) {

tcplen = uip_len - UIP_TCPIP_HLEN;
/* Split the segment in two. If the original packet length was
odd, we make the second packet one byte larger. */
len1 = len2 = tcplen / 2;
if(len1 + len2 < tcplen) {
++len2;
}

/* Create the first packet. This is done by altering the length
field of the IP header and updating the checksums. */
uip_len = len1 + UIP_TCPIP_HLEN;
#if NETSTACK_CONF_WITH_IPV6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
#else /* NETSTACK_CONF_WITH_IPV6 */
BUF->len[0] = uip_len >> 8;
BUF->len[1] = uip_len & 0xff;
#endif /* NETSTACK_CONF_WITH_IPV6 */

/* Recalculate the TCP checksum. */
BUF->tcpchksum = 0;
BUF->tcpchksum = ~(uip_tcpchksum());

#if !NETSTACK_CONF_WITH_IPV6
/* Recalculate the IP checksum. */
BUF->ipchksum = 0;
BUF->ipchksum = ~(uip_ipchksum());
#endif /* NETSTACK_CONF_WITH_IPV6 */

/* Transmit the first packet. */
/* uip_fw_output();*/

NETSTACK_IP.output();

/* Now, create the second packet. To do this, it is not enough to
just alter the length field, but we must also update the TCP
sequence number and point the uip_appdata to a new place in
memory. This place is detemined by the length of the first
packet (len1). */
uip_len = len2 + UIP_TCPIP_HLEN;
#if NETSTACK_CONF_WITH_IPV6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
#else /* NETSTACK_CONF_WITH_IPV6 */
BUF->len[0] = uip_len >> 8;
BUF->len[1] = uip_len & 0xff;
#endif /* NETSTACK_CONF_WITH_IPV6 */

/* uip_appdata += len1;*/
memcpy(uip_appdata, (uint8_t *)uip_appdata + len1, len2);

uip_add32(BUF->seqno, len1);
BUF->seqno[0] = uip_acc32[0];
BUF->seqno[1] = uip_acc32[1];
BUF->seqno[2] = uip_acc32[2];
BUF->seqno[3] = uip_acc32[3];

/* Recalculate the TCP checksum. */
BUF->tcpchksum = 0;
BUF->tcpchksum = ~(uip_tcpchksum());

#if !NETSTACK_CONF_WITH_IPV6
/* Recalculate the IP checksum. */
BUF->ipchksum = 0;
BUF->ipchksum = ~(uip_ipchksum());
#endif /* NETSTACK_CONF_WITH_IPV6 */

/* Transmit the second packet. */
/* uip_fw_output();*/

NETSTACK_IP.output();
return;
}
#endif /* UIP_TCP */

NETSTACK_IP.output();
}

/*-----------------------------------------------------------------------------*/
96 changes: 96 additions & 0 deletions core/net/ip/uip-udp-packet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/

/**
* \file
* Module for sending UDP packets through uIP.
* \author
* Adam Dunkels <adam@sics.se>
*/

#include "contiki-conf.h"

extern uint16_t uip_slen;

#include "net/ip/uip-udp-packet.h"
#include "net/ipv6/multicast/uip-mcast6.h"
#include "netstack.h"
#include <string.h>

/*---------------------------------------------------------------------------*/
void
uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len)
{
#if UIP_UDP
if(data != NULL && len <= (UIP_BUFSIZE - (UIP_LLH_LEN + UIP_IPUDPH_LEN))) {
uip_udp_conn = c;
uip_slen = len;
memmove(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data, len);
uip_process(UIP_UDP_SEND_CONN);

#if UIP_IPV6_MULTICAST
/* Let the multicast engine process the datagram before we send it */
if(uip_is_addr_mcast_routable(&uip_udp_conn->ripaddr)) {
UIP_MCAST6.out();
}
#endif /* UIP_IPV6_MULTICAST */

NETSTACK_IP.output();
}
uip_slen = 0;
#endif /* UIP_UDP */
}
/*---------------------------------------------------------------------------*/
void
uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
const uip_ipaddr_t *toaddr, uint16_t toport)
{
uip_ipaddr_t curaddr;
uint16_t curport;

if(toaddr != NULL) {
/* Save current IP addr/port. */
uip_ipaddr_copy(&curaddr, &c->ripaddr);
curport = c->rport;

/* Load new IP addr/port */
uip_ipaddr_copy(&c->ripaddr, toaddr);
c->rport = toport;

uip_udp_packet_send(c, data, len);

/* Restore old IP addr/port */
uip_ipaddr_copy(&c->ripaddr, &curaddr);
c->rport = curport;
}
}
/*---------------------------------------------------------------------------*/
17 changes: 7 additions & 10 deletions core/net/ipv6/sicslowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
#include "contiki.h"
#include "dev/watchdog.h"
#include "net/link-stats.h"
#include "net/ip/tcpip.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/rime/rime.h"
#include "net/ipv6/sicslowpan.h"
#include "net/netstack.h"
#include "net/ip/tcpip.h"

#include <stdio.h>

Expand Down Expand Up @@ -1609,7 +1609,7 @@ send_packet(linkaddr_t *dest)
* MAC.
*/
static uint8_t
output(const uip_lladdr_t *localdest)
output(const linkaddr_t *localdest)
{
int framer_hdrlen;
int max_payload;
Expand Down Expand Up @@ -2074,7 +2074,9 @@ input(void)
callback->input_callback();
}

tcpip_input();
PRINTF("TCP INPUT: %d\n", uip_len);
NETSTACK_IP.input();

#if SICSLOWPAN_CONF_FRAG
}
#endif /* SICSLOWPAN_CONF_FRAG */
Expand All @@ -2087,12 +2089,6 @@ input(void)
void
sicslowpan_init(void)
{
/*
* Set out output function as the function to be called from uIP to
* send a packet.
*/

tcpip_set_outputfunc(output);

#if SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_HC06
/* Preinitialize any address contexts for better header compression
Expand Down Expand Up @@ -2148,7 +2144,8 @@ sicslowpan_get_last_rssi(void)
const struct network_driver sicslowpan_driver = {
"sicslowpan",
sicslowpan_init,
input
input,
output
};
/*--------------------------------------------------------------------*/
/** @} */
Loading