net: Use our network buffers instead of global ones in Contiki

This mega patch changes how Contiki uses buffers. In standard
Contiki there is only couple of static and global buffers.
This makes the stack non-reentrant and only usable in one
thread. This patch replaces the global buffer with buffer
supplied by caller (net_buf.h). The Contiki stack is still not
fully re-entrant after this (packet reassembly needs more TLC)
but it is a good start.

Change-Id: I63abc230b36b14f33f687d3ef64cffb0f3a69f5d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2015-06-08 16:23:20 +03:00 committed by Anas Nashif
commit 251a45b602
54 changed files with 1816 additions and 1545 deletions

View file

@ -41,13 +41,20 @@
#define __NET_BUF_H
#include <stdint.h>
#include <net/core/ip/uip.h>
#include "contiki/ip/uipopt.h"
#include "contiki/ip/uip.h"
#include "contiki/packetbuf.h"
struct net_context;
/*! The default MTU is 1280 (minimum IPv6 packet size) + LL header
* In Contiki terms this is UIP_LINK_MTU + UIP_LLH_LEN = UIP_BUFSIZE
*
* Contiki assumes that this value is UIP_BUFSIZE so do not change it
* without changing the value of UIP_BUFSIZE!
*/
#define NET_BUF_MAX_DATA (UIP_LINK_MTU + UIP_LLH_LEN)
#define NET_BUF_MAX_DATA UIP_BUFSIZE
struct net_buf {
/*! @cond ignore */
@ -58,6 +65,48 @@ struct net_buf {
/*! Network connection context */
struct net_context *context;
/*! @cond ignore */
/* uIP stack specific data */
uint8_t uip_ext_len;
uint8_t uip_ext_bitmap;
uint8_t uip_ext_opt_offset;
uint8_t uip_flags;
uint16_t uip_slen;
uint8_t *uip_next_hdr;
void *uip_appdata; /* application data */
void *uip_sappdata; /* app data to be sent */
void *uip_conn;
void *uip_udp_conn;
/* Neighbor discovery vars */
void *nd6_opt_prefix_info;
void *nd6_prefix;
void *nd6_nbr;
void *nd6_defrt;
void *nd6_ifaddr;
uint8_t *nd6_opt_llao;
uip_ipaddr_t ipaddr;
uint8_t nd6_opt_offset;
/* 6LoWPAN pointers */
uint8_t *packetbuf_ptr;
uint8_t packetbuf_hdr_len;
int packetbuf_payload_len;
uint8_t uncomp_hdr_len;
int last_tx_status;
/* 802.15.4 specific stuff */
/* FIXME - put behind #ifdef
* - have a separate buffers for these packets
*/
struct packetbuf_attr pkt_packetbuf_attrs[PACKETBUF_NUM_ATTRS];
struct packetbuf_addr pkt_packetbuf_addrs[PACKETBUF_NUM_ADDRS];
uint16_t pkt_buflen, pkt_bufptr;
uint8_t pkt_hdrptr;
uint8_t pkt_packetbuf[PACKETBUF_SIZE + PACKETBUF_HDR_SIZE];
uint8_t *pkt_packetbufptr;
/* @endcond */
/*! Buffer data length */
uint16_t len;
/*! Buffer head pointer */
@ -66,6 +115,50 @@ struct net_buf {
uint8_t buf[NET_BUF_MAX_DATA];
};
/*! @cond ignore */
/* Macros to access net_buf when inside Contiki stack */
#define uip_buf(buf) ((buf)->buf)
#define uip_len(buf) ((buf)->len)
#define uip_slen(buf) ((buf)->uip_slen)
#define uip_ext_len(buf) ((buf)->uip_ext_len)
#define uip_ext_bitmap(buf) ((buf)->uip_ext_bitmap)
#define uip_ext_opt_offset(buf) ((buf)->uip_ext_opt_offset)
#define uip_nd6_opt_offset(buf) ((buf)->nd6_opt_offset)
#define uip_next_hdr(buf) ((buf)->uip_next_hdr)
#define uip_appdata(buf) ((buf)->uip_appdata)
#define uip_sappdata(buf) ((buf)->uip_sappdata)
#define uip_flags(buf) ((buf)->uip_flags)
#define uip_conn(buf) ((struct uip_conn *)((buf)->uip_conn))
#define uip_set_conn(buf) ((buf)->uip_conn)
#define uip_udp_conn(buf) ((struct uip_udp_conn *)((buf)->uip_udp_conn))
#define uip_set_udp_conn(buf) ((buf)->uip_udp_conn)
#define uip_nd6_opt_prefix_info(buf) ((uip_nd6_opt_prefix_info *)((buf)->nd6_opt_prefix_info))
#define uip_set_nd6_opt_prefix_info(buf) ((buf)->nd6_opt_prefix_info)
#define uip_prefix(buf) ((uip_ds6_prefix_t *)((buf)->nd6_prefix))
#define uip_set_prefix(buf) ((buf)->nd6_prefix)
#define uip_nbr(buf) ((uip_ds6_nbr_t *)((buf)->nd6_nbr))
#define uip_set_nbr(buf) ((buf)->nd6_nbr)
#define uip_defrt(buf) ((uip_ds6_defrt_t *)((buf)->nd6_defrt))
#define uip_set_defrt(buf) ((buf)->nd6_defrt)
#define uip_addr(buf) ((uip_ds6_addr_t *)((buf)->nd6_ifaddr))
#define uip_set_addr(buf) ((buf)->nd6_ifaddr)
#define uip_nd6_opt_llao(buf) ((buf)->nd6_opt_llao)
#define uip_set_nd6_opt_llao(buf) ((buf)->nd6_opt_llao)
#define uip_nd6_ipaddr(buf) ((buf)->ipaddr)
#define uip_packetbuf_ptr(buf) ((buf)->packetbuf_ptr)
#define uip_packetbuf_hdr_len(buf) ((buf)->packetbuf_hdr_len)
#define uip_packetbuf_payload_len(buf) ((buf)->packetbuf_payload_len)
#define uip_uncomp_hdr_len(buf) ((buf)->uncomp_hdr_len)
#define uip_last_tx_status(buf) ((buf)->last_tx_status)
#define uip_pkt_buflen(buf) ((buf)->pkt_buflen)
#define uip_pkt_bufptr(buf) ((buf)->pkt_bufptr)
#define uip_pkt_hdrptr(buf) ((buf)->pkt_hdrptr)
#define uip_pkt_packetbuf(buf) ((buf)->pkt_packetbuf)
#define uip_pkt_packetbufptr(buf) ((buf)->pkt_packetbufptr)
#define uip_pkt_packetbuf_attrs(buf) ((buf)->pkt_packetbuf_attrs)
#define uip_pkt_packetbuf_addrs(buf) ((buf)->pkt_packetbuf_addrs)
/* @endcond */
/*!
* @brief Get buffer from the available buffers pool.
*

View file

@ -9,6 +9,8 @@ UIP_MODULES = net/ip/contiki/ip \
EXTRA_CFLAGS += ${PROJECTINCLUDE}
EXTRA_CFLAGS += -I${srctree}/net/ip/contiki
EXTRA_CFLAGS += -I${srctree}/net/ip/contiki/os/lib
EXTRA_CFLAGS += -I${srctree}/net/ip/contiki/os
EXTRA_CFLAGS += -I${srctree}/net/ip
EXTRA_CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1

View file

@ -56,4 +56,6 @@
#include "sys/energest.h"
#include <net/net_buf.h>
#endif /* CONTIKI_H_ */

View file

@ -42,6 +42,8 @@
* @{
*/
#include <net/net_buf.h>
#include "contiki-net.h"
#include "net/ip/simple-udp.h"
@ -50,9 +52,11 @@
PROCESS(simple_udp_process, "Simple UDP process");
static uint8_t started = 0;
#if 0
/* Moved to net_buf */
static uint8_t databuffer[UIP_BUFSIZE];
#define UIP_IP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
#endif
#define UIP_IP_BUF(buf) ((struct uip_udpip_hdr *)&uip_buf(buf)[UIP_LLH_LEN])
/*---------------------------------------------------------------------------*/
static void
@ -65,36 +69,36 @@ init_simple_udp(void)
}
/*---------------------------------------------------------------------------*/
int
simple_udp_send(struct simple_udp_connection *c,
simple_udp_send(struct net_buf *buf, struct simple_udp_connection *c,
const void *data, uint16_t datalen)
{
if(c->udp_conn != NULL) {
uip_udp_packet_sendto(c->udp_conn, data, datalen,
uip_udp_packet_sendto(buf, c->udp_conn, data, datalen,
&c->remote_addr, UIP_HTONS(c->remote_port));
}
return 0;
}
/*---------------------------------------------------------------------------*/
int
simple_udp_sendto(struct simple_udp_connection *c,
simple_udp_sendto(struct net_buf *buf, struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to)
{
if(c->udp_conn != NULL) {
uip_udp_packet_sendto(c->udp_conn, data, datalen,
uip_udp_packet_sendto(buf, c->udp_conn, data, datalen,
to, UIP_HTONS(c->remote_port));
}
return 0;
}
/*---------------------------------------------------------------------------*/
int
simple_udp_sendto_port(struct simple_udp_connection *c,
simple_udp_sendto_port(struct net_buf *buf, struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to,
uint16_t port)
{
if(c->udp_conn != NULL) {
uip_udp_packet_sendto(c->udp_conn, data, datalen,
uip_udp_packet_sendto(buf, c->udp_conn, data, datalen,
to, UIP_HTONS(port));
}
return 0;
@ -130,7 +134,7 @@ simple_udp_register(struct simple_udp_connection *c,
return 1;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(simple_udp_process, ev, data)
PROCESS_THREAD(simple_udp_process, ev, data, buf)
{
struct simple_udp_connection *c;
PROCESS_BEGIN();
@ -152,23 +156,24 @@ PROCESS_THREAD(simple_udp_process, ev, data)
/* If we were called because of incoming data, we should call
the reception callback. */
if(uip_newdata()) {
if(uip_newdata(buf)) {
#if 0
/* Copy the data from the uIP data buffer into our own
buffer to avoid the uIP buffer being messed with by the
callee. */
memcpy(databuffer, uip_appdata, uip_datalen());
#endif
/* Call the client process. We use the PROCESS_CONTEXT
mechanism to temporarily switch process context to the
client process. */
if(c->receive_callback != NULL) {
PROCESS_CONTEXT_BEGIN(c->client_process);
c->receive_callback(c,
&(UIP_IP_BUF->srcipaddr),
UIP_HTONS(UIP_IP_BUF->srcport),
&(UIP_IP_BUF->destipaddr),
UIP_HTONS(UIP_IP_BUF->destport),
databuffer, uip_datalen());
&(UIP_IP_BUF(buf)->srcipaddr),
UIP_HTONS(UIP_IP_BUF(buf)->srcport),
&(UIP_IP_BUF(buf)->destipaddr),
UIP_HTONS(UIP_IP_BUF(buf)->destport),
uip_buf(buf), uip_datalen(buf));
PROCESS_CONTEXT_END();
}
}

View file

@ -104,6 +104,7 @@ int simple_udp_register(struct simple_udp_connection *c,
/**
* \brief Send a UDP packet
* \param buf Buffer to send
* \param c A pointer to a struct simple_udp_connection
* \param data A pointer to the data to be sent
* \param datalen The length of the data
@ -115,11 +116,12 @@ int simple_udp_register(struct simple_udp_connection *c,
*
* \sa simple_udp_sendto()
*/
int simple_udp_send(struct simple_udp_connection *c,
int simple_udp_send(struct net_buf *buf, struct simple_udp_connection *c,
const void *data, uint16_t datalen);
/**
* \brief Send a UDP packet to a specified IP address
* \param buf Buffer to send
* \param c A pointer to a struct simple_udp_connection
* \param data A pointer to the data to be sent
* \param datalen The length of the data
@ -132,12 +134,13 @@ int simple_udp_send(struct simple_udp_connection *c,
*
* \sa simple_udp_send()
*/
int simple_udp_sendto(struct simple_udp_connection *c,
int simple_udp_sendto(struct net_buf *buf, struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to);
/**
* \brief Send a UDP packet to a specified IP address and UDP port
* \param buf Buffer to send
* \param c A pointer to a struct simple_udp_connection
* \param data A pointer to the data to be sent
* \param datalen The length of the data
@ -151,7 +154,7 @@ int simple_udp_sendto(struct simple_udp_connection *c,
*
* \sa simple_udp_sendto()
*/
int simple_udp_sendto_port(struct simple_udp_connection *c,
int simple_udp_sendto_port(struct net_buf *buf, struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to, uint16_t to_port);

View file

@ -60,9 +60,9 @@ void uip_log(char *msg);
#define UIP_LOG(m)
#endif
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_ICMP_BUF(buf) ((struct uip_icmp_hdr *)&uip_buf(buf)[UIP_LLIPH_LEN + uip_ext_len(buf)])
#define UIP_IP_BUF(buf) ((struct uip_ip_hdr *)&uip_buf(buf)[UIP_LLH_LEN])
#define UIP_TCP_BUF(buf) ((struct uip_tcpip_hdr *)&uip_buf(buf)[UIP_LLH_LEN])
#ifdef UIP_FALLBACK_INTERFACE
extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
@ -109,14 +109,14 @@ enum {
/* Called on IP packet output. */
#if NETSTACK_CONF_WITH_IPV6
static uint8_t (* outputfunc)(const uip_lladdr_t *a);
static uint8_t (* outputfunc)(struct net_buf *buf, const uip_lladdr_t *a);
uint8_t
tcpip_output(const uip_lladdr_t *a)
tcpip_output(struct net_buf *buf, const uip_lladdr_t *a)
{
int ret;
if(outputfunc != NULL) {
ret = outputfunc(a);
ret = outputfunc(buf, a);
return ret;
}
UIP_LOG("tcpip_output: Use tcpip_set_outputfunc() to set an output function");
@ -124,7 +124,7 @@ tcpip_output(const uip_lladdr_t *a)
}
void
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *))
tcpip_set_outputfunc(uint8_t (*f)(struct net_buf *buf, const uip_lladdr_t *))
{
outputfunc = f;
}
@ -152,6 +152,8 @@ tcpip_set_outputfunc(uint8_t (*f)(void))
unsigned char tcpip_is_forwarding; /* Forwarding right now? */
#endif /* UIP_CONF_IP_FORWARD */
struct net_buf;
PROCESS(tcpip_process, "TCP/IP stack");
/*---------------------------------------------------------------------------*/
@ -167,7 +169,7 @@ start_periodic_tcp_timer(void)
/*---------------------------------------------------------------------------*/
static void
check_for_tcp_syn(void)
check_for_tcp_syn(struct net_buf *buf)
{
#if UIP_TCP || UIP_CONF_IP_FORWARD
/* This is a hack that is needed to start the periodic TCP timer if
@ -176,15 +178,15 @@ check_for_tcp_syn(void)
this timer. This function is called for every incoming IP packet
to check for such SYNs. */
#define TCP_SYN 0x02
if(UIP_IP_BUF->proto == UIP_PROTO_TCP &&
(UIP_TCP_BUF->flags & TCP_SYN) == TCP_SYN) {
if(UIP_IP_BUF(buf)->proto == UIP_PROTO_TCP &&
(UIP_TCP_BUF(buf)->flags & TCP_SYN) == TCP_SYN) {
start_periodic_tcp_timer();
}
#endif /* UIP_TCP || UIP_CONF_IP_FORWARD */
}
/*---------------------------------------------------------------------------*/
static void
packet_input(void)
packet_input(struct net_buf *buf)
{
#if UIP_CONF_IP_FORWARD
if(uip_len > 0) {
@ -209,18 +211,18 @@ packet_input(void)
tcpip_is_forwarding = 0;
}
#else /* UIP_CONF_IP_FORWARD */
if(uip_len > 0) {
check_for_tcp_syn();
uip_input();
if(uip_len > 0) {
if(uip_len(buf) > 0) {
check_for_tcp_syn(buf);
uip_input(buf);
if(uip_len(buf) > 0) {
#if UIP_CONF_TCP_SPLIT
uip_split_output();
uip_split_output(buf);
#else /* UIP_CONF_TCP_SPLIT */
#if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output();
tcpip_ipv6_output(buf);
#else
PRINTF("tcpip packet_input output len %d\n", uip_len);
tcpip_output();
tcpip_output(buf);
#endif
#endif /* UIP_CONF_TCP_SPLIT */
}
@ -364,14 +366,15 @@ tcpip_icmp6_call(uint8_t type)
if(uip_icmp6_conns.appstate.p != PROCESS_NONE) {
/* XXX: This is a hack that needs to be updated. Passing a pointer (&type)
like this only works with process_post_synch. */
process_post_synch(uip_icmp6_conns.appstate.p, tcpip_icmp6_event, &type);
process_post_synch(uip_icmp6_conns.appstate.p, tcpip_icmp6_event, &type,
NULL);
}
return;
}
#endif /* UIP_CONF_ICMP6 */
/*---------------------------------------------------------------------------*/
static void
eventhandler(process_event_t ev, process_data_t data)
eventhandler(process_event_t ev, process_data_t data, struct net_buf *buf)
{
#if UIP_TCP
static unsigned char i;
@ -438,7 +441,7 @@ eventhandler(process_event_t ev, process_data_t data)
etimer_restart(&periodic);
uip_periodic(i);
#if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output();
tcpip_ipv6_output(buf);
#else
if(uip_len > 0) {
PRINTF("tcpip_output from periodic len %d\n", uip_len);
@ -462,7 +465,7 @@ eventhandler(process_event_t ev, process_data_t data)
if(data == &uip_reass_timer &&
etimer_expired(&uip_reass_timer)) {
uip_reass_over();
tcpip_ipv6_output();
tcpip_ipv6_output(buf);
}
#endif /* UIP_CONF_IPV6_REASSEMBLY */
/*
@ -477,14 +480,14 @@ eventhandler(process_event_t ev, process_data_t data)
#if !UIP_CONF_ROUTER
if(data == &uip_ds6_timer_rs &&
etimer_expired(&uip_ds6_timer_rs)) {
uip_ds6_send_rs();
tcpip_ipv6_output();
uip_ds6_send_rs(buf);
tcpip_ipv6_output(buf);
}
#endif /* !UIP_CONF_ROUTER */
if(data == &uip_ds6_timer_periodic &&
etimer_expired(&uip_ds6_timer_periodic)) {
uip_ds6_periodic();
tcpip_ipv6_output();
uip_ds6_periodic(buf);
tcpip_ipv6_output(buf);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
}
@ -495,7 +498,7 @@ eventhandler(process_event_t ev, process_data_t data)
if(data != NULL) {
uip_poll_conn(data);
#if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output();
tcpip_ipv6_output(buf);
#else /* NETSTACK_CONF_WITH_IPV6 */
if(uip_len > 0) {
PRINTF("tcpip_output from tcp poll len %d\n", uip_len);
@ -510,9 +513,9 @@ eventhandler(process_event_t ev, process_data_t data)
#if UIP_UDP
case UDP_POLL:
if(data != NULL) {
uip_udp_periodic_conn(data);
uip_udp_periodic_conn(buf, data);
#if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output();
tcpip_ipv6_output(buf);
#else
if(uip_len > 0) {
tcpip_output();
@ -523,57 +526,57 @@ eventhandler(process_event_t ev, process_data_t data)
#endif /* UIP_UDP */
case PACKET_INPUT:
packet_input();
packet_input(buf);
break;
};
}
/*---------------------------------------------------------------------------*/
void
tcpip_input(void)
tcpip_input(struct net_buf *buf)
{
process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
uip_len = 0;
process_post_synch(&tcpip_process, PACKET_INPUT, NULL, buf);
uip_len(buf) = 0;
#if NETSTACK_CONF_WITH_IPV6
uip_ext_len = 0;
uip_ext_len(buf) = 0;
#endif /*NETSTACK_CONF_WITH_IPV6*/
}
/*---------------------------------------------------------------------------*/
#if NETSTACK_CONF_WITH_IPV6
void
tcpip_ipv6_output(void)
tcpip_ipv6_output(struct net_buf *buf)
{
uip_ds6_nbr_t *nbr = NULL;
uip_ipaddr_t *nexthop;
if(uip_len == 0) {
if(uip_len(buf) == 0) {
return;
}
if(uip_len > UIP_LINK_MTU) {
if(uip_len(buf) > UIP_LINK_MTU) {
UIP_LOG("tcpip_ipv6_output: Packet to big");
uip_len = 0;
uip_len(buf) = 0;
return;
}
if(uip_is_addr_unspecified(&UIP_IP_BUF->destipaddr)){
if(uip_is_addr_unspecified(&UIP_IP_BUF(buf)->destipaddr)){
UIP_LOG("tcpip_ipv6_output: Destination address unspecified");
uip_len = 0;
uip_len(buf) = 0;
return;
}
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
if(!uip_is_addr_mcast(&UIP_IP_BUF(buf)->destipaddr)) {
/* Next hop determination */
nbr = NULL;
/* We first check if the destination address is on our immediate
link. If so, we simply use the destination address as our
nexthop address. */
if(uip_ds6_is_addr_onlink(&UIP_IP_BUF->destipaddr)){
nexthop = &UIP_IP_BUF->destipaddr;
if(uip_ds6_is_addr_onlink(&UIP_IP_BUF(buf)->destipaddr)){
nexthop = &UIP_IP_BUF(buf)->destipaddr;
} else {
uip_ds6_route_t *route;
/* Check if we have a route to the destination address. */
route = uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr);
route = uip_ds6_route_lookup(&UIP_IP_BUF(buf)->destipaddr);
/* No route was found - we send to the default route instead. */
if(route == NULL) {
@ -582,19 +585,19 @@ tcpip_ipv6_output(void)
if(nexthop == NULL) {
#ifdef UIP_FALLBACK_INTERFACE
PRINTF("FALLBACK: removing ext hdrs & setting proto %d %d\n",
uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40));
if(uip_ext_len > 0) {
uip_ext_len(buf), *((uint8_t *)UIP_IP_BUF(buf) + 40));
if(uip_ext_len(buf) > 0) {
extern void remove_ext_hdr(void);
uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40);
uint8_t proto = *((uint8_t *)UIP_IP_BUF(buf) + 40);
remove_ext_hdr();
/* This should be copied from the ext header... */
UIP_IP_BUF->proto = proto;
UIP_IP_BUF(buf)->proto = proto;
}
UIP_FALLBACK_INTERFACE.output();
#else
PRINTF("tcpip_ipv6_output: Destination off-link but no route\n");
#endif /* !UIP_FALLBACK_INTERFACE */
uip_len = 0;
uip_len(buf) = 0;
return;
}
@ -646,7 +649,7 @@ tcpip_ipv6_output(void)
#if UIP_CONF_IPV6_RPL
if(rpl_update_header_final(nexthop)) {
uip_len = 0;
uip_len(buf) = 0;
return;
}
#endif /* UIP_CONF_IPV6_RPL */
@ -654,14 +657,14 @@ tcpip_ipv6_output(void)
if(nbr == NULL) {
#if UIP_ND6_SEND_NA
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE)) == NULL) {
uip_len = 0;
uip_len(buf) = 0;
return;
} else {
#if UIP_CONF_IPV6_QUEUE_PKT
/* Copy outgoing pkt in the queuing buffer for later transmit. */
if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF(buf), uip_len(buf));
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len(buf));
}
#endif
/* RFC4861, 7.2.2:
@ -670,10 +673,10 @@ tcpip_ipv6_output(void)
* address SHOULD be placed in the IP Source Address of the outgoing
* solicitation. Otherwise, any one of the addresses assigned to the
* interface should be used."*/
if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)){
uip_nd6_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbr->ipaddr);
if(uip_ds6_is_my_addr(&UIP_IP_BUF(buf)->srcipaddr)){
uip_nd6_ns_output(buf, &UIP_IP_BUF(buf)->srcipaddr, NULL, &nbr->ipaddr);
} else {
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
uip_nd6_ns_output(buf, NULL, NULL, &nbr->ipaddr);
}
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
@ -688,11 +691,11 @@ tcpip_ipv6_output(void)
/* Copy outgoing pkt in the queuing buffer for later transmit and set
the destination nbr to nbr. */
if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF(buf), uip_len(buf));
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len(buf));
}
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
uip_len = 0;
uip_len(buf) = 0;
return;
}
/* Send in parallel if we are running NUD (nbc state is either STALE,
@ -705,7 +708,7 @@ tcpip_ipv6_output(void)
}
#endif /* UIP_ND6_SEND_NA */
tcpip_output(uip_ds6_nbr_get_ll(nbr));
tcpip_output(buf, uip_ds6_nbr_get_ll(nbr));
#if UIP_CONF_IPV6_QUEUE_PKT
/*
@ -715,22 +718,22 @@ tcpip_ipv6_output(void)
* to STALE, and you must both send a NA and the queued packet.
*/
if(uip_packetqueue_buflen(&nbr->packethandle) != 0) {
uip_len = uip_packetqueue_buflen(&nbr->packethandle);
memcpy(UIP_IP_BUF, uip_packetqueue_buf(&nbr->packethandle), uip_len);
uip_len(buf) = uip_packetqueue_buflen(&nbr->packethandle);
memcpy(UIP_IP_BUF(buf), uip_packetqueue_buf(&nbr->packethandle), uip_len(buf));
uip_packetqueue_free(&nbr->packethandle);
tcpip_output(uip_ds6_nbr_get_ll(nbr));
}
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
uip_len = 0;
uip_len(buf) = 0;
return;
}
return;
}
/* Multicast IP destination address. */
tcpip_output(NULL);
uip_len = 0;
uip_ext_len = 0;
tcpip_output(buf, NULL);
uip_len(buf) = 0;
uip_ext_len(buf) = 0;
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
/*---------------------------------------------------------------------------*/
@ -751,18 +754,18 @@ tcpip_poll_tcp(struct uip_conn *conn)
#endif /* UIP_TCP */
/*---------------------------------------------------------------------------*/
void
tcpip_uipcall(void)
tcpip_uipcall(struct net_buf *buf)
{
uip_udp_appstate_t *ts;
#if UIP_UDP
if(uip_conn != NULL) {
ts = &uip_conn->appstate;
if(uip_conn(buf) != NULL) {
ts = &uip_conn(buf)->appstate;
} else {
ts = &uip_udp_conn->appstate;
ts = &uip_udp_conn(buf)->appstate;
}
#else /* UIP_UDP */
ts = &uip_conn->appstate;
ts = &uip_conn(buf)->appstate;
#endif /* UIP_UDP */
#if UIP_TCP
@ -791,11 +794,11 @@ tcpip_uipcall(void)
#endif /* UIP_TCP */
if(ts->p != NULL) {
process_post_synch(ts->p, tcpip_event, ts->state);
process_post_synch(ts->p, tcpip_event, ts->state, buf);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tcpip_process, ev, data)
PROCESS_THREAD(tcpip_process, ev, data, buf)
{
PROCESS_BEGIN();
@ -827,7 +830,7 @@ PROCESS_THREAD(tcpip_process, ev, data)
while(1) {
PROCESS_YIELD();
eventhandler(ev, data);
eventhandler(ev, data, buf);
}
PROCESS_END();

View file

@ -68,6 +68,7 @@
#define TCPIP_H_
#include "contiki.h"
#include "net/ip/uipaddr.h"
struct uip_conn;
@ -77,7 +78,7 @@ struct tcpip_uipstate {
};
#define UIP_APPCALL tcpip_uipcall
#define UIP_UDP_APPCALL tcpip_uipcall
#define UIP_UDP_APPCALL(buf) tcpip_uipcall(buf)
#define UIP_ICMP6_APPCALL tcpip_icmp6_call
/*#define UIP_APPSTATE_SIZE sizeof(struct tcpip_uipstate)*/
@ -86,7 +87,7 @@ typedef struct tcpip_uipstate uip_udp_appstate_t;
typedef struct tcpip_uipstate uip_tcp_appstate_t;
typedef struct tcpip_uipstate uip_icmp6_appstate_t;
#include "net/ip/uip.h"
void tcpip_uipcall(void);
void tcpip_uipcall(struct net_buf *buf);
/**
* \name TCP functions
@ -334,15 +335,15 @@ CCIF extern process_event_t tcpip_event;
* and the length of the packet must be in the global
* uip_len variable.
*/
CCIF void tcpip_input(void);
CCIF void tcpip_input(struct net_buf *buf);
/**
* \brief Output packet to layer 2
* The eventual parameter is the MAC address of the destination.
*/
#if NETSTACK_CONF_WITH_IPV6
uint8_t tcpip_output(const uip_lladdr_t *);
void tcpip_set_outputfunc(uint8_t (* f)(const uip_lladdr_t *));
uint8_t tcpip_output(struct net_buf *buf, const uip_lladdr_t *);
void tcpip_set_outputfunc(uint8_t (* f)(struct net_buf *buf, const uip_lladdr_t *));
#else
uint8_t tcpip_output(void);
void tcpip_set_outputfunc(uint8_t (* f)(void));
@ -352,7 +353,7 @@ void tcpip_set_outputfunc(uint8_t (* f)(void));
* \brief This function does address resolution and then calls tcpip_output
*/
#if NETSTACK_CONF_WITH_IPV6
void tcpip_ipv6_output(void);
void tcpip_ipv6_output(struct net_buf *buf);
#endif
/**

View file

@ -29,6 +29,8 @@
*
*/
#include <net/net_buf.h>
#include "contiki-net.h"
#include "udp-socket.h"
@ -36,9 +38,12 @@
PROCESS(udp_socket_process, "UDP socket process");
#if 0
/* Moved to net_buf */
static uint8_t buf[UIP_BUFSIZE];
#endif
#define UIP_IP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_IP_BUF(buf) ((struct uip_udpip_hdr *)&uip_buf(buf)[UIP_LLH_LEN])
/*---------------------------------------------------------------------------*/
@ -118,19 +123,19 @@ udp_socket_connect(struct udp_socket *c,
}
/*---------------------------------------------------------------------------*/
int
udp_socket_send(struct udp_socket *c,
udp_socket_send(struct net_buf *buf, struct udp_socket *c,
const void *data, uint16_t datalen)
{
if(c == NULL || c->udp_conn == NULL) {
return -1;
}
uip_udp_packet_send(c->udp_conn, data, datalen);
uip_udp_packet_send(buf, c->udp_conn, data, datalen);
return datalen;
}
/*---------------------------------------------------------------------------*/
int
udp_socket_sendto(struct udp_socket *c,
udp_socket_sendto(struct net_buf *buf, struct udp_socket *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to,
uint16_t port)
@ -140,14 +145,14 @@ udp_socket_sendto(struct udp_socket *c,
}
if(c->udp_conn != NULL) {
uip_udp_packet_sendto(c->udp_conn, data, datalen,
uip_udp_packet_sendto(buf, c->udp_conn, data, datalen,
to, UIP_HTONS(port));
return datalen;
}
return -1;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_socket_process, ev, data)
PROCESS_THREAD(udp_socket_process, ev, data, buf)
{
struct udp_socket *c;
PROCESS_BEGIN();
@ -169,23 +174,27 @@ PROCESS_THREAD(udp_socket_process, ev, data)
/* If we were called because of incoming data, we should call
the reception callback. */
if(uip_newdata()) {
if(uip_newdata(buf)) {
/* Copy the data from the uIP data buffer into our own
buffer to avoid the uIP buffer being messed with by the
callee. */
memcpy(buf, uip_appdata, uip_datalen());
#if 0
/* Note that we cannot do this as the stack is suppose to be
* re-entrant.
*/
memcpy(bad_buf, uip_appdata(buf), uip_datalen(buf));
#endif
/* Call the client process. We use the PROCESS_CONTEXT
mechanism to temporarily switch process context to the
client process. */
if(c->input_callback != NULL) {
PROCESS_CONTEXT_BEGIN(c->p);
c->input_callback(c, c->ptr,
&(UIP_IP_BUF->srcipaddr),
UIP_HTONS(UIP_IP_BUF->srcport),
&(UIP_IP_BUF->destipaddr),
UIP_HTONS(UIP_IP_BUF->destport),
buf, uip_datalen());
&(UIP_IP_BUF(buf)->srcipaddr),
UIP_HTONS(UIP_IP_BUF(buf)->srcport),
&(UIP_IP_BUF(buf)->destipaddr),
UIP_HTONS(UIP_IP_BUF(buf)->destport),
uip_buf(buf), uip_datalen(buf));
PROCESS_CONTEXT_END();
}
}

View file

@ -32,12 +32,15 @@
#ifndef UDP_SOCKET_H
#define UDP_SOCKET_H
#include <net/net_buf.h>
#include "net/ip/uip.h"
struct udp_socket;
/**
* \brief A UDP socket callback function
* \param buf Buffer that received the data
* \param c A pointer to the struct udp_socket that received the data
* \param ptr An opaque pointer that was specified when the UDP socket was registered with udp_socket_register()
* \param source_addr The IP address from which the datagram was sent
@ -68,7 +71,6 @@ struct udp_socket {
struct process *p;
struct uip_udp_conn *udp_conn;
};
/**
@ -142,6 +144,7 @@ int udp_socket_connect(struct udp_socket *c,
uint16_t remote_port);
/**
* \brief Send data on a UDP socket
* \param buf Buffer to send
* \param c A pointer to the struct udp_socket on which the data should be sent
* \param data A pointer to the data that should be sent
* \param datalen The length of the data to be sent
@ -152,11 +155,12 @@ int udp_socket_connect(struct udp_socket *c,
* port with udp_socket_connect().
*
*/
int udp_socket_send(struct udp_socket *c,
int udp_socket_send(struct net_buf *buf, struct udp_socket *c,
const void *data, uint16_t datalen);
/**
* \brief Send data on a UDP socket to a specific address and port
* \param buf Buffer to send
* \param c A pointer to the struct udp_socket on which the data should be sent
* \param data A pointer to the data that should be sent
* \param datalen The length of the data to be sent
@ -171,7 +175,7 @@ int udp_socket_send(struct udp_socket *c,
* this function.
*
*/
int udp_socket_sendto(struct udp_socket *c,
int udp_socket_sendto(struct net_buf *buf, struct udp_socket *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *addr, uint16_t port);

View file

@ -19,7 +19,7 @@ MEMB(packets_memb, struct uip_packetqueue_packet, MAX_NUM_QUEUED_PACKETS);
/*---------------------------------------------------------------------------*/
static void
packet_timedout(void *ptr)
packet_timedout(struct net_buf *buf, void *ptr)
{
struct uip_packetqueue_handle *h = ptr;
@ -36,7 +36,7 @@ uip_packetqueue_new(struct uip_packetqueue_handle *handle)
}
/*---------------------------------------------------------------------------*/
struct uip_packetqueue_packet *
uip_packetqueue_alloc(struct uip_packetqueue_handle *handle, clock_time_t lifetime)
uip_packetqueue_alloc(struct net_buf *buf, struct uip_packetqueue_handle *handle, clock_time_t lifetime)
{
PRINTF("uip_packetqueue_alloc %p\n", handle);
if(handle->packet != NULL) {
@ -45,7 +45,7 @@ uip_packetqueue_alloc(struct uip_packetqueue_handle *handle, clock_time_t lifeti
}
handle->packet = memb_alloc(&packets_memb);
if(handle->packet != NULL) {
ctimer_set(&handle->packet->lifetimer, lifetime,
ctimer_set(buf, &handle->packet->lifetimer, lifetime,
packet_timedout, handle);
} else {
PRINTF("uip_packetqueue_alloc failed\n");

View file

@ -1,3 +1,5 @@
#include <net/net_buf.h>
#ifndef UIP_PACKETQUEUE_H
#define UIP_PACKETQUEUE_H
@ -21,7 +23,7 @@ void uip_packetqueue_new(struct uip_packetqueue_handle *handle);
struct uip_packetqueue_packet *
uip_packetqueue_alloc(struct uip_packetqueue_handle *handle, clock_time_t lifetime);
uip_packetqueue_alloc(struct net_buf *buf, struct uip_packetqueue_handle *handle, clock_time_t lifetime);
void

View file

@ -37,9 +37,9 @@
* Adam Dunkels <adam@sics.se>
*/
#include "contiki-conf.h"
#include <net/net_buf.h>
extern uint16_t uip_slen;
#include "contiki-conf.h"
#include "net/ip/uip-udp-packet.h"
#include "net/ipv6/multicast/uip-mcast6.h"
@ -48,38 +48,38 @@ extern uint16_t uip_slen;
/*---------------------------------------------------------------------------*/
void
uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len)
uip_udp_packet_send(struct net_buf *buf, struct uip_udp_conn *c, const void *data, int len)
{
#if UIP_UDP
if(data != NULL) {
uip_udp_conn = c;
uip_slen = len;
memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data,
uip_set_udp_conn(buf) = c;
uip_slen(buf) = len;
memcpy(&uip_buf(buf)[UIP_LLH_LEN + UIP_IPUDPH_LEN], data,
len > UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN?
UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN: len);
uip_process(UIP_UDP_SEND_CONN);
uip_process(buf, UIP_UDP_SEND_CONN);
#if UIP_CONF_IPV6_MULTICAST
/* Let the multicast engine process the datagram before we send it */
if(uip_is_addr_mcast_routable(&uip_udp_conn->ripaddr)) {
if(uip_is_addr_mcast_routable(&uip_udp_conn(buf)->ripaddr)) {
UIP_MCAST6.out();
}
#endif /* UIP_IPV6_MULTICAST */
#if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output();
tcpip_ipv6_output(buf);
#else
if(uip_len > 0) {
tcpip_output();
}
#endif
}
uip_slen = 0;
uip_slen(buf) = 0;
#endif /* UIP_UDP */
}
/*---------------------------------------------------------------------------*/
void
uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
uip_udp_packet_sendto(struct net_buf *buf, struct uip_udp_conn *c, const void *data, int len,
const uip_ipaddr_t *toaddr, uint16_t toport)
{
uip_ipaddr_t curaddr;
@ -94,7 +94,7 @@ uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
uip_ipaddr_copy(&c->ripaddr, toaddr);
c->rport = toport;
uip_udp_packet_send(c, data, len);
uip_udp_packet_send(buf, c, data, len);
/* Restore old IP addr/port */
uip_ipaddr_copy(&c->ripaddr, &curaddr);

View file

@ -40,10 +40,12 @@
#ifndef UIP_UDP_PACKET_H_
#define UIP_UDP_PACKET_H_
#include <net/net_buf.h>
#include "net/ip/uip.h"
void uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len);
void uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
void uip_udp_packet_send(struct net_buf *buf, struct uip_udp_conn *c, const void *data, int len);
void uip_udp_packet_sendto(struct net_buf *buf, struct uip_udp_conn *c, const void *data, int len,
const uip_ipaddr_t *toaddr, uint16_t toport);
#endif /* UIP_UDP_PACKET_H_ */

View file

@ -50,10 +50,17 @@
*/
#include <stdint.h>
#include <string.h>
#ifndef UIP_H_
#define UIP_H_
struct net_buf;
#include "net/ip/uipopt.h"
#include "net/ip/uipaddr.h"
#include "net/ip/tcpip.h"
/* Header sizes. */
#if NETSTACK_CONF_WITH_IPV6
#define UIP_IPH_LEN 40
@ -84,10 +91,10 @@
* we need values with and without LLH_LEN we do not use capital
* letters as these values are variable
*/
#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
#define uip_l2_l3_hdr_len(buf) (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len(buf))
#define uip_l2_l3_icmp_hdr_len(buf) (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len(buf) + UIP_ICMPH_LEN)
#define uip_l3_hdr_len(buf) (UIP_IPH_LEN + uip_ext_len(buf))
#define uip_l3_icmp_hdr_len(buf) (UIP_IPH_LEN + uip_ext_len(buf) + UIP_ICMPH_LEN)
#endif /*NETSTACK_CONF_WITH_IPV6*/
@ -277,7 +284,7 @@ void uip_setipid(uint16_t id);
*
* \hideinitializer
*/
#define uip_input() uip_process(UIP_DATA)
#define uip_input(buf) uip_process(buf, UIP_DATA)
/**
@ -415,8 +422,8 @@ void uip_setipid(uint16_t id);
*
* \hideinitializer
*/
#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
uip_process(UIP_UDP_TIMER); } while(0)
#define uip_udp_periodic_conn(buf, conn) do { uip_set_udp_conn(buf) = conn; \
uip_process(buf, UIP_UDP_TIMER); } while(0)
#endif /* UIP_UDP */
/** \brief Abandon the reassembly of the current packet */
@ -454,11 +461,13 @@ typedef union {
uint8_t u8[UIP_BUFSIZE];
} uip_buf_t;
#if 0
/* Moved to net_buf */
CCIF extern uip_buf_t uip_aligned_buf;
/** Macro to access uip_aligned_buf as an array of bytes */
#define uip_buf (uip_aligned_buf.u8)
#endif
/** @} */
@ -574,7 +583,9 @@ struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16_t port);
*
* \hideinitializer
*/
#if UIP_TCP
CCIF void uip_send(const void *data, int len);
#endif
/**
* The length of any incoming data that is currently available (if available)
@ -585,8 +596,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
/*void uip_datalen(void);*/
#define uip_datalen() uip_len
#define uip_datalen(buf) uip_len(buf)
/**
* The length of any out-of-band data (urgent data) that has arrived
@ -646,7 +656,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
#define uip_restart() do { uip_flags |= UIP_NEWDATA; \
#define uip_restart(buf) do { uip_flags(buf) |= UIP_NEWDATA; \
uip_conn->tcpstateflags &= ~UIP_STOPPED; \
} while(0)
@ -673,7 +683,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
#define uip_newdata() (uip_flags & UIP_NEWDATA)
#define uip_newdata(buf) (uip_flags(buf) & UIP_NEWDATA)
/**
* Has previously sent data been acknowledged?
@ -738,7 +748,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
#define uip_rexmit() (uip_flags & UIP_REXMIT)
#define uip_rexmit(buf) (uip_flags(buf) & UIP_REXMIT)
/**
* Is the connection being polled by uIP?
@ -752,7 +762,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
#define uip_poll() (uip_flags & UIP_POLL)
#define uip_poll(buf) (uip_flags(buf) & UIP_POLL)
/**
* Get the initial maximum segment size (MSS) of the current
@ -760,7 +770,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
#define uip_initialmss() (uip_conn->initialmss)
#define uip_initialmss(buf) (uip_conn(buf)->initialmss)
/**
* Get the current maximum segment size that can be sent on the current
@ -773,7 +783,7 @@ CCIF void uip_send(const void *data, int len);
*
* \hideinitializer
*/
#define uip_mss() (uip_conn->mss)
#define uip_mss(buf) (uip_conn(buf)->mss)
/**
* Set up a new UDP connection.
@ -836,7 +846,7 @@ struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport);
*
* \hideinitializer
*/
#define uip_udp_send(len) uip_send((char *)uip_appdata, len)
#define uip_udp_send(buf, len) uip_send((char *)uip_appdata(buf), len)
/** @} */
@ -1213,7 +1223,10 @@ CCIF uint32_t uip_htonl(uint32_t val);
* called. If the application wishes to send data, the application may
* use this space to write the data into before calling uip_send().
*/
#if 0
/* part of net_buf */
CCIF extern void *uip_appdata;
#endif
#if UIP_URGDATA > 0
/* uint8_t *uip_urgdata:
@ -1248,12 +1261,18 @@ extern void *uip_urgdata;
* packet.
*
*/
#if 0
/* No longer used as len is part of net_buf */
CCIF extern uint16_t uip_len;
#endif
/**
* The length of the extension headers
*/
#if 0
/* No longer used as len is part of net_buf */
extern uint8_t uip_ext_len;
#endif
/** @} */
#if UIP_URGDATA > 0
@ -1299,6 +1318,9 @@ struct uip_conn {
/** The application state. */
uip_tcp_appstate_t appstate;
/* buffer holding the data to this connection */
struct net_buf *buf;
};
@ -1308,8 +1330,10 @@ struct uip_conn {
* The uip_conn pointer can be used to access the current TCP
* connection.
*/
#if 0
/* Moved to net_buf */
CCIF extern struct uip_conn *uip_conn;
#endif
#if UIP_TCP
/* The array containing all uIP connections. */
CCIF extern struct uip_conn uip_conns[UIP_CONNS];
@ -1337,12 +1361,18 @@ struct uip_udp_conn {
/** The application state. */
uip_udp_appstate_t appstate;
/* buffer holding the data to this connection */
struct net_buf *buf;
};
/**
* The current UDP connection.
*/
#if 0
/* Moved to net_buf */
extern struct uip_udp_conn *uip_udp_conn;
#endif
extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
struct uip_fallback_interface {
@ -1353,6 +1383,9 @@ struct uip_fallback_interface {
#if UIP_CONF_ICMP6
struct uip_icmp6_conn {
uip_icmp6_appstate_t appstate;
/* buffer holding the data to this connection */
struct net_buf *buf;
};
extern struct uip_icmp6_conn uip_icmp6_conns;
#endif /*UIP_CONF_ICMP6*/
@ -1456,7 +1489,10 @@ struct uip_stats {
* that are defined in this file. Please read below for more
* information.
*/
#if 0
/* Moved to net_buf */
CCIF extern uint8_t uip_flags;
#endif
/* The following flags may be set in the global variable uip_flags
before calling the application callback. The UIP_ACKDATA,
@ -1508,7 +1544,7 @@ uip_ext_hdr_options_process(); */
*
* The actual uIP function which does all the work.
*/
void uip_process(uint8_t flag);
void uip_process(struct net_buf *buf, uint8_t flag);
/* The following flags are passed as an argument to the uip_process()
function. They are used to distinguish between the two cases where
@ -1810,7 +1846,7 @@ struct uip_udp_hdr {
* \hideinitializer
*/
#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
#define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
#define UIP_APPDATA_PTR(buf) (void *)&uip_buf(buf)[UIP_LLH_LEN + UIP_TCPIP_HLEN]
#define UIP_PROTO_ICMP 1
#define UIP_PROTO_TCP 6
@ -2129,7 +2165,7 @@ uint16_t uip_chksum(uint16_t *data, uint16_t len);
* \return The IP header checksum of the IP header in the uip_buf
* buffer.
*/
uint16_t uip_ipchksum(void);
uint16_t uip_ipchksum(struct net_buf *buf);
/**
* Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
@ -2151,14 +2187,14 @@ uint16_t uip_tcpchksum(void);
* \return The UDP checksum of the UDP segment in uip_buf and pointed
* to by uip_appdata.
*/
uint16_t uip_udpchksum(void);
uint16_t uip_udpchksum(struct net_buf *buf);
/**
* Calculate the ICMP checksum of the packet in uip_buf.
*
* \return The ICMP checksum of the ICMP packet in uip_buf
*/
uint16_t uip_icmp6chksum(void);
uint16_t uip_icmp6chksum(struct net_buf *buf);
#endif /* UIP_H_ */

File diff suppressed because it is too large Load diff

View file

@ -191,9 +191,9 @@ uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr)
}
/*---------------------------------------------------------------------------*/
void
uip_ds6_link_neighbor_callback(int status, int numtx)
uip_ds6_link_neighbor_callback(struct net_buf *buf, int status, int numtx)
{
const linkaddr_t *dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
const linkaddr_t *dest = packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER);
if(linkaddr_cmp(dest, &linkaddr_null)) {
return;
}
@ -232,7 +232,7 @@ uip_ds6_link_neighbor_callback(int status, int numtx)
}
/*---------------------------------------------------------------------------*/
void
uip_ds6_neighbor_periodic(void)
uip_ds6_neighbor_periodic(struct net_buf *buf)
{
/* Periodic processing on neighbors */
uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
@ -272,10 +272,10 @@ uip_ds6_neighbor_periodic(void)
case NBR_INCOMPLETE:
if(nbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
uip_ds6_nbr_rm(nbr);
} else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
} else if(stimer_expired(&nbr->sendns) && (uip_len(buf) == 0)) {
nbr->nscount++;
PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount);
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
uip_nd6_ns_output(buf, NULL, NULL, &nbr->ipaddr);
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
}
break;
@ -297,10 +297,10 @@ uip_ds6_neighbor_periodic(void)
}
}
uip_ds6_nbr_rm(nbr);
} else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
} else if(stimer_expired(&nbr->sendns) && (uip_len(buf) == 0)) {
nbr->nscount++;
PRINTF("PROBE: NS %u\n", nbr->nscount);
uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr);
uip_nd6_ns_output(buf, NULL, &nbr->ipaddr, &nbr->ipaddr);
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
}
break;

View file

@ -43,8 +43,7 @@
*
*/
#ifndef UIP_DS6_NEIGHBOR_H_
#define UIP_DS6_NEIGHBOR_H_
#include <net/net_buf.h>
#include "net/ip/uip.h"
#include "net/nbr-table.h"
@ -56,6 +55,9 @@
#include "net/ip/uip-packetqueue.h"
#endif /*UIP_CONF_QUEUE_PKT */
#ifndef UIP_DS6_NEIGHBOR_H_
#define UIP_DS6_NEIGHBOR_H_
/*--------------------------------------------------*/
/** \brief Possible states for the nbr cache entries */
#define NBR_INCOMPLETE 0
@ -93,8 +95,8 @@ uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr);
uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr);
uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr);
const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr);
void uip_ds6_link_neighbor_callback(int status, int numtx);
void uip_ds6_neighbor_periodic(void);
void uip_ds6_link_neighbor_callback(struct net_buf *buf, int status, int numtx);
void uip_ds6_neighbor_periodic(struct net_buf *buf);
int uip_ds6_nbr_num(void);
/**

View file

@ -81,6 +81,7 @@ uint8_t uip_ds6_netif_addr_list_offset;
static uip_ipaddr_t loc_fipaddr;
/* Pointers used in this file */
/* FIXME - we cannot do this as would prevent re-entrancy */
static uip_ds6_addr_t *locaddr;
static uip_ds6_maddr_t *locmaddr;
static uip_ds6_aaddr_t *locaaddr;
@ -142,8 +143,10 @@ uip_ds6_init(void)
/*---------------------------------------------------------------------------*/
void
uip_ds6_periodic(void)
uip_ds6_periodic(struct net_buf *buf)
{
uip_ds6_addr_t *locaddr;
uip_ds6_prefix_t *locprefix;
/* Periodic processing on unicast addresses */
for(locaddr = uip_ds6_if.addr_list;
@ -155,8 +158,8 @@ uip_ds6_periodic(void)
} else if((locaddr->state == ADDR_TENTATIVE)
&& (locaddr->dadnscount <= uip_ds6_if.maxdadns)
&& (timer_expired(&locaddr->dadtimer))
&& (uip_len == 0)) {
uip_ds6_dad(locaddr);
&& (uip_len(buf) == 0)) {
uip_ds6_dad(buf, locaddr);
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
}
}
@ -184,7 +187,7 @@ uip_ds6_periodic(void)
}
#endif /* !UIP_CONF_ROUTER */
uip_ds6_neighbor_periodic();
uip_ds6_neighbor_periodic(buf);
#if UIP_CONF_ROUTER && UIP_ND6_SEND_RA
/* Periodic RA sending */
@ -577,11 +580,11 @@ get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst)
/*---------------------------------------------------------------------------*/
#if UIP_ND6_DEF_MAXDADNS > 0
void
uip_ds6_dad(uip_ds6_addr_t *addr)
uip_ds6_dad(struct net_buf *buf, uip_ds6_addr_t *addr)
{
/* send maxdadns NS for DAD */
if(addr->dadnscount < uip_ds6_if.maxdadns) {
uip_nd6_ns_output(NULL, NULL, &addr->ipaddr);
uip_nd6_ns_output(buf, NULL, NULL, &addr->ipaddr);
addr->dadnscount++;
timer_set(&addr->dadtimer,
uip_ds6_if.retrans_timer / 1000 * CLOCK_SECOND);
@ -672,12 +675,12 @@ uip_ds6_send_ra_periodic(void)
#else /* UIP_CONF_ROUTER */
/*---------------------------------------------------------------------------*/
void
uip_ds6_send_rs(void)
uip_ds6_send_rs(struct net_buf *buf)
{
if((uip_ds6_defrt_choose() == NULL)
&& (rscount < UIP_ND6_MAX_RTR_SOLICITATIONS)) {
PRINTF("Sending RS %u\n", rscount);
uip_nd6_rs_output();
uip_nd6_rs_output(buf);
rscount++;
etimer_set(&uip_ds6_timer_rs,
UIP_ND6_RTR_SOLICITATION_INTERVAL * CLOCK_SECOND);

View file

@ -42,6 +42,8 @@
#ifndef UIP_DS6_H_
#define UIP_DS6_H_
#include <net/net_buf.h>
#include "net/ip/uip.h"
#include "sys/stimer.h"
/* The size of uip_ds6_addr_t depends on UIP_ND6_DEF_MAXDADNS. Include uip-nd6.h to define it. */
@ -244,7 +246,7 @@ extern struct etimer uip_ds6_timer_rs;
void uip_ds6_init(void);
/** \brief Periodic processing of data structures */
void uip_ds6_periodic(void);
void uip_ds6_periodic(struct net_buf *buf);
/** \brief Generic loop routine on an abstract data structure, which generalizes
* all data structures used in DS6 */
@ -310,7 +312,7 @@ uint8_t get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst);
#if UIP_ND6_DEF_MAXDADNS >0
/** \brief Perform Duplicate Address Selection on one address */
void uip_ds6_dad(uip_ds6_addr_t *ifaddr);
void uip_ds6_dad(struct net_buf *buf, uip_ds6_addr_t *ifaddr);
/** \brief Callback when DAD failed */
int uip_ds6_dad_failed(uip_ds6_addr_t *ifaddr);
@ -329,7 +331,7 @@ void uip_ds6_send_ra_periodic(void);
#endif /* UIP_ND6_SEND_RA */
#else /* UIP_CONF_ROUTER */
/** \brief Send periodic RS to find router */
void uip_ds6_send_rs(void);
void uip_ds6_send_rs(struct net_buf *buf);
#endif /* UIP_CONF_ROUTER */
/** \brief Compute the reachable time based on base reachable time, see RFC 4861*/

View file

@ -42,6 +42,8 @@
* \author Mathilde Durvy <mdurvy@cisco.com>
*/
#include <net/net_buf.h>
#include <string.h>
#include "net/ipv6/uip-ds6.h"
#include "net/ipv6/uip-icmp6.h"
@ -58,18 +60,21 @@
#define PRINT6ADDR(addr)
#endif
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
#define UIP_IP_BUF(buf) ((struct uip_ip_hdr *)&uip_buf(buf)[UIP_LLH_LEN])
#define UIP_ICMP_BUF(buf) ((struct uip_icmp_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_ICMP6_ERROR_BUF(buf) ((struct uip_icmp6_error *)&uip_buf(buf)[uip_l2_l3_icmp_hdr_len(buf)])
#define UIP_EXT_BUF(buf) ((struct uip_ext_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_FIRST_EXT_BUF(buf) ((struct uip_ext_hdr *)&uip_buf(buf)[UIP_LLIPH_LEN])
#if UIP_CONF_IPV6_RPL
#include "rpl/rpl.h"
#endif /* UIP_CONF_IPV6_RPL */
#if 0
/* Moved this to individual functions to make the API re-entrant */
/** \brief temporary IP address */
static uip_ipaddr_t tmp_ipaddr;
#endif
LIST(echo_reply_callback_list);
/*---------------------------------------------------------------------------*/
@ -95,7 +100,7 @@ input_handler_lookup(uint8_t type, uint8_t icode)
}
/*---------------------------------------------------------------------------*/
uint8_t
uip_icmp6_input(uint8_t type, uint8_t icode)
uip_icmp6_input(struct net_buf *buf, uint8_t type, uint8_t icode)
{
uip_icmp6_input_handler_t *handler = input_handler_lookup(type, icode);
@ -107,7 +112,7 @@ uip_icmp6_input(uint8_t type, uint8_t icode)
return UIP_ICMP6_INPUT_ERROR;
}
handler->handler();
handler->handler(buf);
return UIP_ICMP6_INPUT_SUCCESS;
}
/*---------------------------------------------------------------------------*/
@ -118,7 +123,7 @@ uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
}
/*---------------------------------------------------------------------------*/
static void
echo_request_input(void)
echo_request_input(struct net_buf *buf)
{
#if UIP_CONF_IPV6_RPL
uint8_t temp_ext_len;
@ -129,58 +134,60 @@ echo_request_input(void)
* headers and change a few fields
*/
PRINTF("Received Echo Request from");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->srcipaddr);
PRINTF("to");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->destipaddr);
PRINTF("\n");
/* IP header */
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
UIP_IP_BUF(buf)->ttl = uip_ds6_if.cur_hop_limit;
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)){
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
if(uip_is_addr_mcast(&UIP_IP_BUF(buf)->destipaddr)){
uip_ipaddr_copy(&UIP_IP_BUF(buf)->destipaddr, &UIP_IP_BUF(buf)->srcipaddr);
uip_ds6_select_src(&UIP_IP_BUF(buf)->srcipaddr, &UIP_IP_BUF(buf)->destipaddr);
} else {
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->srcipaddr);
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &tmp_ipaddr);
uip_ipaddr_t tmp_ipaddr;
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF(buf)->srcipaddr);
uip_ipaddr_copy(&UIP_IP_BUF(buf)->srcipaddr, &UIP_IP_BUF(buf)->destipaddr);
uip_ipaddr_copy(&UIP_IP_BUF(buf)->destipaddr, &tmp_ipaddr);
}
if(uip_ext_len > 0) {
if(uip_ext_len(buf) > 0) {
#if UIP_CONF_IPV6_RPL
if((temp_ext_len = rpl_invert_header())) {
/* If there were other extension headers*/
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
if (uip_ext_len != temp_ext_len) {
uip_len -= (uip_ext_len - temp_ext_len);
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
UIP_FIRST_EXT_BUF(buf)->next = UIP_PROTO_ICMP6;
if (uip_ext_len(buf) != temp_ext_len) {
uip_len(buf) -= (uip_ext_len(buf) - temp_ext_len);
UIP_IP_BUF(buf)->len[0] = ((uip_len(buf) - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_len(buf) - UIP_IPH_LEN) & 0xff);
/* move the echo request payload (starting after the icmp header)
* to the new location in the reply.
* The shift is equal to the length of the remaining extension headers present
* Note: UIP_ICMP_BUF still points to the echo request at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - (uip_ext_len - temp_ext_len),
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - temp_ext_len - UIP_ICMPH_LEN));
memmove((uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN - (uip_ext_len(buf) - temp_ext_len),
(uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN,
(uip_len(buf) - UIP_IPH_LEN - temp_ext_len - UIP_ICMPH_LEN));
}
uip_ext_len = temp_ext_len;
uip_ext_len(buf) = temp_ext_len;
} else {
#endif /* UIP_CONF_IPV6_RPL */
/* If there were extension headers*/
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
uip_len -= uip_ext_len;
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
UIP_IP_BUF(buf)->proto = UIP_PROTO_ICMP6;
uip_len(buf) -= uip_ext_len(buf);
UIP_IP_BUF(buf)->len[0] = ((uip_len(buf) - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_len(buf) - UIP_IPH_LEN) & 0xff);
/* move the echo request payload (starting after the icmp header)
* to the new location in the reply.
* The shift is equal to the length of the extension headers present
* Note: UIP_ICMP_BUF still points to the echo request at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
uip_ext_len = 0;
memmove((uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN - uip_ext_len(buf),
(uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN,
(uip_len(buf) - UIP_IPH_LEN - UIP_ICMPH_LEN));
uip_ext_len(buf) = 0;
#if UIP_CONF_IPV6_RPL
}
#endif /* UIP_CONF_IPV6_RPL */
@ -190,134 +197,136 @@ echo_request_input(void)
*/
/* Note: now UIP_ICMP_BUF points to the beginning of the echo reply */
UIP_ICMP_BUF->type = ICMP6_ECHO_REPLY;
UIP_ICMP_BUF->icode = 0;
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
UIP_ICMP_BUF(buf)->type = ICMP6_ECHO_REPLY;
UIP_ICMP_BUF(buf)->icode = 0;
UIP_ICMP_BUF(buf)->icmpchksum = 0;
UIP_ICMP_BUF(buf)->icmpchksum = ~uip_icmp6chksum(buf);
PRINTF("Sending Echo Reply to");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->destipaddr);
PRINTF("from");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->srcipaddr);
PRINTF("\n");
UIP_STAT(++uip_stat.icmp.sent);
return;
}
/*---------------------------------------------------------------------------*/
void
uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
uip_icmp6_error_output(struct net_buf *buf, uint8_t type, uint8_t code, uint32_t param) {
uip_ipaddr_t tmp_ipaddr;
/* check if originating packet is not an ICMP error*/
if (uip_ext_len) {
if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
uip_len = 0;
if (uip_ext_len(buf)) {
if(UIP_EXT_BUF(buf)->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF(buf)->type < 128){
uip_len(buf) = 0;
return;
}
} else {
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
uip_len = 0;
if(UIP_IP_BUF(buf)->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF(buf)->type < 128){
uip_len(buf) = 0;
return;
}
}
#if UIP_CONF_IPV6_RPL
uip_ext_len = rpl_invert_header();
uip_ext_len(buf) = rpl_invert_header();
#else /* UIP_CONF_IPV6_RPL */
uip_ext_len = 0;
uip_ext_len(buf) = 0;
#endif /* UIP_CONF_IPV6_RPL */
/* remember data of original packet before shifting */
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF(buf)->destipaddr);
uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN;
uip_len(buf) += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN;
if(uip_len > UIP_LINK_MTU)
uip_len = UIP_LINK_MTU;
if(uip_len(buf) > UIP_LINK_MTU)
uip_len(buf) = UIP_LINK_MTU;
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN,
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN);
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF(buf) + uip_ext_len(buf) + UIP_ICMP6_ERROR_LEN,
(void *)UIP_IP_BUF(buf), uip_len(buf) - UIP_IPICMPH_LEN - uip_ext_len(buf) - UIP_ICMP6_ERROR_LEN);
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
if (uip_ext_len) {
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
UIP_IP_BUF(buf)->vtc = 0x60;
UIP_IP_BUF(buf)->tcflow = 0;
UIP_IP_BUF(buf)->flow = 0;
if (uip_ext_len(buf)) {
UIP_FIRST_EXT_BUF(buf)->next = UIP_PROTO_ICMP6;
} else {
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
UIP_IP_BUF(buf)->proto = UIP_PROTO_ICMP6;
}
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
UIP_IP_BUF(buf)->ttl = uip_ds6_if.cur_hop_limit;
/* the source should not be unspecified nor multicast, the check for
multicast is done in uip_process */
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)){
uip_len = 0;
if(uip_is_addr_unspecified(&UIP_IP_BUF(buf)->srcipaddr)){
uip_len(buf) = 0;
return;
}
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
uip_ipaddr_copy(&UIP_IP_BUF(buf)->destipaddr, &UIP_IP_BUF(buf)->srcipaddr);
if(uip_is_addr_mcast(&tmp_ipaddr)){
if(type == ICMP6_PARAM_PROB && code == ICMP6_PARAMPROB_OPTION){
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
uip_ds6_select_src(&UIP_IP_BUF(buf)->srcipaddr, &tmp_ipaddr);
} else {
uip_len = 0;
uip_len(buf) = 0;
return;
}
} else {
#if UIP_CONF_ROUTER
/* need to pick a source that corresponds to this node */
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
uip_ds6_select_src(&UIP_IP_BUF(buf)->srcipaddr, &tmp_ipaddr);
#else
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
uip_ipaddr_copy(&UIP_IP_BUF(buf)->srcipaddr, &tmp_ipaddr);
#endif
}
UIP_ICMP_BUF->type = type;
UIP_ICMP_BUF->icode = code;
UIP_ICMP6_ERROR_BUF->param = uip_htonl(param);
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
UIP_ICMP_BUF(buf)->type = type;
UIP_ICMP_BUF(buf)->icode = code;
UIP_ICMP6_ERROR_BUF(buf)->param = uip_htonl(param);
UIP_IP_BUF(buf)->len[0] = ((uip_len(buf) - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_len(buf) - UIP_IPH_LEN) & 0xff);
UIP_ICMP_BUF(buf)->icmpchksum = 0;
UIP_ICMP_BUF(buf)->icmpchksum = ~uip_icmp6chksum(buf);
UIP_STAT(++uip_stat.icmp.sent);
PRINTF("Sending ICMPv6 ERROR message type %d code %d to", type, code);
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->destipaddr);
PRINTF("from");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->srcipaddr);
PRINTF("\n");
return;
}
/*---------------------------------------------------------------------------*/
void
uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len)
uip_icmp6_send(struct net_buf *buf, const uip_ipaddr_t *dest, int type, int code, int payload_len)
{
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8;
UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff;
UIP_IP_BUF(buf)->vtc = 0x60;
UIP_IP_BUF(buf)->tcflow = 0;
UIP_IP_BUF(buf)->flow = 0;
UIP_IP_BUF(buf)->proto = UIP_PROTO_ICMP6;
UIP_IP_BUF(buf)->ttl = uip_ds6_if.cur_hop_limit;
UIP_IP_BUF(buf)->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8;
UIP_IP_BUF(buf)->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff;
memcpy(&UIP_IP_BUF->destipaddr, dest, sizeof(*dest));
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
memcpy(&UIP_IP_BUF(buf)->destipaddr, dest, sizeof(*dest));
uip_ds6_select_src(&UIP_IP_BUF(buf)->srcipaddr, &UIP_IP_BUF(buf)->destipaddr);
UIP_ICMP_BUF->type = type;
UIP_ICMP_BUF->icode = code;
UIP_ICMP_BUF(buf)->type = type;
UIP_ICMP_BUF(buf)->icode = code;
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
UIP_ICMP_BUF(buf)->icmpchksum = 0;
UIP_ICMP_BUF(buf)->icmpchksum = ~uip_icmp6chksum(buf);
uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + payload_len;
tcpip_ipv6_output();
uip_len(buf) = UIP_IPH_LEN + UIP_ICMPH_LEN + payload_len;
tcpip_ipv6_output(buf);
}
/*---------------------------------------------------------------------------*/
static void
echo_reply_input(void)
echo_reply_input(struct net_buf *buf)
{
int ttl;
uip_ipaddr_t sender;
@ -325,46 +334,46 @@ echo_reply_input(void)
uint8_t temp_ext_len;
#endif /* UIP_CONF_IPV6_RPL */
uip_ipaddr_copy(&sender, &UIP_IP_BUF->srcipaddr);
ttl = UIP_IP_BUF->ttl;
uip_ipaddr_copy(&sender, &UIP_IP_BUF(buf)->srcipaddr);
ttl = UIP_IP_BUF(buf)->ttl;
if(uip_ext_len > 0) {
if(uip_ext_len(buf) > 0) {
#if UIP_CONF_IPV6_RPL
if((temp_ext_len = rpl_invert_header())) {
/* If there were other extension headers*/
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
if (uip_ext_len != temp_ext_len) {
uip_len -= (uip_ext_len - temp_ext_len);
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
UIP_FIRST_EXT_BUF(buf)->next = UIP_PROTO_ICMP6;
if (uip_ext_len(buf) != temp_ext_len) {
uip_len(buf) -= (uip_ext_len(buf) - temp_ext_len);
UIP_IP_BUF(buf)->len[0] = ((uip_len(buf) - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_len(buf) - UIP_IPH_LEN) & 0xff);
/* move the echo reply payload (starting after the icmp
* header) to the new location in the reply. The shift is
* equal to the length of the remaining extension headers
* present Note: UIP_ICMP_BUF still points to the echo reply
* at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - (uip_ext_len - temp_ext_len),
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - temp_ext_len - UIP_ICMPH_LEN));
memmove((uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN - (uip_ext_len(buf) - temp_ext_len),
(uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN,
(uip_len(buf) - UIP_IPH_LEN - temp_ext_len - UIP_ICMPH_LEN));
}
uip_ext_len = temp_ext_len;
uip_len -= uip_ext_len;
uip_ext_len(buf) = temp_ext_len;
uip_len(buf) -= uip_ext_len(buf);
} else {
#endif /* UIP_CONF_IPV6_RPL */
/* If there were extension headers*/
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
uip_len -= uip_ext_len;
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
UIP_IP_BUF(buf)->proto = UIP_PROTO_ICMP6;
uip_len(buf) -= uip_ext_len(buf);
UIP_IP_BUF(buf)->len[0] = ((uip_len(buf) - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_len(buf) - UIP_IPH_LEN) & 0xff);
/* move the echo reply payload (starting after the icmp header)
* to the new location in the reply. The shift is equal to the
* length of the extension headers present Note: UIP_ICMP_BUF
* still points to the echo request at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
uip_ext_len = 0;
memmove((uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN - uip_ext_len(buf),
(uint8_t *)UIP_ICMP_BUF(buf) + UIP_ICMPH_LEN,
(uip_len(buf) - UIP_IPH_LEN - UIP_ICMPH_LEN));
uip_ext_len(buf) = 0;
#if UIP_CONF_IPV6_RPL
}
#endif /* UIP_CONF_IPV6_RPL */
@ -379,13 +388,13 @@ echo_reply_input(void)
n = list_item_next(n)) {
if(n->callback != NULL) {
n->callback(&sender, ttl,
(uint8_t *)&UIP_ICMP_BUF[sizeof(struct uip_icmp_hdr)],
uip_len - sizeof(struct uip_icmp_hdr) - UIP_IPH_LEN);
(uint8_t *)&UIP_ICMP_BUF(buf)[sizeof(struct uip_icmp_hdr)],
uip_len(buf) - sizeof(struct uip_icmp_hdr) - UIP_IPH_LEN);
}
}
}
uip_len = 0;
uip_len(buf) = 0;
return;
}
/*---------------------------------------------------------------------------*/

View file

@ -42,6 +42,8 @@
* \author Mathilde Durvy <mdurvy@cisco.com>
*/
#include <net/net_buf.h>
#ifndef ICMP6_H_
#define ICMP6_H_
@ -115,7 +117,7 @@ typedef struct uip_icmp6_error{
* \param param 32 bit parameter of the error message, semantic depends on error
*/
void
uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param);
uip_icmp6_error_output(struct net_buf *buf, uint8_t type, uint8_t code, uint32_t param);
/**
* \brief Send an icmpv6 message
@ -125,7 +127,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param);
* \param payload_len length of the payload
*/
void
uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len);
uip_icmp6_send(struct net_buf *buf, const uip_ipaddr_t *dest, int type, int code, int payload_len);
@ -178,7 +180,7 @@ typedef struct uip_icmp6_input_handler {
struct uip_icmp6_input_handler *next;
uint8_t type;
uint8_t icode;
void (*handler)(void);
void (*handler)(struct net_buf *buf);
} uip_icmp6_input_handler_t;
#define UIP_ICMP6_INPUT_SUCCESS 0
@ -220,7 +222,7 @@ typedef struct uip_icmp6_input_handler {
* type and that it was invoked. It does NOT provide any indication whatsoever
* regarding whether the handler itself succeeded.
*/
uint8_t uip_icmp6_input(uint8_t type, uint8_t icode);
uint8_t uip_icmp6_input(struct net_buf *buf, uint8_t type, uint8_t icode);
/**
* \brief Register a handler which can handle a specific ICMPv6 message type

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,8 @@
#ifndef UIP_ND6_H_
#define UIP_ND6_H_
#include <net/net_buf.h>
#include "net/ip/uip.h"
#include "sys/stimer.h"
/**
@ -377,7 +379,7 @@ uip_nd6_ns_input(void);
* a SLLAO option, otherwise no.
*/
void
uip_nd6_ns_output(uip_ipaddr_t *src, uip_ipaddr_t *dest, uip_ipaddr_t *tgt);
uip_nd6_ns_output(struct net_buf *buf, uip_ipaddr_t *src, uip_ipaddr_t *dest, uip_ipaddr_t *tgt);
#if UIP_CONF_ROUTER
#if UIP_ND6_SEND_RA
@ -401,7 +403,7 @@ void uip_nd6_ra_output(uip_ipaddr_t *dest);
* possible option is SLLAO, MUST NOT be included if source = unspecified
* SHOULD be included otherwise
*/
void uip_nd6_rs_output(void);
void uip_nd6_rs_output(struct net_buf *buf);
/**
* \brief Initialise the uIP ND core

View file

@ -71,6 +71,8 @@
* the packet back to the peer.
*/
#include <net/net_buf.h>
#include "net/ip/uip.h"
#include "net/ip/uipopt.h"
#include "net/ipv6/uip-icmp6.h"
@ -132,6 +134,8 @@ uip_lladdr_t uip_lladdr = {{0x00,0x06,0x98,0x00,0x02,0x32}};
* field in the header before the fragmentation header, hence we need a pointer
* to this field.
*/
#if 0
/* Global variables cannot be used, these are moved to net_buf */
uint8_t *uip_next_hdr;
/** \brief bitmap we use to record which IPv6 headers we have already seen */
uint8_t uip_ext_bitmap = 0;
@ -142,6 +146,7 @@ uint8_t uip_ext_bitmap = 0;
uint8_t uip_ext_len = 0;
/** \brief length of the header options read */
uint8_t uip_ext_opt_offset = 0;
#endif
/** @} */
/*---------------------------------------------------------------------------*/
@ -151,28 +156,30 @@ uint8_t uip_ext_opt_offset = 0;
* \name Buffer defines
* @{
*/
#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_ROUTING_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_FRAG_BUF ((struct uip_frag_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define FBUF(buf) ((struct uip_tcpip_hdr *)&uip_reassbuf(buf)[0])
#define UIP_IP_BUF(buf) ((struct uip_ip_hdr *)&uip_buf(buf)[UIP_LLH_LEN])
#define UIP_ICMP_BUF(buf) ((struct uip_icmp_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_UDP_BUF(buf) ((struct uip_udp_hdr *)&uip_buf(buf)[UIP_LLH_LEN + UIP_IPH_LEN])
#define UIP_TCP_BUF(buf) ((struct uip_tcp_hdr *)&uip_buf(buf)[UIP_LLH_LEN + UIP_IPH_LEN])
#define UIP_EXT_BUF(buf) ((struct uip_ext_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_ROUTING_BUF(buf) ((struct uip_routing_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_FRAG_BUF(buf) ((struct uip_frag_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_HBHO_BUF(buf) ((struct uip_hbho_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_DESTO_BUF(buf) ((struct uip_desto_hdr *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf)])
#define UIP_EXT_HDR_OPT_BUF(buf) ((struct uip_ext_hdr_opt *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf) + uip_ext_opt_offset(buf)])
#define UIP_EXT_HDR_OPT_PADN_BUF(buf) ((struct uip_ext_hdr_opt_padn *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf) + uip_ext_opt_offset(buf)])
#if UIP_CONF_IPV6_RPL
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_RPL_BUF(buf) ((struct uip_ext_hdr_opt_rpl *)&uip_buf(buf)[uip_l2_l3_hdr_len(buf) + uip_ext_opt_offset(buf)])
#endif /* UIP_CONF_IPV6_RPL */
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
#define UIP_ICMP6_ERROR_BUF(buf) ((struct uip_icmp6_error *)&uip_buf(buf)[uip_l2_l3_icmp_hdr_len(buf)])
/** @} */
/**
* \name Buffer variables
* @{
*/
/** Packet buffer for incoming and outgoing packets */
#if 0
/* Global variables cannot be used, these are now in net_buf */
#ifndef UIP_CONF_EXTERNAL_BUFFER
uip_buf_t uip_aligned_buf;
#endif /* UIP_CONF_EXTERNAL_BUFFER */
@ -181,6 +188,7 @@ uip_buf_t uip_aligned_buf;
void *uip_appdata;
/* The uip_appdata pointer points to the application data which is to be sent*/
void *uip_sappdata;
#endif
#if UIP_URGDATA > 0
/* The uip_urgdata pointer points to urgent data (out-of-band data), if present */
@ -189,7 +197,7 @@ uint16_t uip_urglen, uip_surglen;
#endif /* UIP_URGDATA > 0 */
/* The uip_len is either 8 or 16 bits, depending on the maximum packet size.*/
uint16_t uip_len, uip_slen;
/* uint16_t uip_len, uip_slen; No longer used as len is part of net_buf */
/** @} */
/*---------------------------------------------------------------------------*/
@ -199,16 +207,15 @@ uint16_t uip_len, uip_slen;
*/
/*---------------------------------------------------------------------------*/
#if 0
/* Global variables cannot be used, these are now in net_buf */
/* The uip_flags variable is used for communication between the TCP/IP stack
and the application program. */
uint8_t uip_flags;
/* uip_conn always points to the current connection (set to NULL for UDP). */
struct uip_conn *uip_conn;
/* Temporary variables. */
#if (UIP_TCP || UIP_UDP)
static uint8_t c;
#endif
#if UIP_ACTIVE_OPEN || UIP_UDP
@ -267,7 +274,10 @@ static uint16_t tmp16;
*/
/*---------------------------------------------------------------------------*/
#if UIP_UDP
#if 0
/* Moved to net_buf */
struct uip_udp_conn *uip_udp_conn;
#endif
struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
#endif /* UIP_UDP */
/** @} */
@ -358,18 +368,18 @@ uip_chksum(uint16_t *data, uint16_t len)
/*---------------------------------------------------------------------------*/
#ifndef UIP_ARCH_IPCHKSUM
uint16_t
uip_ipchksum(void)
uip_ipchksum(struct net_buf *buf)
{
uint16_t sum;
sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
sum = chksum(0, &uip_buf(buf)[UIP_LLH_LEN], UIP_IPH_LEN);
PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
return (sum == 0) ? 0xffff : uip_htons(sum);
}
#endif
/*---------------------------------------------------------------------------*/
static uint16_t
upper_layer_chksum(uint8_t proto)
upper_layer_chksum(struct net_buf *buf, uint8_t proto)
{
/* gcc 4.4.0 - 4.6.1 (maybe 4.3...) with -Os on 8 bit CPUS incorrectly compiles:
* int bar (int);
@ -383,28 +393,28 @@ upper_layer_chksum(uint8_t proto)
volatile uint16_t upper_layer_len;
uint16_t sum;
upper_layer_len = (((uint16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1] - uip_ext_len);
upper_layer_len = (((uint16_t)(UIP_IP_BUF(buf)->len[0]) << 8) + UIP_IP_BUF(buf)->len[1] - uip_ext_len(buf));
PRINTF("Upper layer checksum len: %d from: %d\n", upper_layer_len,
UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len);
UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len(buf));
/* First sum pseudoheader. */
/* IP protocol and length fields. This addition cannot carry. */
sum = upper_layer_len + proto;
/* Sum IP source and destination addresses. */
sum = chksum(sum, (uint8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
sum = chksum(sum, (uint8_t *)&UIP_IP_BUF(buf)->srcipaddr, 2 * sizeof(uip_ipaddr_t));
/* Sum TCP header and data. */
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len],
sum = chksum(sum, &uip_buf(buf)[UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len(buf)],
upper_layer_len);
return (sum == 0) ? 0xffff : uip_htons(sum);
}
/*---------------------------------------------------------------------------*/
uint16_t
uip_icmp6chksum(void)
uip_icmp6chksum(struct net_buf *buf)
{
return upper_layer_chksum(UIP_PROTO_ICMP6);
return upper_layer_chksum(buf, UIP_PROTO_ICMP6);
}
/*---------------------------------------------------------------------------*/
@ -418,9 +428,9 @@ uip_tcpchksum(void)
/*---------------------------------------------------------------------------*/
#if UIP_UDP && UIP_UDP_CHECKSUMS
uint16_t
uip_udpchksum(void)
uip_udpchksum(struct net_buf *buf)
{
return upper_layer_chksum(UIP_PROTO_UDP);
return upper_layer_chksum(buf, UIP_PROTO_UDP);
}
#endif /* UIP_UDP && UIP_UDP_CHECKSUMS */
#endif /* UIP_ARCH_CHKSUM */
@ -428,6 +438,7 @@ uip_udpchksum(void)
void
uip_init(void)
{
uint8_t c;
uip_ds6_init();
uip_icmp6_init();
@ -462,6 +473,7 @@ struct uip_conn *
uip_connect(uip_ipaddr_t *ripaddr, uint16_t rport)
{
register struct uip_conn *conn, *cconn;
uint8_t c;
/* Find an unused local port. */
again:
@ -529,27 +541,28 @@ uip_connect(uip_ipaddr_t *ripaddr, uint16_t rport)
#endif /* UIP_TCP && UIP_ACTIVE_OPEN */
/*---------------------------------------------------------------------------*/
void
remove_ext_hdr(void)
remove_ext_hdr(struct net_buf *buf)
{
/* Remove ext header before TCP/UDP processing. */
if(uip_ext_len > 0) {
if(uip_ext_len(buf) > 0) {
PRINTF("Cutting ext-header before processing (extlen: %d, uiplen: %d)\n",
uip_ext_len, uip_len);
if(uip_len < UIP_IPH_LEN + uip_ext_len) {
uip_ext_len(buf), uip_len(buf));
if(uip_len(buf) < UIP_IPH_LEN + uip_ext_len(buf)) {
PRINTF("ERROR: uip_len too short compared to ext len\n");
uip_ext_len = 0;
uip_len = 0;
uip_ext_len(buf) = 0;
uip_len(buf) = 0;
return;
}
memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + uip_ext_len,
uip_len - UIP_IPH_LEN - uip_ext_len);
memmove(((uint8_t *)UIP_TCP_BUF(buf)),
(uint8_t *)UIP_TCP_BUF(buf) + uip_ext_len(buf),
uip_len(buf) - UIP_IPH_LEN - uip_ext_len(buf));
uip_len -= uip_ext_len;
uip_len(buf) -= uip_ext_len(buf);
/* Update the IP length. */
UIP_IP_BUF->len[0] = (uip_len - UIP_IPH_LEN) >> 8;
UIP_IP_BUF->len[1] = (uip_len - UIP_IPH_LEN) & 0xff;
uip_ext_len = 0;
UIP_IP_BUF(buf)->len[0] = (uip_len(buf) - UIP_IPH_LEN) >> 8;
UIP_IP_BUF(buf)->len[1] = (uip_len(buf) - UIP_IPH_LEN) & 0xff;
uip_ext_len(buf) = 0;
}
}
/*---------------------------------------------------------------------------*/
@ -558,6 +571,7 @@ struct uip_udp_conn *
uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
{
register struct uip_udp_conn *conn;
uint8_t c;
/* Find an unused local port. */
again:
@ -671,7 +685,7 @@ uip_reass(void)
buffer. The reset the other reassembly variables. */
if(uip_reass_on == 0) {
PRINTF("Starting reassembly\n");
memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN);
memcpy(FBUF, UIP_IP_BUF(buf), uip_ext_len(buf) + UIP_IPH_LEN);
/* temporary in case we do not receive the fragment with offset 0 first */
etimer_set(&uip_reass_timer, UIP_REASS_MAXAGE*CLOCK_SECOND);
uip_reass_on = 1;
@ -685,10 +699,10 @@ uip_reass(void)
* in the reasembly buffer. If so, we proceed with copying the fragment
* into the buffer.
*/
if(uip_ipaddr_cmp(&FBUF->srcipaddr, &UIP_IP_BUF->srcipaddr) &&
uip_ipaddr_cmp(&FBUF->destipaddr, &UIP_IP_BUF->destipaddr) &&
if(uip_ipaddr_cmp(&FBUF->srcipaddr, &UIP_IP_BUF(buf)->srcipaddr) &&
uip_ipaddr_cmp(&FBUF->destipaddr, &UIP_IP_BUF(buf)->destipaddr) &&
UIP_FRAG_BUF->id == uip_id) {
len = uip_len - uip_ext_len - UIP_IPH_LEN - UIP_FRAGH_LEN;
len = uip_len(buf) - uip_ext_len(buf) - UIP_IPH_LEN - UIP_FRAGH_LEN;
offset = (uip_ntohs(UIP_FRAG_BUF->offsetresmore) & 0xfff8);
/* in byte, originaly in multiple of 8 bytes*/
PRINTF("len %d\n", len);
@ -701,12 +715,12 @@ uip_reass(void)
* fragment's Fragment header.
*/
*uip_next_hdr = UIP_FRAG_BUF->next;
memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN);
memcpy(FBUF, UIP_IP_BUF(buf), uip_ext_len(buf) + UIP_IPH_LEN);
PRINTF("src ");
PRINT6ADDR(&FBUF->srcipaddr);
PRINTF("dest ");
PRINT6ADDR(&FBUF->destipaddr);
PRINTF("next %d\n", UIP_IP_BUF->proto);
PRINTF("next %d\n", UIP_IP_BUF(buf)->proto);
}
@ -738,13 +752,13 @@ uip_reass(void)
the conformance tests */
uip_reass_on = 0;
etimer_stop(&uip_reass_timer);
return uip_len;
return uip_len(buf);
}
}
/* Copy the fragment into the reassembly buffer, at the right
offset. */
memcpy((uint8_t *)FBUF + UIP_IPH_LEN + uip_ext_len + offset,
memcpy((uint8_t *)FBUF + UIP_IPH_LEN + uip_ext_len(buf) + offset,
(uint8_t *)UIP_FRAG_BUF + UIP_FRAGH_LEN, len);
/* Update the bitmap. */
@ -789,12 +803,12 @@ uip_reass(void)
uip_reass_on = 0;
etimer_stop(&uip_reass_timer);
uip_reasslen += UIP_IPH_LEN + uip_ext_len;
memcpy(UIP_IP_BUF, FBUF, uip_reasslen);
UIP_IP_BUF->len[0] = ((uip_reasslen - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_reasslen - UIP_IPH_LEN) & 0xff);
uip_reasslen += UIP_IPH_LEN + uip_ext_len(buf);
memcpy(UIP_IP_BUF(buf), FBUF, uip_reasslen);
UIP_IP_BUF(buf)->len[0] = ((uip_reasslen - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_reasslen - UIP_IPH_LEN) & 0xff);
PRINTF("REASSEMBLED PAQUET %d (%d)\n", uip_reasslen,
(UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]);
(UIP_IP_BUF(buf)->len[0] << 8) | UIP_IP_BUF(buf)->len[1]);
return uip_reasslen;
@ -806,7 +820,7 @@ uip_reass(void)
}
void
uip_reass_over(void)
uip_reass_over(struct net_buf *buf)
{
/* to late, we abandon the reassembly of the packet */
@ -824,14 +838,14 @@ uip_reass_over(void)
* any RFC, we decided not to include it as it reduces the size of
* the packet.
*/
uip_len = 0;
uip_ext_len = 0;
memcpy(UIP_IP_BUF, FBUF, UIP_IPH_LEN); /* copy the header for src
uip_len(buf) = 0;
uip_ext_len(buf) = 0;
memcpy(UIP_IP_BUF(buf), FBUF, UIP_IPH_LEN); /* copy the header for src
and dest address*/
uip_icmp6_error_output(ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_REASSEMBLY, 0);
UIP_STAT(++uip_stat.ip.sent);
uip_flags = 0;
uip_flags(buf) = 0;
}
}
@ -855,16 +869,16 @@ uip_add_rcv_nxt(uint16_t n)
* \brief Process the options in Destination and Hop By Hop extension headers
*/
static uint8_t
ext_hdr_options_process(void)
ext_hdr_options_process(struct net_buf *buf)
{
/*
* Length field in the extension header: length of the header in units of
* 8 bytes, excluding the first 8 bytes
* length field in an option : the length of data in the option
*/
uip_ext_opt_offset = 2;
while(uip_ext_opt_offset < ((UIP_EXT_BUF->len << 3) + 8)) {
switch(UIP_EXT_HDR_OPT_BUF->type) {
uip_ext_opt_offset(buf) = 2;
while(uip_ext_opt_offset(buf) < ((UIP_EXT_BUF(buf)->len << 3) + 8)) {
switch(UIP_EXT_HDR_OPT_BUF(buf)->type) {
/*
* for now we do not support any options except padding ones
* PAD1 does not make sense as the header must be 8bytes aligned,
@ -872,11 +886,11 @@ ext_hdr_options_process(void)
*/
case UIP_EXT_HDR_OPT_PAD1:
PRINTF("Processing PAD1 option\n");
uip_ext_opt_offset += 1;
uip_ext_opt_offset(buf) += 1;
break;
case UIP_EXT_HDR_OPT_PADN:
PRINTF("Processing PADN option\n");
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2;
uip_ext_opt_offset(buf) += UIP_EXT_HDR_OPT_PADN_BUF(buf)->opt_len + 2;
break;
case UIP_EXT_HDR_OPT_RPL:
/* Fixes situation when a node that is not using RPL
@ -889,12 +903,12 @@ ext_hdr_options_process(void)
*/
#if UIP_CONF_IPV6_RPL
PRINTF("Processing RPL option\n");
if(rpl_verify_header(uip_ext_opt_offset)) {
if(rpl_verify_header(uip_ext_opt_offset(buf))) {
PRINTF("RPL Option Error: Dropping Packet\n");
return 1;
}
#endif /* UIP_CONF_IPV6_RPL */
uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF->len) + 2;
uip_ext_opt_offset(buf) += (UIP_EXT_HDR_OPT_BUF(buf)->len) + 2;
return 0;
default:
/*
@ -910,23 +924,23 @@ ext_hdr_options_process(void)
* Problem, Code 2, message to the packet's Source Address,
* pointing to the unrecognized Option Type.
*/
PRINTF("MSB %x\n", UIP_EXT_HDR_OPT_BUF->type);
switch(UIP_EXT_HDR_OPT_BUF->type & 0xC0) {
PRINTF("MSB %x\n", UIP_EXT_HDR_OPT_BUF(buf)->type);
switch(UIP_EXT_HDR_OPT_BUF(buf)->type & 0xC0) {
case 0:
break;
case 0x40:
return 1;
case 0xC0:
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
if(uip_is_addr_mcast(&UIP_IP_BUF(buf)->destipaddr)) {
return 1;
}
case 0x80:
uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION,
(uint32_t)UIP_IPH_LEN + uip_ext_len + uip_ext_opt_offset);
uip_icmp6_error_output(buf, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION,
(uint32_t)UIP_IPH_LEN + uip_ext_len(buf) + uip_ext_opt_offset(buf));
return 2;
}
/* in the cases were we did not discard, update ext_opt* */
uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF->len + 2;
uip_ext_opt_offset(buf) += UIP_EXT_HDR_OPT_BUF(buf)->len + 2;
break;
}
}
@ -936,7 +950,7 @@ ext_hdr_options_process(void)
/*---------------------------------------------------------------------------*/
void
uip_process(uint8_t flag)
uip_process(struct net_buf *buf, uint8_t flag)
{
#if UIP_TCP
register struct uip_conn *uip_connr = uip_conn;
@ -946,7 +960,7 @@ uip_process(uint8_t flag)
goto udp_send;
}
#endif /* UIP_UDP */
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
uip_sappdata(buf) = uip_appdata(buf) = &uip_buf(buf)[UIP_IPTCPH_LEN + UIP_LLH_LEN];
/* Check if we were invoked because of a poll request for a
particular connection. */
@ -960,7 +974,7 @@ uip_process(uint8_t flag)
#if UIP_ACTIVE_OPEN
} else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
/* In the SYN_SENT state, we retransmit out SYN. */
UIP_TCP_BUF->flags = 0;
UIP_TCP_BUF(buf)->flags = 0;
goto tcp_send_syn;
#endif /* UIP_ACTIVE_OPEN */
}
@ -970,8 +984,8 @@ uip_process(uint8_t flag)
} else if(flag == UIP_TIMER) {
/* Reset the length variables. */
#if UIP_TCP
uip_len = 0;
uip_slen = 0;
uip_len(buf) = 0;
uip_slen(buf) = 0;
/* Increase the initial sequence number. */
if(++iss[3] == 0) {
@ -1081,12 +1095,12 @@ uip_process(uint8_t flag)
}
#if UIP_UDP
if(flag == UIP_UDP_TIMER) {
if(uip_udp_conn->lport != 0) {
uip_conn = NULL;
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_len = uip_slen = 0;
uip_flags = UIP_POLL;
UIP_UDP_APPCALL();
if(uip_udp_conn(buf)->lport != 0) {
uip_set_conn(buf) = NULL;
uip_sappdata(buf) = uip_appdata(buf) = &uip_buf(buf)[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_len(buf) = uip_slen(buf) = 0;
uip_flags(buf) = UIP_POLL;
UIP_UDP_APPCALL(buf);
goto udp_send;
} else {
goto drop;
@ -1101,7 +1115,7 @@ uip_process(uint8_t flag)
/* Start of IP input header processing code. */
/* Check validity of the IP header. */
if((UIP_IP_BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */
if((UIP_IP_BUF(buf)->vtc & 0xf0) != 0x60) { /* IP version and header length. */
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.vhlerr);
UIP_LOG("ipv6: invalid version.");
@ -1116,8 +1130,8 @@ uip_process(uint8_t flag)
* value..
*/
if((UIP_IP_BUF->len[0] << 8) + UIP_IP_BUF->len[1] <= uip_len) {
uip_len = (UIP_IP_BUF->len[0] << 8) + UIP_IP_BUF->len[1] + UIP_IPH_LEN;
if((UIP_IP_BUF(buf)->len[0] << 8) + UIP_IP_BUF(buf)->len[1] <= uip_len(buf)) {
uip_len(buf) = (UIP_IP_BUF(buf)->len[0] << 8) + UIP_IP_BUF(buf)->len[1] + UIP_IPH_LEN;
/*
* The length reported in the IPv6 header is the
* length of the payload that follows the
@ -1135,12 +1149,12 @@ uip_process(uint8_t flag)
}
PRINTF("IPv6 packet received from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->srcipaddr);
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINT6ADDR(&UIP_IP_BUF(buf)->destipaddr);
PRINTF("\n");
if(uip_is_addr_mcast(&UIP_IP_BUF->srcipaddr)){
if(uip_is_addr_mcast(&UIP_IP_BUF(buf)->srcipaddr)){
UIP_STAT(++uip_stat.ip.drop);
PRINTF("Dropping packet, src is mcast\n");
goto drop;
@ -1153,7 +1167,7 @@ uip_process(uint8_t flag)
* the packet.
*/
uip_next_hdr = &UIP_IP_BUF->proto;
uip_ext_len = 0;
uip_ext_len(buf) = 0;
uip_ext_bitmap = 0;
if(*uip_next_hdr == UIP_PROTO_HBHO) {
#if UIP_CONF_IPV6_CHECKS
@ -1163,7 +1177,7 @@ uip_process(uint8_t flag)
case 0:
/* continue */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_ext_len(buf) += (UIP_EXT_BUF->len << 3) + 8;
break;
case 1:
PRINTF("Dropping packet after extension header processing\n");
@ -1255,9 +1269,9 @@ uip_process(uint8_t flag)
}
}
#else /* UIP_CONF_ROUTER */
if(!uip_ds6_is_my_addr(&UIP_IP_BUF->destipaddr) &&
!uip_ds6_is_my_maddr(&UIP_IP_BUF->destipaddr) &&
!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
if(!uip_ds6_is_my_addr(&UIP_IP_BUF(buf)->destipaddr) &&
!uip_ds6_is_my_maddr(&UIP_IP_BUF(buf)->destipaddr) &&
!uip_is_addr_mcast(&UIP_IP_BUF(buf)->destipaddr)) {
PRINTF("Dropping packet, not for me\n");
UIP_STAT(++uip_stat.ip.drop);
goto drop;
@ -1267,9 +1281,9 @@ uip_process(uint8_t flag)
* Next header field processing. In IPv6, we can have extension headers,
* they are processed here
*/
uip_next_hdr = &UIP_IP_BUF->proto;
uip_ext_len = 0;
uip_ext_bitmap = 0;
uip_next_hdr(buf) = &UIP_IP_BUF(buf)->proto;
uip_ext_len(buf) = 0;
uip_ext_bitmap(buf) = 0;
#endif /* UIP_CONF_ROUTER */
#if UIP_CONF_IPV6_MULTICAST
@ -1277,7 +1291,7 @@ uip_process(uint8_t flag)
#endif
while(1) {
switch(*uip_next_hdr){
switch(*(uip_next_hdr(buf))){
#if UIP_TCP
case UIP_PROTO_TCP:
/* TCP, for both IPv4 and IPv6 */
@ -1296,17 +1310,17 @@ uip_process(uint8_t flag)
/* Hop by hop option header */
#if UIP_CONF_IPV6_CHECKS
/* Hop by hop option header. If we saw one HBH already, drop */
if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_HBHO) {
if(uip_ext_bitmap(buf) & UIP_EXT_HDR_BITMAP_HBHO) {
goto bad_hdr;
} else {
uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_HBHO;
uip_ext_bitmap(buf) |= UIP_EXT_HDR_BITMAP_HBHO;
}
#endif /*UIP_CONF_IPV6_CHECKS*/
switch(ext_hdr_options_process()) {
switch(ext_hdr_options_process(buf)) {
case 0:
/*continue*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr(buf) = &UIP_EXT_BUF(buf)->next;
uip_ext_len(buf) += (UIP_EXT_BUF(buf)->len << 3) + 8;
break;
case 1:
/*silently discard*/
@ -1321,21 +1335,21 @@ uip_process(uint8_t flag)
#if UIP_CONF_IPV6_CHECKS
/* Destination option header. if we saw two already, drop */
PRINTF("Processing desto header\n");
if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO1) {
if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO2) {
if(uip_ext_bitmap(buf) & UIP_EXT_HDR_BITMAP_DESTO1) {
if(uip_ext_bitmap(buf) & UIP_EXT_HDR_BITMAP_DESTO2) {
goto bad_hdr;
} else{
uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO2;
uip_ext_bitmap(buf) |= UIP_EXT_HDR_BITMAP_DESTO2;
}
} else {
uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO1;
uip_ext_bitmap(buf) |= UIP_EXT_HDR_BITMAP_DESTO1;
}
#endif /*UIP_CONF_IPV6_CHECKS*/
switch(ext_hdr_options_process()) {
switch(ext_hdr_options_process(buf)) {
case 0:
/*continue*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr(buf) = &UIP_EXT_BUF(buf)->next;
uip_ext_len(buf) += (UIP_EXT_BUF(buf)->len << 3) + 8;
break;
case 1:
/*silently discard*/
@ -1349,10 +1363,10 @@ uip_process(uint8_t flag)
case UIP_PROTO_ROUTING:
#if UIP_CONF_IPV6_CHECKS
/* Routing header. If we saw one already, drop */
if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_ROUTING) {
if(uip_ext_bitmap(buf) & UIP_EXT_HDR_BITMAP_ROUTING) {
goto bad_hdr;
} else {
uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_ROUTING;
uip_ext_bitmap(buf) |= UIP_EXT_HDR_BITMAP_ROUTING;
}
#endif /*UIP_CONF_IPV6_CHECKS*/
/*
@ -1364,21 +1378,21 @@ uip_process(uint8_t flag)
*/
PRINTF("Processing Routing header\n");
if(UIP_ROUTING_BUF->seg_left > 0) {
uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, UIP_IPH_LEN + uip_ext_len + 2);
if(UIP_ROUTING_BUF(buf)->seg_left > 0) {
uip_icmp6_error_output(buf, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, UIP_IPH_LEN + uip_ext_len(buf) + 2);
UIP_STAT(++uip_stat.ip.drop);
UIP_LOG("ip6: unrecognized routing type");
goto send;
}
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr(buf) = &UIP_EXT_BUF(buf)->next;
uip_ext_len(buf) += (UIP_EXT_BUF(buf)->len << 3) + 8;
break;
case UIP_PROTO_FRAG:
/* Fragmentation header:call the reassembly function, then leave */
#if UIP_CONF_IPV6_REASSEMBLY
PRINTF("Processing frag header\n");
uip_len = uip_reass();
if(uip_len == 0) {
uip_len(buf) = uip_reass();
if(uip_len(buf) == 0) {
goto drop;
}
if(uip_reassflags & UIP_REASS_FLAG_ERROR_MSG){
@ -1388,9 +1402,9 @@ uip_process(uint8_t flag)
/*packet is reassembled, reset the next hdr to the beginning
of the IP header and restart the parsing of the reassembled pkt*/
PRINTF("Processing reassembled packet\n");
uip_ext_len = 0;
uip_ext_bitmap = 0;
uip_next_hdr = &UIP_IP_BUF->proto;
uip_ext_len(buf) = 0;
uip_ext_bitmap(buf) = 0;
uip_next_hdr(buf) = &UIP_IP_BUF(buf)->proto;
break;
#else /* UIP_CONF_IPV6_REASSEMBLY */
UIP_STAT(++uip_stat.ip.drop);
@ -1409,7 +1423,7 @@ uip_process(uint8_t flag)
* RFC 2460 send error message parameterr problem, code unrecognized
* next header, pointing to the next header field
*/
uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER, (uint32_t)(uip_next_hdr - (uint8_t *)UIP_IP_BUF));
uip_icmp6_error_output(buf, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER, (uint32_t)(uip_next_hdr(buf) - (uint8_t *)UIP_IP_BUF(buf)));
UIP_STAT(++uip_stat.ip.drop);
UIP_STAT(++uip_stat.ip.protoerr);
UIP_LOG("ip6: unrecognized header");
@ -1418,11 +1432,11 @@ uip_process(uint8_t flag)
icmp6_input:
/* This is IPv6 ICMPv6 processing code. */
PRINTF("icmp6_input: length %d type: %d \n", uip_len, UIP_ICMP_BUF->type);
PRINTF("icmp6_input: length %d type: %d \n", uip_len(buf), UIP_ICMP_BUF(buf)->type);
#if UIP_CONF_IPV6_CHECKS
/* Compute and check the ICMP header checksum */
if(uip_icmp6chksum() != 0xffff) {
if(uip_icmp6chksum(buf) != 0xffff) {
UIP_STAT(++uip_stat.icmp.drop);
UIP_STAT(++uip_stat.icmp.chkerr);
UIP_LOG("icmpv6: bad checksum.");
@ -1442,23 +1456,23 @@ uip_process(uint8_t flag)
* we "goto send"
*/
#if UIP_CONF_ICMP6
UIP_ICMP6_APPCALL(UIP_ICMP_BUF->type);
UIP_ICMP6_APPCALL(UIP_ICMP_BUF(buf)->type);
#endif /*UIP_CONF_ICMP6*/
/*
* Search generic input handlers.
* The handler is in charge of setting uip_len to 0
*/
if(uip_icmp6_input(UIP_ICMP_BUF->type,
UIP_ICMP_BUF->icode) == UIP_ICMP6_INPUT_ERROR) {
PRINTF("Unknown ICMPv6 message type/code %d\n", UIP_ICMP_BUF->type);
if(uip_icmp6_input(buf, UIP_ICMP_BUF(buf)->type,
UIP_ICMP_BUF(buf)->icode) == UIP_ICMP6_INPUT_ERROR) {
PRINTF("Unknown ICMPv6 message type/code %d\n", UIP_ICMP_BUF(buf)->type);
UIP_STAT(++uip_stat.icmp.drop);
UIP_STAT(++uip_stat.icmp.typeerr);
UIP_LOG("icmp6: unknown ICMPv6 message.");
uip_len = 0;
uip_len(buf) = 0;
}
if(uip_len > 0) {
if(uip_len(buf) > 0) {
goto send;
} else {
goto drop;
@ -1470,7 +1484,7 @@ uip_process(uint8_t flag)
/* UDP input processing. */
udp_input:
remove_ext_hdr();
remove_ext_hdr(buf);
PRINTF("Receiving UDP packet\n");
@ -1479,34 +1493,34 @@ uip_process(uint8_t flag)
work. If the application sets uip_slen, it has a packet to
send. */
#if UIP_UDP_CHECKSUMS
uip_len = uip_len - UIP_IPUDPH_LEN;
uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_len(buf) = uip_len(buf) - UIP_IPUDPH_LEN;
uip_appdata(buf) = &uip_buf(buf)[UIP_IPUDPH_LEN + UIP_LLH_LEN];
/* XXX hack: UDP/IPv6 receivers should drop packets with UDP
checksum 0. Here, we explicitly receive UDP packets with checksum
0. This is to be able to debug code that for one reason or
another miscomputes UDP checksums. The reception of zero UDP
checksums should be turned into a configration option. */
if(UIP_UDP_BUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
if(UIP_UDP_BUF(buf)->udpchksum != 0 && uip_udpchksum(buf) != 0xffff) {
UIP_STAT(++uip_stat.udp.drop);
UIP_STAT(++uip_stat.udp.chkerr);
PRINTF("udp: bad checksum 0x%04x 0x%04x\n", UIP_UDP_BUF->udpchksum,
uip_udpchksum());
PRINTF("udp: bad checksum 0x%04x 0x%04x\n", UIP_UDP_BUF(buf)->udpchksum,
uip_udpchksum(buf));
goto drop;
}
#else /* UIP_UDP_CHECKSUMS */
uip_len = uip_len - UIP_IPUDPH_LEN;
uip_len(buf) = uip_len(buf) - UIP_IPUDPH_LEN;
#endif /* UIP_UDP_CHECKSUMS */
/* Make sure that the UDP destination port number is not zero. */
if(UIP_UDP_BUF->destport == 0) {
if(UIP_UDP_BUF(buf)->destport == 0) {
PRINTF("udp: zero port.\n");
goto drop;
}
/* Demultiplex this UDP packet between the UDP "connections". */
for(uip_udp_conn = &uip_udp_conns[0];
uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS];
++uip_udp_conn) {
for(uip_set_udp_conn(buf) = &uip_udp_conns[0];
uip_udp_conn(buf) < &uip_udp_conns[UIP_UDP_CONNS];
++uip_set_udp_conn(buf)) {
/* If the local UDP port is non-zero, the connection is considered
to be used. If so, the local port number is checked against the
destination port number in the received packet. If the two port
@ -1514,12 +1528,12 @@ uip_process(uint8_t flag)
connection is bound to a remote port. Finally, if the
connection is bound to a remote IP address, the source IP
address of the packet is checked. */
if(uip_udp_conn->lport != 0 &&
UIP_UDP_BUF->destport == uip_udp_conn->lport &&
(uip_udp_conn->rport == 0 ||
UIP_UDP_BUF->srcport == uip_udp_conn->rport) &&
(uip_is_addr_unspecified(&uip_udp_conn->ripaddr) ||
uip_ipaddr_cmp(&UIP_IP_BUF->srcipaddr, &uip_udp_conn->ripaddr))) {
if(uip_udp_conn(buf)->lport != 0 &&
UIP_UDP_BUF(buf)->destport == uip_udp_conn(buf)->lport &&
(uip_udp_conn(buf)->rport == 0 ||
UIP_UDP_BUF(buf)->srcport == uip_udp_conn(buf)->rport) &&
(uip_is_addr_unspecified(&uip_udp_conn(buf)->ripaddr) ||
uip_ipaddr_cmp(&UIP_IP_BUF(buf)->srcipaddr, &uip_udp_conn(buf)->ripaddr))) {
goto udp_found;
}
}
@ -1527,7 +1541,7 @@ uip_process(uint8_t flag)
UIP_STAT(++uip_stat.udp.drop);
#if UIP_UDP_SEND_UNREACH_NOPORT
uip_icmp6_error_output(ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
uip_icmp6_error_output(buf, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
goto send;
#else
goto drop;
@ -1537,44 +1551,44 @@ uip_process(uint8_t flag)
PRINTF("In udp_found\n");
UIP_STAT(++uip_stat.udp.recv);
uip_conn = NULL;
uip_flags = UIP_NEWDATA;
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_slen = 0;
UIP_UDP_APPCALL();
uip_set_conn(buf) = NULL;
uip_flags(buf) = UIP_NEWDATA;
uip_sappdata(buf) = uip_appdata(buf) = &uip_buf(buf)[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_slen(buf) = 0;
UIP_UDP_APPCALL(buf);
udp_send:
PRINTF("In udp_send\n");
if(uip_slen == 0) {
if(uip_slen(buf) == 0) {
goto drop;
}
uip_len = uip_slen + UIP_IPUDPH_LEN;
uip_len(buf) = uip_slen(buf) + UIP_IPUDPH_LEN;
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
UIP_IP_BUF(buf)->len[0] = ((uip_len(buf) - UIP_IPH_LEN) >> 8);
UIP_IP_BUF(buf)->len[1] = ((uip_len(buf) - UIP_IPH_LEN) & 0xff);
UIP_IP_BUF->ttl = uip_udp_conn->ttl;
UIP_IP_BUF->proto = UIP_PROTO_UDP;
UIP_IP_BUF(buf)->ttl = uip_udp_conn(buf)->ttl;
UIP_IP_BUF(buf)->proto = UIP_PROTO_UDP;
UIP_UDP_BUF->udplen = UIP_HTONS(uip_slen + UIP_UDPH_LEN);
UIP_UDP_BUF->udpchksum = 0;
UIP_UDP_BUF(buf)->udplen = UIP_HTONS(uip_slen(buf) + UIP_UDPH_LEN);
UIP_UDP_BUF(buf)->udpchksum = 0;
UIP_UDP_BUF->srcport = uip_udp_conn->lport;
UIP_UDP_BUF->destport = uip_udp_conn->rport;
UIP_UDP_BUF(buf)->srcport = uip_udp_conn(buf)->lport;
UIP_UDP_BUF(buf)->destport = uip_udp_conn(buf)->rport;
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &uip_udp_conn->ripaddr);
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
uip_ipaddr_copy(&UIP_IP_BUF(buf)->destipaddr, &uip_udp_conn(buf)->ripaddr);
uip_ds6_select_src(&UIP_IP_BUF(buf)->srcipaddr, &UIP_IP_BUF(buf)->destipaddr);
uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
uip_appdata(buf) = &uip_buf(buf)[UIP_LLH_LEN + UIP_IPTCPH_LEN];
#if UIP_UDP_CHECKSUMS
/* Calculate UDP checksum. */
UIP_UDP_BUF->udpchksum = ~(uip_udpchksum());
if(UIP_UDP_BUF->udpchksum == 0) {
UIP_UDP_BUF->udpchksum = 0xffff;
UIP_UDP_BUF(buf)->udpchksum = ~(uip_udpchksum(buf));
if(UIP_UDP_BUF(buf)->udpchksum == 0) {
UIP_UDP_BUF(buf)->udpchksum = 0xffff;
}
#endif /* UIP_UDP_CHECKSUMS */
@ -2296,23 +2310,23 @@ uip_process(uint8_t flag)
#if UIP_UDP
ip_send_nolen:
#endif
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0x00;
UIP_IP_BUF->flow = 0x00;
UIP_IP_BUF(buf)->vtc = 0x60;
UIP_IP_BUF(buf)->tcflow = 0x00;
UIP_IP_BUF(buf)->flow = 0x00;
send:
PRINTF("Sending packet with length %d (%d)\n", uip_len,
(UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]);
PRINTF("Sending packet with length %d (%d)\n", uip_len(buf),
(UIP_IP_BUF(buf)->len[0] << 8) | UIP_IP_BUF(buf)->len[1]);
UIP_STAT(++uip_stat.ip.sent);
/* Return and let the caller do the actual transmission. */
uip_flags = 0;
uip_flags(buf) = 0;
return;
drop:
uip_len = 0;
uip_ext_len = 0;
uip_ext_bitmap = 0;
uip_flags = 0;
uip_len(buf) = 0;
uip_ext_len(buf) = 0;
uip_ext_bitmap(buf) = 0;
uip_flags(buf) = 0;
return;
}
/*---------------------------------------------------------------------------*/
@ -2328,8 +2342,9 @@ uip_htonl(uint32_t val)
return UIP_HTONL(val);
}
/*---------------------------------------------------------------------------*/
#if UIP_TCP
void
uip_send(const void *data, int len)
uip_send(struct net_buf *buf, const void *data, int len)
{
int copylen;
#define MIN(a,b) ((a) < (b)? (a): (b))
@ -2353,5 +2368,6 @@ uip_send(const void *data, int len)
}
}
}
#endif /* UIP_TCP */
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -51,43 +51,43 @@ static uint32_t counter;
/*---------------------------------------------------------------------------*/
void
anti_replay_set_counter(void)
anti_replay_set_counter(struct net_buf *buf)
{
frame802154_frame_counter_t reordered_counter;
reordered_counter.u32 = LLSEC802154_HTONL(++counter);
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, reordered_counter.u16[0]);
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, reordered_counter.u16[1]);
packetbuf_set_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, reordered_counter.u16[0]);
packetbuf_set_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, reordered_counter.u16[1]);
}
/*---------------------------------------------------------------------------*/
uint32_t
anti_replay_get_counter(void)
anti_replay_get_counter(struct net_buf *buf)
{
frame802154_frame_counter_t disordered_counter;
disordered_counter.u16[0] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1);
disordered_counter.u16[1] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3);
disordered_counter.u16[0] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1);
disordered_counter.u16[1] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3);
return LLSEC802154_HTONL(disordered_counter.u32);
}
/*---------------------------------------------------------------------------*/
void
anti_replay_init_info(struct anti_replay_info *info)
anti_replay_init_info(struct net_buf *buf, struct anti_replay_info *info)
{
info->last_broadcast_counter
= info->last_unicast_counter
= anti_replay_get_counter();
= anti_replay_get_counter(buf);
}
/*---------------------------------------------------------------------------*/
int
anti_replay_was_replayed(struct anti_replay_info *info)
anti_replay_was_replayed(struct net_buf *buf, struct anti_replay_info *info)
{
uint32_t received_counter;
received_counter = anti_replay_get_counter();
received_counter = anti_replay_get_counter(buf);
if(packetbuf_holds_broadcast()) {
if(packetbuf_holds_broadcast(buf)) {
/* broadcast */
if(received_counter <= info->last_broadcast_counter) {
return 1;

View file

@ -55,25 +55,25 @@ struct anti_replay_info {
/**
* \brief Sets the frame counter packetbuf attributes.
*/
void anti_replay_set_counter(void);
void anti_replay_set_counter(struct net_buf *buf);
/**
* \brief Gets the frame counter from packetbuf.
*/
uint32_t anti_replay_get_counter(void);
uint32_t anti_replay_get_counter(struct net_buf *buf);
/**
* \brief Initializes the anti-replay information about the sender
* \param info Anti-replay information about the sender
*/
void anti_replay_init_info(struct anti_replay_info *info);
void anti_replay_init_info(struct net_buf *buf, struct anti_replay_info *info);
/**
* \brief Checks if received frame was replayed
* \param info Anti-replay information about the sender
* \retval 0 <-> received frame was not replayed
*/
int anti_replay_was_replayed(struct anti_replay_info *info);
int anti_replay_was_replayed(struct net_buf *buf, struct anti_replay_info *info);
#endif /* ANTI_REPLAY_H */

View file

@ -50,7 +50,7 @@
/*---------------------------------------------------------------------------*/
static void
set_nonce(uint8_t *nonce,
set_nonce(struct net_buf *buf, uint8_t *nonce,
uint8_t flags,
const uint8_t *extended_source_address,
uint8_t counter)
@ -60,18 +60,18 @@ set_nonce(uint8_t *nonce,
nonce[0] = flags;
memcpy(nonce + 1, extended_source_address, 8);
nonce[9] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3) >> 8;
nonce[10] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3) & 0xff;
nonce[11] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1) >> 8;
nonce[12] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1) & 0xff;
nonce[13] = packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL);
nonce[9] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3) >> 8;
nonce[10] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3) & 0xff;
nonce[11] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1) >> 8;
nonce[12] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1) & 0xff;
nonce[13] = packetbuf_attr(buf, PACKETBUF_ATTR_SECURITY_LEVEL);
nonce[14] = 0;
nonce[15] = counter;
}
/*---------------------------------------------------------------------------*/
/* XORs the block m[pos] ... m[pos + 15] with K_{counter} */
static void
ctr_step(const uint8_t *extended_source_address,
ctr_step(struct net_buf *buf, const uint8_t *extended_source_address,
uint8_t pos,
uint8_t *m_and_result,
uint8_t m_len,
@ -80,7 +80,7 @@ ctr_step(const uint8_t *extended_source_address,
uint8_t a[AES_128_BLOCK_SIZE];
uint8_t i;
set_nonce(a, CCM_STAR_ENCRYPTION_FLAGS, extended_source_address, counter);
set_nonce(buf, a, CCM_STAR_ENCRYPTION_FLAGS, extended_source_address, counter);
AES_128.encrypt(a);
for(i = 0; (pos + i < m_len) && (i < AES_128_BLOCK_SIZE); i++) {
@ -89,7 +89,7 @@ ctr_step(const uint8_t *extended_source_address,
}
/*---------------------------------------------------------------------------*/
static void
mic(const uint8_t *extended_source_address,
mic(struct net_buf *buf, const uint8_t *extended_source_address,
uint8_t *result,
uint8_t mic_len)
{
@ -103,7 +103,7 @@ mic(const uint8_t *extended_source_address,
uint8_t m_len;
uint8_t *m;
shall_encrypt = packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & (1 << 2);
shall_encrypt = packetbuf_attr(buf, PACKETBUF_ATTR_SECURITY_LEVEL) & (1 << 2);
if(shall_encrypt) {
a_len = packetbuf_hdrlen();
m_len = packetbuf_datalen();
@ -116,15 +116,15 @@ mic(const uint8_t *extended_source_address,
extended_source_address,
m_len);
#else /* LLSEC802154_USES_ENCRYPTION */
a_len = packetbuf_totlen();
set_nonce(x,
a_len = packetbuf_totlen(buf);
set_nonce(buf, x,
CCM_STAR_AUTH_FLAGS(a_len, mic_len),
extended_source_address,
0);
#endif /* LLSEC802154_USES_ENCRYPTION */
AES_128.encrypt(x);
a = packetbuf_hdrptr();
a = packetbuf_hdrptr(buf);
if(a_len) {
x[1] = x[1] ^ a_len;
for(i = 2; (i - 2 < a_len) && (i < AES_128_BLOCK_SIZE); i++) {
@ -157,26 +157,26 @@ mic(const uint8_t *extended_source_address,
}
#endif /* LLSEC802154_USES_ENCRYPTION */
ctr_step(extended_source_address, 0, x, AES_128_BLOCK_SIZE, 0);
ctr_step(buf, extended_source_address, 0, x, AES_128_BLOCK_SIZE, 0);
memcpy(result, x, mic_len);
}
/*---------------------------------------------------------------------------*/
static void
ctr(const uint8_t *extended_source_address)
ctr(struct net_buf *buf, const uint8_t *extended_source_address)
{
uint8_t m_len;
uint8_t *m;
uint8_t pos;
uint8_t counter;
m_len = packetbuf_datalen();
m = (uint8_t *) packetbuf_dataptr();
m_len = packetbuf_datalen(buf);
m = (uint8_t *) packetbuf_dataptr(buf);
pos = 0;
counter = 1;
while(pos < m_len) {
ctr_step(extended_source_address, pos, m, m_len, counter++);
ctr_step(buf, extended_source_address, pos, m, m_len, counter++);
pos += AES_128_BLOCK_SIZE;
}
}

View file

@ -68,14 +68,14 @@ struct ccm_star_driver {
* \param result The generated MIC will be put here
* \param mic_len <= 16; set to LLSEC802154_MIC_LENGTH to be compliant
*/
void (* mic)(const uint8_t *extended_source_address,
void (* mic)(struct net_buf *buf, const uint8_t *extended_source_address,
uint8_t *result,
uint8_t mic_len);
/**
* \brief XORs the frame in the packetbuf with the key stream.
*/
void (* ctr)(const uint8_t *extended_source_address);
void (* ctr)(struct net_buf *buf, const uint8_t *extended_source_address);
};
extern const struct ccm_star_driver CCM_STAR;

View file

@ -55,11 +55,11 @@
* @{
*/
#include "net/mac/mac.h"
#ifndef LLSEC_H_
#define LLSEC_H_
#include "net/mac/mac.h"
typedef void (* llsec_on_bootstrapped_t)(void);
/**
@ -72,7 +72,7 @@ struct llsec_driver {
void (* bootstrap)(llsec_on_bootstrapped_t on_bootstrapped);
/** Secures outgoing frames before passing them to NETSTACK_MAC. */
void (* send)(mac_callback_t sent_callback, void *ptr);
void (* send)(struct net_buf *buf, mac_callback_t sent_callback, void *ptr);
/**
* Once the NETSTACK_FRAMER wrote the headers, the LLSEC driver
@ -85,7 +85,7 @@ struct llsec_driver {
* Decrypts incoming frames;
* filters out injected or replayed frames.
*/
void (* input)(void);
void (* input)(struct net_buf *buf);
/** Returns the security-related overhead per frame in bytes */
uint8_t (* get_overhead)(void);

View file

@ -42,6 +42,8 @@
* @{
*/
#include <net/net_buf.h>
#include "net/llsec/nullsec.h"
#include "net/mac/frame802154.h"
#include "net/netstack.h"
@ -55,10 +57,10 @@ bootstrap(llsec_on_bootstrapped_t on_bootstrapped)
}
/*---------------------------------------------------------------------------*/
static void
send(mac_callback_t sent, void *ptr)
send(struct net_buf *buf, mac_callback_t sent, void *ptr)
{
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
NETSTACK_MAC.send(sent, ptr);
packetbuf_set_attr(buf, PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
NETSTACK_MAC.send(buf, sent, ptr);
}
/*---------------------------------------------------------------------------*/
static int
@ -68,9 +70,9 @@ on_frame_created(void)
}
/*---------------------------------------------------------------------------*/
static void
input(void)
input(struct net_buf *buf)
{
NETSTACK_NETWORK.input();
NETSTACK_NETWORK.input(buf);
}
/*---------------------------------------------------------------------------*/
static uint8_t

View file

@ -37,6 +37,8 @@
* Adam Dunkels <adam@sics.se>
*/
#include <net/net_buf.h>
#include "net/mac/csma.h"
#include "net/packetbuf.h"
#include "net/queuebuf.h"
@ -55,6 +57,14 @@
#include <stdio.h>
#if UIP_LOGGING
#include <stdio.h>
void uip_log(char *msg);
#define UIP_LOG(m) uip_log(m)
#else
#define UIP_LOG(m)
#endif
#define DEBUG 0
#if DEBUG
#include <stdio.h>
@ -121,8 +131,8 @@ MEMB(packet_memb, struct rdc_buf_list, MAX_QUEUED_PACKETS);
MEMB(metadata_memb, struct qbuf_metadata, MAX_QUEUED_PACKETS);
LIST(neighbor_list);
static void packet_sent(void *ptr, int status, int num_transmissions);
static void transmit_packet_list(void *ptr);
static void packet_sent(struct net_buf *buf, void *ptr, int status, int num_transmissions);
static void transmit_packet_list(struct net_buf *buf, void *ptr);
/*---------------------------------------------------------------------------*/
static struct neighbor_queue *
@ -156,7 +166,7 @@ default_timebase(void)
}
/*---------------------------------------------------------------------------*/
static void
transmit_packet_list(void *ptr)
transmit_packet_list(struct net_buf *buf, void *ptr)
{
struct neighbor_queue *n = ptr;
if(n) {
@ -165,13 +175,13 @@ transmit_packet_list(void *ptr)
PRINTF("csma: preparing number %d %p, queue len %d\n", n->transmissions, q,
list_length(n->queued_packet_list));
/* Send packets in the neighbor's list */
NETSTACK_RDC.send_list(packet_sent, n, q);
NETSTACK_RDC.send_list(buf, packet_sent, n, q);
}
}
}
/*---------------------------------------------------------------------------*/
static void
free_packet(struct neighbor_queue *n, struct rdc_buf_list *p)
free_packet(struct net_buf *buf, struct neighbor_queue *n, struct rdc_buf_list *p)
{
if(p != NULL) {
/* Remove packet from list and deallocate */
@ -188,7 +198,7 @@ free_packet(struct neighbor_queue *n, struct rdc_buf_list *p)
n->collisions = 0;
n->deferrals = 0;
/* Set a timer for next transmissions */
ctimer_set(&n->transmit_timer, default_timebase(),
ctimer_set(buf, &n->transmit_timer, default_timebase(),
transmit_packet_list, n);
} else {
/* This was the last packet in the queue, we free the neighbor */
@ -200,7 +210,7 @@ free_packet(struct neighbor_queue *n, struct rdc_buf_list *p)
}
/*---------------------------------------------------------------------------*/
static void
packet_sent(void *ptr, int status, int num_transmissions)
packet_sent(struct net_buf *buf, void *ptr, int status, int num_transmissions)
{
struct neighbor_queue *n;
struct rdc_buf_list *q;
@ -233,7 +243,7 @@ packet_sent(void *ptr, int status, int num_transmissions)
for(q = list_head(n->queued_packet_list);
q != NULL; q = list_item_next(q)) {
if(queuebuf_attr(q->buf, PACKETBUF_ATTR_MAC_SEQNO) ==
packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)) {
packetbuf_attr(buf, PACKETBUF_ATTR_MAC_SEQNO)) {
break;
}
}
@ -285,16 +295,16 @@ packet_sent(void *ptr, int status, int num_transmissions)
if(n->transmissions < metadata->max_transmissions) {
PRINTF("csma: retransmitting with time %lu %p\n", time, q);
ctimer_set(&n->transmit_timer, time,
ctimer_set(buf, &n->transmit_timer, time,
transmit_packet_list, n);
/* This is needed to correctly attribute energy that we spent
transmitting this packet. */
queuebuf_update_attr_from_packetbuf(q->buf);
queuebuf_update_attr_from_packetbuf(buf, q->buf);
} else {
PRINTF("csma: drop with status %d after %d transmissions, %d collisions\n",
status, n->transmissions, n->collisions);
free_packet(n, q);
mac_call_sent_callback(sent, cptr, status, num_tx);
free_packet(buf, n, q);
mac_call_sent_callback(buf, sent, cptr, status, num_tx);
}
} else {
if(status == MAC_TX_OK) {
@ -302,25 +312,30 @@ packet_sent(void *ptr, int status, int num_transmissions)
} else {
PRINTF("csma: rexmit failed %d: %d\n", n->transmissions, status);
}
free_packet(n, q);
mac_call_sent_callback(sent, cptr, status, num_tx);
free_packet(buf, n, q);
mac_call_sent_callback(buf, sent, cptr, status, num_tx);
}
} else {
PRINTF("csma: no metadata\n");
}
} else {
PRINTF("csma: seqno %d not found\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
PRINTF("csma: seqno %d not found\n", packetbuf_attr(buf, PACKETBUF_ATTR_MAC_SEQNO));
}
}
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
send_packet(struct net_buf *buf, mac_callback_t sent, void *ptr)
{
struct rdc_buf_list *q;
struct neighbor_queue *n;
static uint8_t initialized = 0;
static uint16_t seqno;
const linkaddr_t *addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
const linkaddr_t *addr = packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER);
if (!buf) {
UIP_LOG("csma: send_packet(): net_buf is NULL, cannot send packet");
return;
}
if(!initialized) {
initialized = 1;
@ -333,7 +348,7 @@ send_packet(mac_callback_t sent, void *ptr)
in framer-802154.c. */
seqno++;
}
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
packetbuf_set_attr(buf, PACKETBUF_ATTR_MAC_SEQNO, seqno++);
/* Look for the neighbor entry */
n = neighbor_queue_from_addr(addr);
@ -360,21 +375,21 @@ send_packet(mac_callback_t sent, void *ptr)
if(q != NULL) {
q->ptr = memb_alloc(&metadata_memb);
if(q->ptr != NULL) {
q->buf = queuebuf_new_from_packetbuf();
q->buf = queuebuf_new_from_packetbuf(buf);
if(q->buf != NULL) {
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
/* Neighbor and packet successfully allocated */
if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
if(packetbuf_attr(buf, PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
/* Use default configuration for max transmissions */
metadata->max_transmissions = CSMA_MAX_MAC_TRANSMISSIONS;
} else {
metadata->max_transmissions =
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
packetbuf_attr(buf, PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
}
metadata->sent = sent;
metadata->cptr = ptr;
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
if(packetbuf_attr(buf, PACKETBUF_ATTR_PACKET_TYPE) ==
PACKETBUF_ATTR_PACKET_TYPE_ACK) {
list_push(n->queued_packet_list, q);
} else {
@ -385,7 +400,7 @@ send_packet(mac_callback_t sent, void *ptr)
list_length(n->queued_packet_list), memb_numfree(&packet_memb));
/* If q is the first packet in the neighbor's queue, send asap */
if(list_head(n->queued_packet_list) == q) {
ctimer_set(&n->transmit_timer, 0, transmit_packet_list, n);
ctimer_set(buf, &n->transmit_timer, 0, transmit_packet_list, n);
}
return;
}
@ -407,13 +422,13 @@ send_packet(mac_callback_t sent, void *ptr)
} else {
PRINTF("csma: could not allocate neighbor, dropping packet\n");
}
mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1);
mac_call_sent_callback(buf, sent, ptr, MAC_TX_ERR, 1);
}
/*---------------------------------------------------------------------------*/
static void
input_packet(void)
input_packet(struct net_buf *buf)
{
NETSTACK_LLSEC.input();
NETSTACK_LLSEC.input(buf);
}
/*---------------------------------------------------------------------------*/
static int

View file

@ -88,7 +88,7 @@ is_broadcast_addr(uint8_t mode, uint8_t *addr)
}
/*---------------------------------------------------------------------------*/
static int
create_frame(int type, int do_create)
create_frame(struct net_buf *buf, int type, int do_create)
{
frame802154_t params;
int hdr_len;
@ -102,12 +102,12 @@ create_frame(int type, int do_create)
}
/* Build the FCF. */
params.fcf.frame_type = packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE);
params.fcf.frame_pending = packetbuf_attr(PACKETBUF_ATTR_PENDING);
if(packetbuf_holds_broadcast()) {
params.fcf.frame_type = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_TYPE);
params.fcf.frame_pending = packetbuf_attr(buf, PACKETBUF_ATTR_PENDING);
if(packetbuf_holds_broadcast(buf)) {
params.fcf.ack_required = 0;
} else {
params.fcf.ack_required = packetbuf_attr(PACKETBUF_ATTR_MAC_ACK);
params.fcf.ack_required = packetbuf_attr(buf, PACKETBUF_ATTR_MAC_ACK);
}
params.fcf.panid_compression = 0;
@ -115,17 +115,17 @@ create_frame(int type, int do_create)
params.fcf.frame_version = FRAME802154_IEEE802154_2006;
#if LLSEC802154_SECURITY_LEVEL
if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL)) {
if(packetbuf_attr(buf, PACKETBUF_ATTR_SECURITY_LEVEL)) {
params.fcf.security_enabled = 1;
}
/* Setting security-related attributes */
params.aux_hdr.security_control.security_level = packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL);
params.aux_hdr.frame_counter.u16[0] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1);
params.aux_hdr.frame_counter.u16[1] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3);
params.aux_hdr.security_control.security_level = packetbuf_attr(buf, PACKETBUF_ATTR_SECURITY_LEVEL);
params.aux_hdr.frame_counter.u16[0] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1);
params.aux_hdr.frame_counter.u16[1] = packetbuf_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3);
#if LLSEC802154_USES_EXPLICIT_KEYS
params.aux_hdr.security_control.key_id_mode = packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE);
params.aux_hdr.key_index = packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX);
params.aux_hdr.key_source.u16[0] = packetbuf_attr(PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1);
params.aux_hdr.security_control.key_id_mode = packetbuf_attr(buf, PACKETBUF_ATTR_KEY_ID_MODE);
params.aux_hdr.key_index = packetbuf_attr(buf, PACKETBUF_ATTR_KEY_INDEX);
params.aux_hdr.key_source.u16[0] = packetbuf_attr(buf, PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1);
#endif /* LLSEC802154_USES_EXPLICIT_KEYS */
#endif /* LLSEC802154_SECURITY_LEVEL */
@ -134,8 +134,8 @@ create_frame(int type, int do_create)
/* Only length calculation - no sequence number is needed and
should not be consumed. */
} else if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)) {
params.seq = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO);
} else if(packetbuf_attr(buf, PACKETBUF_ATTR_MAC_SEQNO)) {
params.seq = packetbuf_attr(buf, PACKETBUF_ATTR_MAC_SEQNO);
} else {
/* Ensure that the sequence number 0 is not used as it would bypass the above check. */
@ -143,7 +143,7 @@ create_frame(int type, int do_create)
mac_dsn++;
}
params.seq = mac_dsn++;
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, params.seq);
packetbuf_set_attr(buf, PACKETBUF_ATTR_MAC_SEQNO, params.seq);
}
/* Complete the addressing fields. */
@ -159,7 +159,7 @@ create_frame(int type, int do_create)
}
params.dest_pid = mac_dst_pan_id;
if(packetbuf_holds_broadcast()) {
if(packetbuf_holds_broadcast(buf)) {
/* Broadcast requires short address mode. */
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
params.dest_addr[0] = 0xFF;
@ -167,7 +167,7 @@ create_frame(int type, int do_create)
} else {
linkaddr_copy((linkaddr_t *)&params.dest_addr,
packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER));
/* Use short address mode if linkaddr size is small */
if(LINKADDR_SIZE == 2) {
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
@ -185,19 +185,19 @@ create_frame(int type, int do_create)
*/
linkaddr_copy((linkaddr_t *)&params.src_addr, &linkaddr_node_addr);
params.payload = packetbuf_dataptr();
params.payload_len = packetbuf_datalen();
params.payload = packetbuf_dataptr(buf);
params.payload_len = packetbuf_datalen(buf);
hdr_len = frame802154_hdrlen(&params);
if(!do_create) {
/* Only calculate header length */
return hdr_len;
} else if(packetbuf_hdralloc(hdr_len)) {
frame802154_create(&params, packetbuf_hdrptr());
} else if(packetbuf_hdralloc(buf, hdr_len)) {
frame802154_create(&params, packetbuf_hdrptr(buf));
PRINTF("15.4-OUT: %2X", params.fcf.frame_type);
PRINTADDR(params.dest_addr);
PRINTF("%d %u (%u)\n", hdr_len, packetbuf_datalen(), packetbuf_totlen());
PRINTF("%d %u (%u)\n", hdr_len, packetbuf_datalen(buf), packetbuf_totlen(buf));
return hdr_len;
} else {
@ -207,27 +207,27 @@ create_frame(int type, int do_create)
}
/*---------------------------------------------------------------------------*/
static int
hdr_length(void)
hdr_length(struct net_buf *buf)
{
return create_frame(FRAME802154_DATAFRAME, 0);
return create_frame(buf, FRAME802154_DATAFRAME, 0);
}
/*---------------------------------------------------------------------------*/
static int
create(void)
create(struct net_buf *buf)
{
return create_frame(FRAME802154_DATAFRAME, 1);
return create_frame(buf, FRAME802154_DATAFRAME, 1);
}
/*---------------------------------------------------------------------------*/
static int
parse(void)
parse(struct net_buf *buf)
{
frame802154_t frame;
int hdr_len;
hdr_len = frame802154_parse(packetbuf_dataptr(), packetbuf_datalen(), &frame);
hdr_len = frame802154_parse(packetbuf_dataptr(buf), packetbuf_datalen(buf), &frame);
if(hdr_len && packetbuf_hdrreduce(hdr_len)) {
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, frame.fcf.frame_type);
if(hdr_len && packetbuf_hdrreduce(buf, hdr_len)) {
packetbuf_set_attr(buf, PACKETBUF_ATTR_FRAME_TYPE, frame.fcf.frame_type);
if(frame.fcf.dest_addr_mode) {
if(frame.dest_pid != mac_src_pan_id &&
@ -237,31 +237,31 @@ parse(void)
return FRAMER_FAILED;
}
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
packetbuf_set_addr(buf, PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
}
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending);
packetbuf_set_addr(buf, PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(buf, PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending);
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
packetbuf_set_attr(buf, PACKETBUF_ATTR_PACKET_ID, frame.seq);
#if LLSEC802154_SECURITY_LEVEL
if(frame.fcf.security_enabled) {
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, frame.aux_hdr.security_control.security_level);
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, frame.aux_hdr.frame_counter.u16[0]);
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, frame.aux_hdr.frame_counter.u16[1]);
packetbuf_set_attr(buf, PACKETBUF_ATTR_SECURITY_LEVEL, frame.aux_hdr.security_control.security_level);
packetbuf_set_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, frame.aux_hdr.frame_counter.u16[0]);
packetbuf_set_attr(buf, PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, frame.aux_hdr.frame_counter.u16[1]);
#if LLSEC802154_USES_EXPLICIT_KEYS
packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, frame.aux_hdr.security_control.key_id_mode);
packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, frame.aux_hdr.key_index);
packetbuf_set_attr(PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1, frame.aux_hdr.key_source.u16[0]);
packetbuf_set_attr(buf, PACKETBUF_ATTR_KEY_ID_MODE, frame.aux_hdr.security_control.key_id_mode);
packetbuf_set_attr(buf, PACKETBUF_ATTR_KEY_INDEX, frame.aux_hdr.key_index);
packetbuf_set_attr(buf, PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1, frame.aux_hdr.key_source.u16[0]);
#endif /* LLSEC802154_USES_EXPLICIT_KEYS */
}
#endif /* LLSEC802154_SECURITY_LEVEL */
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
PRINTF("%d %u (%u)\n", hdr_len, packetbuf_datalen(), packetbuf_totlen());
PRINTADDR(packetbuf_addr(buf, PACKETBUF_ADDR_SENDER));
PRINTADDR(packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER));
PRINTF("%d %u (%u)\n", hdr_len, packetbuf_datalen(buf), packetbuf_totlen(buf));
return hdr_len;
}

View file

@ -34,13 +34,13 @@
/*---------------------------------------------------------------------------*/
int
framer_canonical_create_and_secure(void)
framer_canonical_create_and_secure(struct net_buf *buf)
{
int hdr_len;
hdr_len = NETSTACK_FRAMER.create();
hdr_len = NETSTACK_FRAMER.create(buf);
if(hdr_len >= 0) {
packetbuf_compact();
packetbuf_compact(buf);
if(!NETSTACK_LLSEC.on_frame_created()) {
return FRAMER_FAILED;
}

View file

@ -38,6 +38,8 @@
* Joakim Eriksson <joakime@sics.se>
*/
#include <net/net_buf.h>
#ifndef FRAMER_H_
#define FRAMER_H_
@ -46,14 +48,14 @@
struct framer {
int (* length)(void);
int (* create)(void);
int (* create)(struct net_buf *buf);
/** Creates the frame and calls LLSEC.on_frame_created() */
int (* create_and_secure)(void);
int (* parse)(void);
int (* parse)(struct net_buf *buf);
};
int framer_canonical_create_and_secure(void);
int framer_canonical_create_and_secure(struct net_buf *buf);
#endif /* FRAMER_H_ */

View file

@ -47,7 +47,6 @@
#include "contiki-net.h"
#include "net/mac/mac-sequence.h"
#include "net/packetbuf.h"
#include "net/rime/rime.h"
struct seqno {
linkaddr_t sender;
@ -63,7 +62,7 @@ static struct seqno received_seqnos[MAX_SEQNOS];
/*---------------------------------------------------------------------------*/
int
mac_sequence_is_duplicate(void)
mac_sequence_is_duplicate(struct net_buf *buf)
{
int i;
@ -72,9 +71,9 @@ mac_sequence_is_duplicate(void)
* packet with the last few ones we saw.
*/
for(i = 0; i < MAX_SEQNOS; ++i) {
if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER),
if(linkaddr_cmp(packetbuf_addr(buf, PACKETBUF_ADDR_SENDER),
&received_seqnos[i].sender)) {
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno) {
if(packetbuf_attr(buf, PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno) {
/* Duplicate packet. */
return 1;
}
@ -85,13 +84,13 @@ mac_sequence_is_duplicate(void)
}
/*---------------------------------------------------------------------------*/
void
mac_sequence_register_seqno(void)
mac_sequence_register_seqno(struct net_buf *buf)
{
int i, j;
/* Locate possible previous sequence number for this address. */
for(i = 0; i < MAX_SEQNOS; ++i) {
if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER),
if(linkaddr_cmp(packetbuf_addr(buf, PACKETBUF_ADDR_SENDER),
&received_seqnos[i].sender)) {
i++;
break;
@ -102,8 +101,8 @@ mac_sequence_register_seqno(void)
for(j = i - 1; j > 0; --j) {
memcpy(&received_seqnos[j], &received_seqnos[j - 1], sizeof(struct seqno));
}
received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
received_seqnos[0].seqno = packetbuf_attr(buf, PACKETBUF_ATTR_PACKET_ID);
linkaddr_copy(&received_seqnos[0].sender,
packetbuf_addr(PACKETBUF_ADDR_SENDER));
packetbuf_addr(buf, PACKETBUF_ADDR_SENDER));
}
/*---------------------------------------------------------------------------*/

View file

@ -53,7 +53,7 @@
* the sequence number of the incoming packet with the last few ones
* we saw, filtering with the Rime address.
*/
int mac_sequence_is_duplicate(void);
int mac_sequence_is_duplicate(struct net_buf *buf);
/**
* \brief Register the sequence number of the packetbuf
@ -61,6 +61,6 @@ int mac_sequence_is_duplicate(void);
* This function is used to add the sequence number of the incoming
* packet to the history.
*/
void mac_sequence_register_seqno(void);
void mac_sequence_register_seqno(struct net_buf *buf);
#endif /* MAC_SEQUENCE_H */

View file

@ -31,6 +31,7 @@
*/
#include "net/mac/mac.h"
#include "net/net_buf.h"
#define DEBUG 0
#if DEBUG
@ -42,7 +43,7 @@
/*---------------------------------------------------------------------------*/
void
mac_call_sent_callback(mac_callback_t sent, void *ptr, int status, int num_tx)
mac_call_sent_callback(struct net_buf *buf, mac_callback_t sent, void *ptr, int status, int num_tx)
{
PRINTF("mac_callback_t %p ptr %p status %d num_tx %d\n",
(void *)sent, ptr, status, num_tx);
@ -61,7 +62,7 @@ mac_call_sent_callback(mac_callback_t sent, void *ptr, int status, int num_tx)
}
if(sent) {
sent(ptr, status, num_tx);
sent(buf, ptr, status, num_tx);
}
}
/*---------------------------------------------------------------------------*/

View file

@ -43,10 +43,12 @@
#include "contiki-conf.h"
#include "dev/radio.h"
#include <net/net_buf.h>
typedef void (* mac_callback_t)(void *ptr, int status, int transmissions);
void mac_call_sent_callback(mac_callback_t sent, void *ptr, int status, int num_tx);
typedef void (* mac_callback_t)(struct net_buf *buf, void *ptr, int status, int transmissions);
void mac_call_sent_callback(struct net_buf *buf, mac_callback_t sent, void *ptr, int status, int num_tx);
/**
* The structure of a MAC protocol driver in Contiki.
@ -58,10 +60,10 @@ struct mac_driver {
void (* init)(void);
/** Send a packet from the Rime buffer */
void (* send)(mac_callback_t sent_callback, void *ptr);
void (* send)(struct net_buf *buf, mac_callback_t sent_callback, void *ptr);
/** Callback for getting notified of incoming packet. */
void (* input)(void);
void (* input)(struct net_buf *buf);
/** Turn the MAC layer on. */
int (* on)(void);

View file

@ -41,6 +41,8 @@
#ifndef RDC_H_
#define RDC_H_
#include <net/net_buf.h>
#include "contiki-conf.h"
#include "net/mac/mac.h"
@ -71,13 +73,13 @@ struct rdc_driver {
void (* init)(void);
/** Send a packet from the Rime buffer */
void (* send)(mac_callback_t sent_callback, void *ptr);
void (* send)(struct net_buf *buf, mac_callback_t sent_callback, void *ptr);
/** Send a packet list */
void (* send_list)(mac_callback_t sent_callback, void *ptr, struct rdc_buf_list *list);
void (* send_list)(struct net_buf *buf, mac_callback_t sent_callback, void *ptr, struct rdc_buf_list *list);
/** Callback for getting notified of incoming packet. */
void (* input)(void);
void (* input)(struct net_buf *buf);
/** Turn the MAC layer on. */
int (* on)(void);

View file

@ -44,6 +44,9 @@
*/
#include <string.h>
struct net_buf;
#include "net/mac/sicslowmac/sicslowmac.h"
#include "net/mac/frame802154.h"
#include "net/packetbuf.h"
@ -94,7 +97,7 @@ is_broadcast_addr(uint8_t mode, uint8_t *addr)
}
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
send_packet(struct net_buf *buf, mac_callback_t sent, void *ptr)
{
frame802154_t params;
uint8_t len;
@ -106,7 +109,7 @@ send_packet(mac_callback_t sent, void *ptr)
params.fcf.frame_type = FRAME802154_DATAFRAME;
params.fcf.security_enabled = 0;
params.fcf.frame_pending = 0;
params.fcf.ack_required = packetbuf_attr(PACKETBUF_ATTR_RELIABLE);
params.fcf.ack_required = packetbuf_attr(buf, PACKETBUF_ATTR_RELIABLE);
params.fcf.panid_compression = 0;
/* Insert IEEE 802.15.4 (2003) version bit. */
@ -123,7 +126,7 @@ send_packet(mac_callback_t sent, void *ptr)
params.fcf.src_addr_mode = FRAME802154_LONGADDRMODE;
params.dest_pid = mac_dst_pan_id;
if(packetbuf_holds_broadcast()) {
if(packetbuf_holds_broadcast(buf)) {
/* Broadcast requires short address mode. */
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
params.dest_addr[0] = 0xFF;
@ -131,7 +134,7 @@ send_packet(mac_callback_t sent, void *ptr)
} else {
linkaddr_copy((linkaddr_t *)&params.dest_addr,
packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER));
params.fcf.dest_addr_mode = FRAME802154_LONGADDRMODE;
}
@ -148,25 +151,25 @@ send_packet(mac_callback_t sent, void *ptr)
linkaddr_copy((linkaddr_t *)&params.src_addr, &linkaddr_node_addr);
#endif
params.payload = packetbuf_dataptr();
params.payload_len = packetbuf_datalen();
params.payload = packetbuf_dataptr(buf);
params.payload_len = packetbuf_datalen(buf);
len = frame802154_hdrlen(&params);
if(packetbuf_hdralloc(len)) {
if(packetbuf_hdralloc(buf, len)) {
int ret;
frame802154_create(&params, packetbuf_hdrptr());
frame802154_create(&params, packetbuf_hdrptr(buf));
PRINTF("6MAC-UT: %2X", params.fcf.frame_type);
PRINTADDR(params.dest_addr);
PRINTF("%u %u (%u)\n", len, packetbuf_datalen(), packetbuf_totlen());
PRINTF("%u %u (%u)\n", len, packetbuf_datalen(buf), packetbuf_totlen(buf));
ret = NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
ret = NETSTACK_RADIO.send(buf, packetbuf_hdrptr(buf), packetbuf_totlen(buf));
if(sent) {
switch(ret) {
case RADIO_TX_OK:
sent(ptr, MAC_TX_OK, 1);
sent(buf, ptr, MAC_TX_OK, 1);
break;
case RADIO_TX_ERR:
sent(ptr, MAC_TX_ERR, 1);
sent(buf, ptr, MAC_TX_ERR, 1);
break;
}
}
@ -176,24 +179,24 @@ send_packet(mac_callback_t sent, void *ptr)
}
/*---------------------------------------------------------------------------*/
void
send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list)
send_list(struct net_buf *buf, mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list)
{
if(buf_list != NULL) {
queuebuf_to_packetbuf(buf_list->buf);
send_packet(sent, ptr);
queuebuf_to_packetbuf(buf, buf_list->buf);
send_packet(buf, sent, ptr);
}
}
/*---------------------------------------------------------------------------*/
static void
input_packet(void)
input_packet(struct net_buf *buf)
{
frame802154_t frame;
int len;
len = packetbuf_datalen();
len = packetbuf_datalen(buf);
if(frame802154_parse(packetbuf_dataptr(), len, &frame) &&
packetbuf_hdrreduce(len - frame.payload_len)) {
if(frame802154_parse(packetbuf_dataptr(buf), len, &frame) &&
packetbuf_hdrreduce(buf, len - frame.payload_len)) {
if(frame.fcf.dest_addr_mode) {
if(frame.dest_pid != mac_src_pan_id &&
frame.dest_pid != FRAME802154_BROADCASTPANDID) {
@ -202,9 +205,9 @@ input_packet(void)
return;
}
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
packetbuf_set_addr(buf, PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
#if !NETSTACK_CONF_BRIDGE_MODE
if(!linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
if(!linkaddr_cmp(packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER),
&linkaddr_node_addr)) {
/* Not for this node */
PRINTF("6MAC: not for us\n");
@ -213,13 +216,13 @@ input_packet(void)
#endif
}
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_addr(buf, PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
PRINTF("6MAC-IN: %2X", frame.fcf.frame_type);
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
PRINTF("%u\n", packetbuf_datalen());
NETSTACK_MAC.input();
PRINTADDR(packetbuf_addr(buf, PACKETBUF_ADDR_SENDER));
PRINTADDR(packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER));
PRINTF("%u\n", packetbuf_datalen(buf));
NETSTACK_MAC.input(buf);
} else {
PRINTF("6MAC: failed to parse hdr\n");
}

View file

@ -41,6 +41,8 @@
#ifndef NETSTACK_H
#define NETSTACK_H
#include <net/net_buf.h>
#include "contiki-conf.h"
#ifndef NETSTACK_NETWORK
@ -121,7 +123,7 @@ struct network_driver {
void (* init)(void);
/** Callback for getting notified of incoming packet. */
void (* input)(void);
void (* input)(struct net_buf *buf);
};
extern const struct network_driver NETSTACK_NETWORK;

View file

@ -1,3 +1,5 @@
#include <net/net_buf.h>
#include "dev/nullradio.h"
@ -15,16 +17,16 @@ prepare(const void *payload, unsigned short payload_len)
}
/*---------------------------------------------------------------------------*/
static int
transmit(unsigned short transmit_len)
transmit(struct net_buf *buf, unsigned short transmit_len)
{
return RADIO_TX_OK;
}
/*---------------------------------------------------------------------------*/
static int
send(const void *payload, unsigned short payload_len)
send(struct net_buf *buf, const void *payload, unsigned short payload_len)
{
prepare(payload, payload_len);
return transmit(payload_len);
return transmit(buf, payload_len);
}
/*---------------------------------------------------------------------------*/
static int

View file

@ -59,6 +59,8 @@
#include <stddef.h>
#include <net/net_buf.h>
/**
* Each radio has a set of parameters that designate the current
* configuration and state of the radio. Parameters can either have
@ -230,10 +232,10 @@ struct radio_driver {
int (* prepare)(const void *payload, unsigned short payload_len);
/** Send the packet that has previously been prepared. */
int (* transmit)(unsigned short transmit_len);
int (* transmit)(struct net_buf *buf, unsigned short transmit_len);
/** Prepare & transmit a packet. */
int (* send)(const void *payload, unsigned short payload_len);
int (* send)(struct net_buf *buf, const void *payload, unsigned short payload_len);
/** Read a received packet into a buffer. */
int (* read)(void *buf, unsigned short buf_len);

View file

@ -42,6 +42,8 @@
* @{
*/
#include <net/net_buf.h>
#include "sys/ctimer.h"
#include "contiki.h"
#include "lib/list.h"
@ -60,7 +62,7 @@ static char initialized;
/*---------------------------------------------------------------------------*/
PROCESS(ctimer_process, "Ctimer process");
PROCESS_THREAD(ctimer_process, ev, data)
PROCESS_THREAD(ctimer_process, ev, data, buf)
{
struct ctimer *c;
PROCESS_BEGIN();
@ -77,7 +79,7 @@ PROCESS_THREAD(ctimer_process, ev, data)
list_remove(ctimer_list, c);
PROCESS_CONTEXT_BEGIN(c->p);
if(c->f != NULL) {
c->f(c->ptr);
c->f(c->buf, c->ptr);
}
PROCESS_CONTEXT_END(c->p);
break;
@ -96,13 +98,14 @@ ctimer_init(void)
}
/*---------------------------------------------------------------------------*/
void
ctimer_set(struct ctimer *c, clock_time_t t,
void (*f)(void *), void *ptr)
ctimer_set(struct net_buf *buf, struct ctimer *c, clock_time_t t,
void (*f)(struct net_buf *, void *), void *ptr)
{
PRINTF("ctimer_set %p %u\n", c, (unsigned)t);
c->p = PROCESS_CURRENT();
c->f = f;
c->ptr = ptr;
c->buf = buf;
if(initialized) {
PROCESS_CONTEXT_BEGIN(&ctimer_process);
etimer_set(&c->etimer, t);

View file

@ -51,6 +51,8 @@
*
*/
#include <net/net_buf.h>
#ifndef CTIMER_H_
#define CTIMER_H_
@ -60,8 +62,9 @@ struct ctimer {
struct ctimer *next;
struct etimer etimer;
struct process *p;
void (*f)(void *);
void (*f)(struct net_buf *, void *);
void *ptr;
struct net_buf *buf;
};
/**
@ -110,8 +113,8 @@ void ctimer_restart(struct ctimer *c);
* the callback function f will be called with ptr as argument.
*
*/
void ctimer_set(struct ctimer *c, clock_time_t t,
void (*f)(void *), void *ptr);
void ctimer_set(struct net_buf *buf, struct ctimer *c, clock_time_t t,
void (*f)(struct net_buf *, void *), void *ptr);
/**
* \brief Stop a pending callback timer.

View file

@ -77,7 +77,7 @@ update_time(void)
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(etimer_process, ev, data)
PROCESS_THREAD(etimer_process, ev, data, buf)
{
struct etimer *t, *u;

View file

@ -45,6 +45,9 @@
#include <stdio.h>
#include <net/net_buf.h>
#include <net/net_core.h>
#include "sys/process.h"
#include "sys/arg.h"
@ -78,7 +81,7 @@ static volatile unsigned char poll_requested;
#define PROCESS_STATE_RUNNING 1
#define PROCESS_STATE_CALLED 2
static void call_process(struct process *p, process_event_t ev, process_data_t data);
static void call_process(struct process *p, process_event_t ev, process_data_t data, struct net_buf *buf);
#define DEBUG 0
#if DEBUG
@ -117,11 +120,11 @@ process_start(struct process *p, process_data_t data)
PRINTF("process: starting '%s'\n", PROCESS_NAME_STRING(p));
/* Post a synchronous initialization event to the process. */
process_post_synch(p, PROCESS_EVENT_INIT, data);
process_post_synch(p, PROCESS_EVENT_INIT, data, NULL);
}
/*---------------------------------------------------------------------------*/
static void
exit_process(struct process *p, struct process *fromprocess)
exit_process(struct process *p, struct process *fromprocess, struct net_buf *buf)
{
register struct process *q;
struct process *old_current = process_current;
@ -146,14 +149,14 @@ exit_process(struct process *p, struct process *fromprocess)
*/
for(q = process_list; q != NULL; q = q->next) {
if(p != q) {
call_process(q, PROCESS_EVENT_EXITED, (process_data_t)p);
call_process(q, PROCESS_EVENT_EXITED, (process_data_t)p, NULL);
}
}
if(p->thread != NULL && p != fromprocess) {
/* Post the exit event to the process that is about to exit. */
process_current = p;
p->thread(&p->pt, PROCESS_EVENT_EXIT, NULL);
p->thread(&p->pt, PROCESS_EVENT_EXIT, NULL, buf);
}
}
@ -172,26 +175,28 @@ exit_process(struct process *p, struct process *fromprocess)
}
/*---------------------------------------------------------------------------*/
static void
call_process(struct process *p, process_event_t ev, process_data_t data)
call_process(struct process *p, process_event_t ev, process_data_t data,
struct net_buf *buf)
{
int ret;
#if DEBUG
if(p->state == PROCESS_STATE_CALLED) {
printf("process: process '%s' called again with event %d\n", PROCESS_NAME_STRING(p), ev);
printf("process: process '%s' called again with event %d buf %p\n",
PROCESS_NAME_STRING(p), ev, buf);
}
#endif /* DEBUG */
if((p->state & PROCESS_STATE_RUNNING) &&
p->thread != NULL) {
PRINTF("process: calling process '%s' with event %d\n", PROCESS_NAME_STRING(p), ev);
PRINTF("process: calling process '%s' with event %d buf %p\n", PROCESS_NAME_STRING(p), ev, buf);
process_current = p;
p->state = PROCESS_STATE_CALLED;
ret = p->thread(&p->pt, ev, data);
ret = p->thread(&p->pt, ev, data, buf);
if(ret == PT_EXITED ||
ret == PT_ENDED ||
ev == PROCESS_EVENT_EXIT) {
exit_process(p, p);
exit_process(p, p, buf);
} else {
p->state = PROCESS_STATE_RUNNING;
}
@ -201,7 +206,7 @@ call_process(struct process *p, process_event_t ev, process_data_t data)
void
process_exit(struct process *p)
{
exit_process(p, PROCESS_CURRENT());
exit_process(p, PROCESS_CURRENT(), NULL);
}
/*---------------------------------------------------------------------------*/
void
@ -222,7 +227,7 @@ process_init(void)
*/
/*---------------------------------------------------------------------------*/
static void
do_poll(void)
do_poll(struct net_buf *buf)
{
struct process *p;
@ -232,7 +237,7 @@ do_poll(void)
if(p->needspoll) {
p->state = PROCESS_STATE_RUNNING;
p->needspoll = 0;
call_process(p, PROCESS_EVENT_POLL, NULL);
call_process(p, PROCESS_EVENT_POLL, NULL, buf);
}
}
}
@ -243,7 +248,7 @@ do_poll(void)
*/
/*---------------------------------------------------------------------------*/
static void
do_event(void)
do_event(struct net_buf *buf)
{
static process_event_t ev;
static process_data_t data;
@ -279,9 +284,9 @@ do_event(void)
/* If we have been requested to poll a process, we do this in
between processing the broadcast event. */
if(poll_requested) {
do_poll();
do_poll(buf);
}
call_process(p, ev, data);
call_process(p, ev, data, buf);
}
} else {
/* This is not a broadcast event, so we deliver it to the
@ -293,21 +298,21 @@ do_event(void)
}
/* Make sure that the process actually is running. */
call_process(receiver, ev, data);
call_process(receiver, ev, data, buf);
}
}
}
/*---------------------------------------------------------------------------*/
int
process_run(void)
process_run(struct net_buf *buf)
{
/* Process poll events. */
if(poll_requested) {
do_poll();
do_poll(buf);
}
/* Process one event from the queue */
do_event();
do_event(buf);
return nevents + poll_requested;
}
@ -359,11 +364,12 @@ process_post(struct process *p, process_event_t ev, process_data_t data)
}
/*---------------------------------------------------------------------------*/
void
process_post_synch(struct process *p, process_event_t ev, process_data_t data)
process_post_synch(struct process *p, process_event_t ev, process_data_t data,
struct net_buf *buf)
{
struct process *caller = process_current;
call_process(p, ev, data);
call_process(p, ev, data, buf);
process_current = caller;
}
/*---------------------------------------------------------------------------*/

View file

@ -50,12 +50,15 @@
* Adam Dunkels <adam@sics.se>
*
*/
#ifndef PROCESS_H_
#define PROCESS_H_
#include "sys/pt.h"
#include "sys/cc.h"
struct net_buf;
typedef unsigned char process_event_t;
typedef void * process_data_t;
typedef unsigned char process_num_events_t;
@ -270,10 +273,11 @@ typedef unsigned char process_num_events_t;
*
* \hideinitializer
*/
#define PROCESS_THREAD(name, ev, data) \
#define PROCESS_THREAD(name, ev, data, buf) \
static PT_THREAD(process_thread_##name(struct pt *process_pt, \
process_event_t ev, \
process_data_t data))
process_data_t data, \
struct net_buf *buf))
/**
* Declare the name of a process.
@ -305,7 +309,7 @@ static PT_THREAD(process_thread_##name(struct pt *process_pt, \
process_thread_##name }
#else
#define PROCESS(name, strname) \
PROCESS_THREAD(name, ev, data); \
PROCESS_THREAD(name, ev, data, buf); \
struct process name = { NULL, strname, \
process_thread_##name }
#endif
@ -320,7 +324,8 @@ struct process {
const char *name;
#define PROCESS_NAME_STRING(process) (process)->name
#endif
PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t));
PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t,
struct net_buf *));
struct pt pt;
unsigned char state, needspoll;
};
@ -375,7 +380,8 @@ CCIF int process_post(struct process *p, process_event_t ev, process_data_t data
* with the event.
*/
CCIF void process_post_synch(struct process *p,
process_event_t ev, process_data_t data);
process_event_t ev, process_data_t data,
struct net_buf *buf);
/**
* \brief Cause a process to exit
@ -497,7 +503,7 @@ void process_init(void);
* \return The number of events that are currently waiting in the
* event queue.
*/
int process_run(void);
int process_run(struct net_buf *buf);
/**

View file

@ -51,6 +51,8 @@
#include "net/rime/rime.h"
#endif
#if 0
/* Moved to net_buf.h */
struct packetbuf_attr packetbuf_attrs[PACKETBUF_NUM_ATTRS];
struct packetbuf_addr packetbuf_addrs[PACKETBUF_NUM_ADDRS];
@ -66,6 +68,7 @@ static uint32_t packetbuf_aligned[(PACKETBUF_SIZE + PACKETBUF_HDR_SIZE + 3) / 4]
static uint8_t *packetbuf = (uint8_t *)packetbuf_aligned;
static uint8_t *packetbufptr;
#endif
#define DEBUG 0
#if DEBUG
@ -77,70 +80,70 @@ static uint8_t *packetbufptr;
/*---------------------------------------------------------------------------*/
void
packetbuf_clear(void)
packetbuf_clear(struct net_buf *buf)
{
buflen = bufptr = 0;
hdrptr = PACKETBUF_HDR_SIZE;
uip_pkt_buflen(buf) = uip_pkt_bufptr(buf) = 0;
uip_pkt_hdrptr(buf) = PACKETBUF_HDR_SIZE;
packetbufptr = &packetbuf[PACKETBUF_HDR_SIZE];
packetbuf_attr_clear();
uip_pkt_packetbufptr(buf) = &uip_pkt_packetbuf(buf)[PACKETBUF_HDR_SIZE];
packetbuf_attr_clear(buf);
}
/*---------------------------------------------------------------------------*/
void
packetbuf_clear_hdr(void)
packetbuf_clear_hdr(struct net_buf *buf)
{
hdrptr = PACKETBUF_HDR_SIZE;
uip_pkt_hdrptr(buf) = PACKETBUF_HDR_SIZE;
}
/*---------------------------------------------------------------------------*/
int
packetbuf_copyfrom(const void *from, uint16_t len)
packetbuf_copyfrom(struct net_buf *buf, const void *from, uint16_t len)
{
uint16_t l;
packetbuf_clear();
packetbuf_clear(buf);
l = len > PACKETBUF_SIZE? PACKETBUF_SIZE: len;
memcpy(packetbufptr, from, l);
buflen = l;
memcpy(uip_pkt_packetbufptr(buf), from, l);
uip_pkt_buflen(buf) = l;
return l;
}
/*---------------------------------------------------------------------------*/
void
packetbuf_compact(void)
packetbuf_compact(struct net_buf *buf)
{
int i, len;
if(packetbuf_is_reference()) {
memcpy(&packetbuf[PACKETBUF_HDR_SIZE], packetbuf_reference_ptr(),
packetbuf_datalen());
} else if(bufptr > 0) {
len = packetbuf_datalen() + PACKETBUF_HDR_SIZE;
if(packetbuf_is_reference(buf)) {
memcpy(&uip_pkt_packetbuf(buf)[PACKETBUF_HDR_SIZE], packetbuf_reference_ptr(buf),
packetbuf_datalen(buf));
} else if(uip_pkt_bufptr(buf) > 0) {
len = packetbuf_datalen(buf) + PACKETBUF_HDR_SIZE;
for(i = PACKETBUF_HDR_SIZE; i < len; i++) {
packetbuf[i] = packetbuf[bufptr + i];
uip_pkt_packetbuf(buf)[i] = uip_pkt_packetbuf(buf)[uip_pkt_bufptr(buf) + i];
}
bufptr = 0;
uip_pkt_bufptr(buf) = 0;
}
}
/*---------------------------------------------------------------------------*/
int
packetbuf_copyto_hdr(uint8_t *to)
packetbuf_copyto_hdr(struct net_buf *buf, uint8_t *to)
{
#if DEBUG_LEVEL > 0
{
int i;
PRINTF("packetbuf_write_hdr: header:\n");
for(i = hdrptr; i < PACKETBUF_HDR_SIZE; ++i) {
PRINTF("0x%02x, ", packetbuf[i]);
for(i = uip_pkt_hdrptr(buf); i < PACKETBUF_HDR_SIZE; ++i) {
PRINTF("0x%02x, ", uip_pkt_packetbuf(buf)[i]);
}
PRINTF("\n");
}
#endif /* DEBUG_LEVEL */
memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr);
return PACKETBUF_HDR_SIZE - hdrptr;
memcpy(to, uip_pkt_packetbuf(buf) + uip_pkt_hdrptr(buf), PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf));
return PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf);
}
/*---------------------------------------------------------------------------*/
int
packetbuf_copyto(void *to)
packetbuf_copyto(struct net_buf *buf, void *to)
{
#if DEBUG_LEVEL > 0
{
@ -149,184 +152,184 @@ packetbuf_copyto(void *to)
char *bufferptr = buffer;
bufferptr[0] = 0;
for(i = hdrptr; i < PACKETBUF_HDR_SIZE; ++i) {
bufferptr += sprintf(bufferptr, "0x%02x, ", packetbuf[i]);
for(i = uip_pkt_hdrptr(buf); i < PACKETBUF_HDR_SIZE; ++i) {
bufferptr += sprintf(bufferptr, "0x%02x, ", uip_pkt_packetbuf(buf)[i]);
}
PRINTF("packetbuf_write: header: %s\n", buffer);
bufferptr = buffer;
bufferptr[0] = 0;
for(i = bufptr; i < buflen + bufptr; ++i) {
bufferptr += sprintf(bufferptr, "0x%02x, ", packetbufptr[i]);
for(i = uip_pkt_bufptr(buf); i < uip_pkt_buflen(buf) + uip_pkt_bufptr(buf); ++i) {
bufferptr += sprintf(bufferptr, "0x%02x, ", uip_pkt_packetbufptr(buf)[i]);
}
PRINTF("packetbuf_write: data: %s\n", buffer);
}
#endif /* DEBUG_LEVEL */
if(PACKETBUF_HDR_SIZE - hdrptr + buflen > PACKETBUF_SIZE) {
if(PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf) + uip_pkt_buflen(buf) > PACKETBUF_SIZE) {
/* Too large packet */
return 0;
}
memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr);
memcpy((uint8_t *)to + PACKETBUF_HDR_SIZE - hdrptr, packetbufptr + bufptr,
buflen);
return PACKETBUF_HDR_SIZE - hdrptr + buflen;
memcpy(to, uip_pkt_packetbuf(buf) + uip_pkt_hdrptr(buf), PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf));
memcpy((uint8_t *)to + PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf), uip_pkt_packetbufptr(buf) + uip_pkt_bufptr(buf),
uip_pkt_buflen(buf));
return PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf) + uip_pkt_buflen(buf);
}
/*---------------------------------------------------------------------------*/
int
packetbuf_hdralloc(int size)
packetbuf_hdralloc(struct net_buf *buf, int size)
{
if(hdrptr >= size && packetbuf_totlen() + size <= PACKETBUF_SIZE) {
hdrptr -= size;
if(uip_pkt_hdrptr(buf) >= size && packetbuf_totlen(buf) + size <= PACKETBUF_SIZE) {
uip_pkt_hdrptr(buf) -= size;
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
void
packetbuf_hdr_remove(int size)
packetbuf_hdr_remove(struct net_buf *buf, int size)
{
hdrptr += size;
uip_pkt_hdrptr(buf) += size;
}
/*---------------------------------------------------------------------------*/
int
packetbuf_hdrreduce(int size)
packetbuf_hdrreduce(struct net_buf *buf, int size)
{
if(buflen < size) {
if(uip_pkt_buflen(buf) < size) {
return 0;
}
bufptr += size;
buflen -= size;
uip_pkt_bufptr(buf) += size;
uip_pkt_buflen(buf) -= size;
return 1;
}
/*---------------------------------------------------------------------------*/
void
packetbuf_set_datalen(uint16_t len)
packetbuf_set_datalen(struct net_buf *buf, uint16_t len)
{
PRINTF("packetbuf_set_len: len %d\n", len);
buflen = len;
uip_pkt_buflen(buf) = len;
}
/*---------------------------------------------------------------------------*/
void *
packetbuf_dataptr(void)
packetbuf_dataptr(struct net_buf *buf)
{
return (void *)(&packetbuf[bufptr + PACKETBUF_HDR_SIZE]);
return (void *)(&uip_pkt_packetbuf(buf)[uip_pkt_bufptr(buf) + PACKETBUF_HDR_SIZE]);
}
/*---------------------------------------------------------------------------*/
void *
packetbuf_hdrptr(void)
packetbuf_hdrptr(struct net_buf *buf)
{
return (void *)(&packetbuf[hdrptr]);
return (void *)(&uip_pkt_packetbuf(buf)[uip_pkt_hdrptr(buf)]);
}
/*---------------------------------------------------------------------------*/
void
packetbuf_reference(void *ptr, uint16_t len)
packetbuf_reference(struct net_buf *buf, void *ptr, uint16_t len)
{
packetbuf_clear();
packetbufptr = ptr;
buflen = len;
packetbuf_clear(buf);
uip_pkt_packetbufptr(buf) = ptr;
uip_pkt_buflen(buf) = len;
}
/*---------------------------------------------------------------------------*/
int
packetbuf_is_reference(void)
packetbuf_is_reference(struct net_buf *buf)
{
return packetbufptr != &packetbuf[PACKETBUF_HDR_SIZE];
return uip_pkt_packetbufptr(buf) != &uip_pkt_packetbuf(buf)[PACKETBUF_HDR_SIZE];
}
/*---------------------------------------------------------------------------*/
void *
packetbuf_reference_ptr(void)
packetbuf_reference_ptr(struct net_buf *buf)
{
return packetbufptr;
return uip_pkt_packetbufptr(buf);
}
/*---------------------------------------------------------------------------*/
uint16_t
packetbuf_datalen(void)
packetbuf_datalen(struct net_buf *buf)
{
return buflen;
return uip_pkt_buflen(buf);
}
/*---------------------------------------------------------------------------*/
uint8_t
packetbuf_hdrlen(void)
packetbuf_hdrlen(struct net_buf *buf)
{
uint8_t hdrlen;
hdrlen = PACKETBUF_HDR_SIZE - hdrptr;
hdrlen = PACKETBUF_HDR_SIZE - uip_pkt_hdrptr(buf);
if(hdrlen) {
/* outbound packet */
return hdrlen;
} else {
/* inbound packet */
return bufptr;
return uip_pkt_bufptr(buf);
}
}
/*---------------------------------------------------------------------------*/
uint16_t
packetbuf_totlen(void)
packetbuf_totlen(struct net_buf *buf)
{
return packetbuf_hdrlen() + packetbuf_datalen();
return packetbuf_hdrlen(buf) + packetbuf_datalen(buf);
}
/*---------------------------------------------------------------------------*/
void
packetbuf_attr_clear(void)
packetbuf_attr_clear(struct net_buf *buf)
{
int i;
for(i = 0; i < PACKETBUF_NUM_ATTRS; ++i) {
packetbuf_attrs[i].val = 0;
uip_pkt_packetbuf_attrs(buf)[i].val = 0;
}
for(i = 0; i < PACKETBUF_NUM_ADDRS; ++i) {
linkaddr_copy(&packetbuf_addrs[i].addr, &linkaddr_null);
linkaddr_copy(&uip_pkt_packetbuf_addrs(buf)[i].addr, &linkaddr_null);
}
}
/*---------------------------------------------------------------------------*/
void
packetbuf_attr_copyto(struct packetbuf_attr *attrs,
packetbuf_attr_copyto(struct net_buf *buf, struct packetbuf_attr *attrs,
struct packetbuf_addr *addrs)
{
memcpy(attrs, packetbuf_attrs, sizeof(packetbuf_attrs));
memcpy(addrs, packetbuf_addrs, sizeof(packetbuf_addrs));
memcpy(attrs, uip_pkt_packetbuf_attrs(buf), sizeof(uip_pkt_packetbuf_attrs(buf)));
memcpy(addrs, uip_pkt_packetbuf_addrs(buf), sizeof(uip_pkt_packetbuf_addrs(buf)));
}
/*---------------------------------------------------------------------------*/
void
packetbuf_attr_copyfrom(struct packetbuf_attr *attrs,
packetbuf_attr_copyfrom(struct net_buf *buf, struct packetbuf_attr *attrs,
struct packetbuf_addr *addrs)
{
memcpy(packetbuf_attrs, attrs, sizeof(packetbuf_attrs));
memcpy(packetbuf_addrs, addrs, sizeof(packetbuf_addrs));
memcpy(uip_pkt_packetbuf_attrs(buf), attrs, sizeof(uip_pkt_packetbuf_attrs(buf)));
memcpy(uip_pkt_packetbuf_addrs(buf), addrs, sizeof(uip_pkt_packetbuf_addrs(buf)));
}
/*---------------------------------------------------------------------------*/
#if !PACKETBUF_CONF_ATTRS_INLINE
int
packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val)
packetbuf_set_attr(struct net_buf *buf, uint8_t type, const packetbuf_attr_t val)
{
/* packetbuf_attrs[type].type = type; */
packetbuf_attrs[type].val = val;
/* uip_pkt_packetbuf_attrs(buf)[type].type = type; */
uip_pkt_packetbuf_attrs(buf)[type].val = val;
return 1;
}
/*---------------------------------------------------------------------------*/
packetbuf_attr_t
packetbuf_attr(uint8_t type)
packetbuf_attr(struct net_buf *buf, uint8_t type)
{
return packetbuf_attrs[type].val;
return uip_pkt_packetbuf_attrs(buf)[type].val;
}
/*---------------------------------------------------------------------------*/
int
packetbuf_set_addr(uint8_t type, const linkaddr_t *addr)
packetbuf_set_addr(struct net_buf *buf, uint8_t type, const linkaddr_t *addr)
{
/* packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].type = type; */
linkaddr_copy(&packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].addr, addr);
/* uip_pkt_packetbuf_addrs(buf)[type - PACKETBUF_ADDR_FIRST].type = type; */
linkaddr_copy(&uip_pkt_packetbuf_addrs(buf)[type - PACKETBUF_ADDR_FIRST].addr, addr);
return 1;
}
/*---------------------------------------------------------------------------*/
const linkaddr_t *
packetbuf_addr(uint8_t type)
packetbuf_addr(struct net_buf *buf, uint8_t type)
{
return &packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].addr;
return &uip_pkt_packetbuf_addrs(buf)[type - PACKETBUF_ADDR_FIRST].addr;
}
/*---------------------------------------------------------------------------*/
#endif /* PACKETBUF_CONF_ATTRS_INLINE */
int
packetbuf_holds_broadcast(void)
packetbuf_holds_broadcast(struct net_buf *buf)
{
return linkaddr_cmp(&packetbuf_addrs[PACKETBUF_ADDR_RECEIVER - PACKETBUF_ADDR_FIRST].addr, &linkaddr_null);
return linkaddr_cmp(&uip_pkt_packetbuf_addrs(buf)[PACKETBUF_ADDR_RECEIVER - PACKETBUF_ADDR_FIRST].addr, &linkaddr_null);
}
/*---------------------------------------------------------------------------*/

View file

@ -49,13 +49,13 @@
* The packetbuf module does Rime's buffer management.
*/
#ifndef PACKETBUF_H_
#define PACKETBUF_H_
#include "contiki-conf.h"
#include "net/linkaddr.h"
#include "net/llsec/llsec802154.h"
#ifndef PACKETBUF_H_
#define PACKETBUF_H_
/**
* \brief The size of the packetbuf, in bytes
*/
@ -83,7 +83,7 @@
* packet in the packetbuf.
*
*/
void packetbuf_clear(void);
void packetbuf_clear(struct net_buf *buf);
/**
* \brief Clear and reset the header of the packetbuf
@ -96,9 +96,9 @@ void packetbuf_clear(void);
* packet buffer for a later retransmission.
*
*/
void packetbuf_clear_hdr(void);
void packetbuf_clear_hdr(struct net_buf *buf);
void packetbuf_hdr_remove(int bytes);
void packetbuf_hdr_remove(struct net_buf *buf, int bytes);
/**
* \brief Get a pointer to the data in the packetbuf
@ -118,7 +118,7 @@ void packetbuf_hdr_remove(int bytes);
* the header for incoming packets.
*
*/
void *packetbuf_dataptr(void);
void *packetbuf_dataptr(struct net_buf *buf);
/**
* \brief Get a pointer to the header in the packetbuf, for outbound packets
@ -130,7 +130,7 @@ void *packetbuf_dataptr(void);
* stored in the packetbuf.
*
*/
void *packetbuf_hdrptr(void);
void *packetbuf_hdrptr(struct net_buf *buf);
/**
* \brief Get the length of the header in the packetbuf
@ -143,7 +143,7 @@ void *packetbuf_hdrptr(void);
* packetbuf_hdrptr() function.
*
*/
uint8_t packetbuf_hdrlen(void);
uint8_t packetbuf_hdrlen(struct net_buf *buf);
/**
@ -162,14 +162,14 @@ uint8_t packetbuf_hdrlen(void);
* length of the packet - both header and data.
*
*/
uint16_t packetbuf_datalen(void);
uint16_t packetbuf_datalen(struct net_buf *buf);
/**
* \brief Get the total length of the header and data in the packetbuf
* \return Length of data and header in the packetbuf
*
*/
uint16_t packetbuf_totlen(void);
uint16_t packetbuf_totlen(struct net_buf *buf);
/**
* \brief Set the length of the data in the packetbuf
@ -179,7 +179,7 @@ uint16_t packetbuf_totlen(void);
* parts: header and data. This function is used to set
* the length of the data in the packetbuf.
*/
void packetbuf_set_datalen(uint16_t len);
void packetbuf_set_datalen(struct net_buf *buf, uint16_t len);
/**
* \brief Point the packetbuf to external data
@ -192,7 +192,7 @@ void packetbuf_set_datalen(uint16_t len);
* specifies the length of the external data that the
* packetbuf references.
*/
void packetbuf_reference(void *ptr, uint16_t len);
void packetbuf_reference(struct net_buf *buf, void *ptr, uint16_t len);
/**
* \brief Check if the packetbuf references external data
@ -204,7 +204,7 @@ void packetbuf_reference(void *ptr, uint16_t len);
* previously been referenced with packetbuf_reference().
*
*/
int packetbuf_is_reference(void);
int packetbuf_is_reference(struct net_buf *buf);
/**
* \brief Get a pointer to external data referenced by the packetbuf
@ -217,7 +217,7 @@ int packetbuf_is_reference(void);
* pointer to the external data.
*
*/
void *packetbuf_reference_ptr(void);
void *packetbuf_reference_ptr(struct net_buf *buf);
/**
* \brief Compact the packetbuf
@ -233,7 +233,7 @@ void *packetbuf_reference_ptr(void);
* that the entire packet is consecutive in memory.
*
*/
void packetbuf_compact(void);
void packetbuf_compact(struct net_buf *buf);
/**
* \brief Copy from external data into the packetbuf
@ -248,7 +248,7 @@ void packetbuf_compact(void);
* copied into the rimbuf is returned.
*
*/
int packetbuf_copyfrom(const void *from, uint16_t len);
int packetbuf_copyfrom(struct net_buf *buf, const void *from, uint16_t len);
/**
* \brief Copy the entire packetbuf to an external buffer
@ -268,7 +268,7 @@ int packetbuf_copyfrom(const void *from, uint16_t len);
* returned.
*
*/
int packetbuf_copyto(void *to);
int packetbuf_copyto(struct net_buf *buf, void *to);
/**
* \brief Copy the header portion of the packetbuf to an external buffer
@ -284,7 +284,7 @@ int packetbuf_copyto(void *to);
* copied to the external buffer is returned.
*
*/
int packetbuf_copyto_hdr(uint8_t *to);
int packetbuf_copyto_hdr(struct net_buf *buf, uint8_t *to);
/**
* \brief Extend the header of the packetbuf, for outbound packets
@ -298,7 +298,7 @@ int packetbuf_copyto_hdr(uint8_t *to);
* zero and does not allocate anything.
*
*/
int packetbuf_hdralloc(int size);
int packetbuf_hdralloc(struct net_buf *buf, int size);
/**
* \brief Reduce the header in the packetbuf, for incoming packets
@ -312,7 +312,7 @@ int packetbuf_hdralloc(int size);
* zero and does not allocate anything.
*
*/
int packetbuf_hdrreduce(int size);
int packetbuf_hdrreduce(struct net_buf *buf, int size);
/* Packet attributes stuff below: */
@ -422,59 +422,64 @@ enum {
#if PACKETBUF_CONF_ATTRS_INLINE
#if 0
/* Moved to net_buf.h */
extern struct packetbuf_attr packetbuf_attrs[];
extern struct packetbuf_addr packetbuf_addrs[];
#endif
static int packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val);
static packetbuf_attr_t packetbuf_attr(uint8_t type);
static int packetbuf_set_addr(uint8_t type, const linkaddr_t *addr);
static const linkaddr_t *packetbuf_addr(uint8_t type);
static int packetbuf_set_attr(struct net_buf *buf, uint8_t type, const packetbuf_attr_t val);
static packetbuf_attr_t packetbuf_attr(struct net_buf *buf, uint8_t type);
static int packetbuf_set_addr(struct net_buf *buf, uint8_t type, const linkaddr_t *addr);
static const linkaddr_t *packetbuf_addr(struct net_buf *buf, uint8_t type);
static inline int
packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val)
packetbuf_set_attr(struct net_buf *buf, uint8_t type, const packetbuf_attr_t val)
{
/* packetbuf_attrs[type].type = type; */
packetbuf_attrs[type].val = val;
uip_pkt_packetbuf_attrs(buf)[type].val = val;
return 1;
}
static inline packetbuf_attr_t
packetbuf_attr(uint8_t type)
packetbuf_attr(struct net_buf *buf, uint8_t type)
{
return packetbuf_attrs[type].val;
return uip_pkt_packetbuf_attrs(buf)[type].val;
}
static inline int
packetbuf_set_addr(uint8_t type, const linkaddr_t *addr)
packetbuf_set_addr(struct net_buf *buf, uint8_t type, const linkaddr_t *addr)
{
/* packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].type = type; */
linkaddr_copy(&packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].addr, addr);
linkaddr_copy(&uip_pkt_packetbuf_addrs(buf)[type - PACKETBUF_ADDR_FIRST].addr, addr);
return 1;
}
static inline const linkaddr_t *
packetbuf_addr(uint8_t type)
packetbuf_addr(struct net_buf *buf, uint8_t type)
{
return &packetbuf_addrs[type - PACKETBUF_ADDR_FIRST].addr;
return &uip_pkt_packetbuf_addrs(buf)[type - PACKETBUF_ADDR_FIRST].addr;
}
#else /* PACKETBUF_CONF_ATTRS_INLINE */
int packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val);
packetbuf_attr_t packetbuf_attr(uint8_t type);
int packetbuf_set_addr(uint8_t type, const linkaddr_t *addr);
const linkaddr_t *packetbuf_addr(uint8_t type);
int packetbuf_set_attr(struct net_buf *buf, uint8_t type, const packetbuf_attr_t val);
packetbuf_attr_t packetbuf_attr(struct net_buf *buf, uint8_t type);
int packetbuf_set_addr(struct net_buf *buf, uint8_t type, const linkaddr_t *addr);
const linkaddr_t *packetbuf_addr(struct net_buf *buf, uint8_t type);
#endif /* PACKETBUF_CONF_ATTRS_INLINE */
/**
* \brief Checks whether the current packet is a broadcast.
* \retval 0 iff current packet is not a broadcast
*/
int packetbuf_holds_broadcast(void);
int packetbuf_holds_broadcast(struct net_buf *buf);
void packetbuf_attr_clear(void);
void packetbuf_attr_clear(struct net_buf *buf);
void packetbuf_attr_copyto(struct packetbuf_attr *attrs,
struct packetbuf_addr *addrs);
void packetbuf_attr_copyfrom(struct packetbuf_attr *attrs,
void packetbuf_attr_copyto(struct net_buf *buf,
struct packetbuf_attr *attrs,
struct packetbuf_addr *addrs);
void packetbuf_attr_copyfrom(struct net_buf *buf,
struct packetbuf_attr *attrs,
struct packetbuf_addr *addrs);
#define PACKETBUF_ATTRIBUTES(...) { __VA_ARGS__ PACKETBUF_ATTR_LAST }
#define PACKETBUF_ATTR_LAST { PACKETBUF_ATTR_NONE, 0 }

View file

@ -43,6 +43,8 @@
*/
#include "contiki-net.h"
#include "memb.h"
#include "queuebuf.h"
#if WITH_SWAP
#include "cfs/cfs.h"
#endif
@ -308,9 +310,9 @@ queuebuf_init(void)
}
/*---------------------------------------------------------------------------*/
int
queuebuf_numfree(void)
queuebuf_numfree(struct net_buf *buf)
{
if(packetbuf_is_reference()) {
if(packetbuf_is_reference(buf)) {
return memb_numfree(&refbufmem);
} else {
return memb_numfree(&bufmem);
@ -319,24 +321,24 @@ queuebuf_numfree(void)
/*---------------------------------------------------------------------------*/
#if QUEUEBUF_DEBUG
struct queuebuf *
queuebuf_new_from_packetbuf_debug(const char *file, int line)
queuebuf_new_from_packetbuf_debug(struct net_buf *netbuf, const char *file, int line)
#else /* QUEUEBUF_DEBUG */
struct queuebuf *
queuebuf_new_from_packetbuf(void)
queuebuf_new_from_packetbuf(struct net_buf *netbuf)
#endif /* QUEUEBUF_DEBUG */
{
struct queuebuf *buf;
struct queuebuf_ref *rbuf;
if(packetbuf_is_reference()) {
if(packetbuf_is_reference(netbuf)) {
rbuf = memb_alloc(&refbufmem);
if(rbuf != NULL) {
#if QUEUEBUF_STATS
++queuebuf_ref_len;
#endif /* QUEUEBUF_STATS */
rbuf->len = packetbuf_datalen();
rbuf->ref = packetbuf_reference_ptr();
rbuf->hdrlen = packetbuf_copyto_hdr(rbuf->hdr);
rbuf->len = packetbuf_datalen(netbuf);
rbuf->ref = packetbuf_reference_ptr(netbuf);
rbuf->hdrlen = packetbuf_copyto_hdr(netbuf, rbuf->hdr);
} else {
PRINTF("queuebuf_new_from_packetbuf: could not allocate a reference queuebuf\n");
}
@ -372,8 +374,8 @@ queuebuf_new_from_packetbuf(void)
buframptr = buf->ram_ptr;
#endif
buframptr->len = packetbuf_copyto(buframptr->data);
packetbuf_attr_copyto(buframptr->attrs, buframptr->addrs);
buframptr->len = packetbuf_copyto(netbuf, buframptr->data);
packetbuf_attr_copyto(netbuf, buframptr->attrs, buframptr->addrs);
#if WITH_SWAP
if(buf->location == IN_CFS) {
@ -404,10 +406,10 @@ queuebuf_new_from_packetbuf(void)
}
/*---------------------------------------------------------------------------*/
void
queuebuf_update_attr_from_packetbuf(struct queuebuf *buf)
queuebuf_update_attr_from_packetbuf(struct net_buf *netbuf, struct queuebuf *buf)
{
struct queuebuf_data *buframptr = queuebuf_load_to_ram(buf);
packetbuf_attr_copyto(buframptr->attrs, buframptr->addrs);
packetbuf_attr_copyto(netbuf, buframptr->attrs, buframptr->addrs);
#if WITH_SWAP
if(buf->location == IN_CFS) {
queuebuf_flush_tmpdata();
@ -416,11 +418,11 @@ queuebuf_update_attr_from_packetbuf(struct queuebuf *buf)
}
/*---------------------------------------------------------------------------*/
void
queuebuf_update_from_packetbuf(struct queuebuf *buf)
queuebuf_update_from_packetbuf(struct net_buf *netbuf, struct queuebuf *buf)
{
struct queuebuf_data *buframptr = queuebuf_load_to_ram(buf);
packetbuf_attr_copyto(buframptr->attrs, buframptr->addrs);
buframptr->len = packetbuf_copyto(buframptr->data);
packetbuf_attr_copyto(netbuf, buframptr->attrs, buframptr->addrs);
buframptr->len = packetbuf_copyto(netbuf, buframptr->data);
#if WITH_SWAP
if(buf->location == IN_CFS) {
queuebuf_flush_tmpdata();
@ -458,19 +460,19 @@ queuebuf_free(struct queuebuf *buf)
}
/*---------------------------------------------------------------------------*/
void
queuebuf_to_packetbuf(struct queuebuf *b)
queuebuf_to_packetbuf(struct net_buf *netbuf, struct queuebuf *b)
{
struct queuebuf_ref *r;
if(memb_inmemb(&bufmem, b)) {
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
packetbuf_copyfrom(buframptr->data, buframptr->len);
packetbuf_attr_copyfrom(buframptr->attrs, buframptr->addrs);
packetbuf_copyfrom(netbuf, buframptr->data, buframptr->len);
packetbuf_attr_copyfrom(netbuf, buframptr->attrs, buframptr->addrs);
} else if(memb_inmemb(&refbufmem, b)) {
r = (struct queuebuf_ref *)b;
packetbuf_clear();
packetbuf_copyfrom(r->ref, r->len);
packetbuf_hdralloc(r->hdrlen);
memcpy(packetbuf_hdrptr(), r->hdr, r->hdrlen);
packetbuf_clear(netbuf);
packetbuf_copyfrom(netbuf, r->ref, r->len);
packetbuf_hdralloc(netbuf, r->hdrlen);
memcpy(packetbuf_hdrptr(netbuf), r->hdr, r->hdrlen);
}
}
/*---------------------------------------------------------------------------*/

View file

@ -90,15 +90,15 @@ struct queuebuf;
void queuebuf_init(void);
#if QUEUEBUF_DEBUG
struct queuebuf *queuebuf_new_from_packetbuf_debug(const char *file, int line);
#define queuebuf_new_from_packetbuf() queuebuf_new_from_packetbuf_debug(__FILE__, __LINE__)
struct queuebuf *queuebuf_new_from_packetbuf_debug(struct net_buf *buf, const char *file, int line);
#define queuebuf_new_from_packetbuf(buf) queuebuf_new_from_packetbuf_debug(buf,__FILE__, __LINE__)
#else /* QUEUEBUF_DEBUG */
struct queuebuf *queuebuf_new_from_packetbuf(void);
struct queuebuf *queuebuf_new_from_packetbuf(struct net_buf *buf);
#endif /* QUEUEBUF_DEBUG */
void queuebuf_update_attr_from_packetbuf(struct queuebuf *b);
void queuebuf_update_from_packetbuf(struct queuebuf *b);
void queuebuf_update_attr_from_packetbuf(struct net_buf *buf, struct queuebuf *b);
void queuebuf_update_from_packetbuf(struct net_buf *buf, struct queuebuf *b);
void queuebuf_to_packetbuf(struct queuebuf *b);
void queuebuf_to_packetbuf(struct net_buf *buf, struct queuebuf *b);
void queuebuf_free(struct queuebuf *b);
void *queuebuf_dataptr(struct queuebuf *b);
@ -109,7 +109,7 @@ packetbuf_attr_t queuebuf_attr(struct queuebuf *b, uint8_t type);
void queuebuf_debug_print(void);
int queuebuf_numfree(void);
int queuebuf_numfree(struct net_buf *buf);
#endif /* __QUEUEBUF_H__ */

View file

@ -45,13 +45,13 @@
/*--------------------------------------------------------------------*/
uint8_t
uip_driver_send(const uip_lladdr_t *lladdr)
uip_driver_send(struct net_buf *buf, const uip_lladdr_t *lladdr)
{
packetbuf_copyfrom(&uip_buf[UIP_LLH_LEN], uip_len);
packetbuf_copyfrom(buf, &uip_buf(buf)[UIP_LLH_LEN], uip_len(buf));
/* XXX we should provide a callback function that is called when the
packet is sent. For now, we just supply a NULL pointer. */
NETSTACK_LLSEC.send(NULL, NULL);
NETSTACK_LLSEC.send(buf, NULL, NULL);
return 1;
}
/*--------------------------------------------------------------------*/
@ -66,13 +66,13 @@ init(void)
}
/*--------------------------------------------------------------------*/
static void
input(void)
input(struct net_buf *buf)
{
if(packetbuf_datalen() > 0 &&
packetbuf_datalen() <= UIP_BUFSIZE - UIP_LLH_LEN) {
memcpy(&uip_buf[UIP_LLH_LEN], packetbuf_dataptr(), packetbuf_datalen());
uip_len = packetbuf_datalen();
tcpip_input();
if(packetbuf_datalen(buf) > 0 &&
packetbuf_datalen(buf) <= UIP_BUFSIZE - UIP_LLH_LEN) {
memcpy(&uip_buf(buf)[UIP_LLH_LEN], packetbuf_dataptr(buf), packetbuf_datalen(buf));
uip_len(buf) = packetbuf_datalen(buf);
tcpip_input(buf);
}
}
/*--------------------------------------------------------------------*/

View file

@ -40,8 +40,9 @@
#define UIP_DRIVER_H_
#include "net/netstack.h"
#include "net/ip/uip.h"
uint8_t uip_driver_send(const uip_lladdr_t *lladdr);
uint8_t uip_driver_send(struct net_buf *buf, const uip_lladdr_t *lladdr);
extern const struct network_driver uip_driver;