2011-05-24 08:31:05 +02:00
|
|
|
|
|
|
|
/* Various stub functions and uIP variables other code might need to
|
|
|
|
* compile. Allows you to save needing to compile all of uIP in just
|
|
|
|
* to get a few things */
|
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#define NETSTACK_CONF_WITH_IPV6 1
|
2011-05-24 08:31:05 +02:00
|
|
|
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip.h"
|
2011-05-24 08:31:05 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#undef uip_buf
|
|
|
|
unsigned char *uip_buf;
|
2012-02-20 20:45:47 +01:00
|
|
|
uint16_t uip_len;
|
2011-05-24 08:31:05 +02:00
|
|
|
|
|
|
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
|
|
|
|
2012-02-20 20:45:47 +01:00
|
|
|
static uint16_t
|
|
|
|
chksum(uint16_t sum, const uint8_t *data, uint16_t len)
|
2011-05-24 08:31:05 +02:00
|
|
|
{
|
2012-02-20 20:45:47 +01:00
|
|
|
uint16_t t;
|
|
|
|
const uint8_t *dataptr;
|
|
|
|
const uint8_t *last_byte;
|
2011-05-24 08:31:05 +02:00
|
|
|
|
|
|
|
dataptr = data;
|
|
|
|
last_byte = data + len - 1;
|
|
|
|
|
|
|
|
while(dataptr < last_byte) { /* At least two more bytes */
|
|
|
|
t = (dataptr[0] << 8) + dataptr[1];
|
|
|
|
sum += t;
|
|
|
|
if(sum < t) {
|
|
|
|
sum++; /* carry */
|
|
|
|
}
|
|
|
|
dataptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dataptr == last_byte) {
|
|
|
|
t = (dataptr[0] << 8) + 0;
|
|
|
|
sum += t;
|
|
|
|
if(sum < t) {
|
|
|
|
sum++; /* carry */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return sum in host byte order. */
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2012-02-20 20:45:47 +01:00
|
|
|
static uint16_t
|
|
|
|
upper_layer_chksum(uint8_t proto)
|
2011-05-24 08:31:05 +02:00
|
|
|
{
|
2012-02-20 20:45:47 +01:00
|
|
|
uint16_t upper_layer_len;
|
|
|
|
uint16_t sum;
|
2011-05-24 08:31:05 +02:00
|
|
|
|
2012-02-20 20:45:47 +01:00
|
|
|
upper_layer_len = (((uint16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1]) ;
|
2011-05-24 08:31:05 +02:00
|
|
|
|
|
|
|
/* First sum pseudoheader. */
|
|
|
|
/* IP protocol and length fields. This addition cannot carry. */
|
|
|
|
sum = upper_layer_len + proto;
|
|
|
|
/* Sum IP source and destination addresses. */
|
2012-02-20 20:45:47 +01:00
|
|
|
sum = chksum(sum, (uint8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
|
2011-05-24 08:31:05 +02:00
|
|
|
|
|
|
|
/* Sum TCP header and data. */
|
|
|
|
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
|
|
|
|
upper_layer_len);
|
|
|
|
|
|
|
|
return (sum == 0) ? 0xffff : htons(sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-02-20 20:45:47 +01:00
|
|
|
uint16_t
|
2011-05-24 08:31:05 +02:00
|
|
|
uip_icmp6chksum(void)
|
|
|
|
{
|
|
|
|
return upper_layer_chksum(UIP_PROTO_ICMP6);
|
|
|
|
}
|
2013-07-03 20:26:54 +02:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
uip_ds6_link_neighbor_callback(int status, int numtx)
|
|
|
|
{
|
|
|
|
}
|