packetbuf: No more splitting of header and data

master-31012017
kkrentz 2016-02-04 03:25:47 -08:00
parent 0af4a18c09
commit 6fb6fd5bb9
6 changed files with 28 additions and 92 deletions

View File

@ -54,17 +54,15 @@ struct packetbuf_addr packetbuf_addrs[PACKETBUF_NUM_ADDRS];
static uint16_t buflen, bufptr; static uint16_t buflen, bufptr;
static uint8_t hdrptr; static uint8_t hdrlen;
/* The declarations below ensure that the packet buffer is aligned on /* The declarations below ensure that the packet buffer is aligned on
an even 32-bit boundary. On some platforms (most notably the an even 32-bit boundary. On some platforms (most notably the
msp430 or OpenRISC), having a potentially misaligned packet buffer may lead to msp430 or OpenRISC), having a potentially misaligned packet buffer may lead to
problems when accessing words. */ problems when accessing words. */
static uint32_t packetbuf_aligned[(PACKETBUF_SIZE + PACKETBUF_HDR_SIZE + 3) / 4]; static uint32_t packetbuf_aligned[(PACKETBUF_SIZE + 3) / 4];
static uint8_t *packetbuf = (uint8_t *)packetbuf_aligned; static uint8_t *packetbuf = (uint8_t *)packetbuf_aligned;
static uint8_t *packetbufptr;
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
#include <stdio.h> #include <stdio.h>
@ -78,9 +76,8 @@ void
packetbuf_clear(void) packetbuf_clear(void)
{ {
buflen = bufptr = 0; buflen = bufptr = 0;
hdrptr = PACKETBUF_HDR_SIZE; hdrlen = 0;
packetbufptr = &packetbuf[PACKETBUF_HDR_SIZE];
packetbuf_attr_clear(); packetbuf_attr_clear();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -91,7 +88,7 @@ packetbuf_copyfrom(const void *from, uint16_t len)
packetbuf_clear(); packetbuf_clear();
l = MIN(PACKETBUF_SIZE, len); l = MIN(PACKETBUF_SIZE, len);
memcpy(packetbufptr, from, l); memcpy(packetbuf, from, l);
buflen = l; buflen = l;
return l; return l;
} }
@ -99,14 +96,13 @@ packetbuf_copyfrom(const void *from, uint16_t len)
void void
packetbuf_compact(void) packetbuf_compact(void)
{ {
int i, len; int16_t i;
if(bufptr > 0) { if(bufptr) {
len = packetbuf_datalen() + PACKETBUF_HDR_SIZE; /* shift data to the left */
for(i = PACKETBUF_HDR_SIZE; i < len; i++) { for(i = 0; i < buflen; i++) {
packetbuf[i] = packetbuf[bufptr + i]; packetbuf[hdrlen + i] = packetbuf[packetbuf_hdrlen() + i];
} }
bufptr = 0; bufptr = 0;
} }
} }
@ -114,24 +110,29 @@ packetbuf_compact(void)
int int
packetbuf_copyto(void *to) packetbuf_copyto(void *to)
{ {
if(PACKETBUF_HDR_SIZE - hdrptr + buflen > PACKETBUF_SIZE) { if(hdrlen + buflen > PACKETBUF_SIZE) {
/* Too large packet */
return 0; return 0;
} }
memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr); memcpy(to, packetbuf_hdrptr(), hdrlen);
memcpy((uint8_t *)to + PACKETBUF_HDR_SIZE - hdrptr, packetbufptr + bufptr, memcpy((uint8_t *)to + hdrlen, packetbuf_dataptr(), buflen);
buflen); return hdrlen + buflen;
return PACKETBUF_HDR_SIZE - hdrptr + buflen;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
packetbuf_hdralloc(int size) packetbuf_hdralloc(int size)
{ {
if(hdrptr >= size && packetbuf_totlen() + size <= PACKETBUF_SIZE) { int16_t i;
hdrptr -= size;
return 1; if(size + packetbuf_totlen() > PACKETBUF_SIZE) {
return 0;
} }
return 0;
/* shift data to the right */
for(i = packetbuf_totlen() - 1; i >= 0; i--) {
packetbuf[i + size] = packetbuf[i];
}
hdrlen += size;
return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
@ -156,13 +157,13 @@ packetbuf_set_datalen(uint16_t len)
void * void *
packetbuf_dataptr(void) packetbuf_dataptr(void)
{ {
return (void *)(&packetbuf[bufptr + PACKETBUF_HDR_SIZE]); return packetbuf + packetbuf_hdrlen();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void * void *
packetbuf_hdrptr(void) packetbuf_hdrptr(void)
{ {
return (void *)(&packetbuf[hdrptr]); return packetbuf;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint16_t uint16_t
@ -174,16 +175,7 @@ packetbuf_datalen(void)
uint8_t uint8_t
packetbuf_hdrlen(void) packetbuf_hdrlen(void)
{ {
uint8_t hdrlen; return bufptr + hdrlen;
hdrlen = PACKETBUF_HDR_SIZE - hdrptr;
if(hdrlen) {
/* outbound packet */
return hdrlen;
} else {
/* inbound packet */
return bufptr;
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint16_t uint16_t

View File

@ -66,15 +66,6 @@
#define PACKETBUF_SIZE 128 #define PACKETBUF_SIZE 128
#endif #endif
/**
* \brief The size of the packetbuf header, in bytes
*/
#ifdef PACKETBUF_CONF_HDR_SIZE
#define PACKETBUF_HDR_SIZE PACKETBUF_CONF_HDR_SIZE
#else
#define PACKETBUF_HDR_SIZE 48
#endif
#ifdef PACKETBUF_CONF_WITH_PACKET_TYPE #ifdef PACKETBUF_CONF_WITH_PACKET_TYPE
#define PACKETBUF_WITH_PACKET_TYPE PACKETBUF_CONF_WITH_PACKET_TYPE #define PACKETBUF_WITH_PACKET_TYPE PACKETBUF_CONF_WITH_PACKET_TYPE
#else #else
@ -100,15 +91,6 @@ void packetbuf_clear(void);
* the packetbuf. The data is either stored in the packetbuf, * the packetbuf. The data is either stored in the packetbuf,
* or referenced to an external location. * or referenced to an external location.
* *
* For outbound packets, the packetbuf consists of two
* parts: header and data. The header is accessed with the
* packetbuf_hdrptr() function.
*
* For incoming packets, both the packet header and the
* packet data is stored in the data portion of the
* packetbuf. Thus this function is used to get a pointer to
* the header for incoming packets.
*
*/ */
void *packetbuf_dataptr(void); void *packetbuf_dataptr(void);
@ -116,11 +98,6 @@ void *packetbuf_dataptr(void);
* \brief Get a pointer to the header in the packetbuf, for outbound packets * \brief Get a pointer to the header in the packetbuf, for outbound packets
* \return Pointer to the packetbuf header * \return Pointer to the packetbuf header
* *
* For outbound packets, the packetbuf consists of two
* parts: header and data. This function is used to get a
* pointer to the header in the packetbuf. The header is
* stored in the packetbuf.
*
*/ */
void *packetbuf_hdrptr(void); void *packetbuf_hdrptr(void);
@ -128,12 +105,6 @@ void *packetbuf_hdrptr(void);
* \brief Get the length of the header in the packetbuf * \brief Get the length of the header in the packetbuf
* \return Length of the header in the packetbuf * \return Length of the header in the packetbuf
* *
* For outbound packets, the packetbuf consists of two
* parts: header and data. This function is used to get
* the length of the header in the packetbuf. The header is
* stored in the packetbuf and accessed via the
* packetbuf_hdrptr() function.
*
*/ */
uint8_t packetbuf_hdrlen(void); uint8_t packetbuf_hdrlen(void);
@ -142,17 +113,6 @@ uint8_t packetbuf_hdrlen(void);
* \brief Get the length of the data in the packetbuf * \brief Get the length of the data in the packetbuf
* \return Length of the data in the packetbuf * \return Length of the data in the packetbuf
* *
* For outbound packets, the packetbuf consists of two
* parts: header and data. This function is used to get
* the length of the data in the packetbuf. The data is
* stored in the packetbuf and accessed via the
* packetbuf_dataptr() function.
*
* For incoming packets, both the packet header and the
* packet data is stored in the data portion of the
* packetbuf. This function is then used to get the total
* length of the packet - both header and data.
*
*/ */
uint16_t packetbuf_datalen(void); uint16_t packetbuf_datalen(void);
@ -166,10 +126,6 @@ uint16_t packetbuf_totlen(void);
/** /**
* \brief Set the length of the data in the packetbuf * \brief Set the length of the data in the packetbuf
* \param len The length of the data * \param len The length of the data
*
* For outbound packets, the packetbuf consists of two
* 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(uint16_t len);
@ -213,7 +169,7 @@ int packetbuf_copyfrom(const void *from, uint16_t len);
* *
* The external buffer to which the packetbuf is to be * The external buffer to which the packetbuf is to be
* copied must be able to accomodate at least * copied must be able to accomodate at least
* (PACKETBUF_SIZE + PACKETBUF_HDR_SIZE) bytes. The number of * PACKETBUF_SIZE bytes. The number of
* bytes that was copied to the external buffer is * bytes that was copied to the external buffer is
* returned. * returned.
* *

View File

@ -138,15 +138,12 @@ typedef unsigned short uip_stats_t;
/* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */ /* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */
#if RF230BB #if RF230BB
#undef PACKETBUF_CONF_HDR_SIZE //Use the packetbuf default for header size
/* TX routine passes the cca/ack result in the return parameter */ /* TX routine passes the cca/ack result in the return parameter */
#define RDC_CONF_HARDWARE_ACK 1 #define RDC_CONF_HARDWARE_ACK 1
/* TX routine does automatic cca and optional backoff */ /* TX routine does automatic cca and optional backoff */
#define RDC_CONF_HARDWARE_CSMA 1 #define RDC_CONF_HARDWARE_CSMA 1
/* Allow MCU sleeping between channel checks */ /* Allow MCU sleeping between channel checks */
#define RDC_CONF_MCU_SLEEP 0 #define RDC_CONF_MCU_SLEEP 0
#else
#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally
#endif /*RF230BB */ #endif /*RF230BB */
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6

View File

@ -204,11 +204,6 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len);
/* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */ /* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */
/* These mostly have no effect when the Jackdaw is a repeater (CONTIKI_NO_NET=1 using fakeuip.c) */ /* These mostly have no effect when the Jackdaw is a repeater (CONTIKI_NO_NET=1 using fakeuip.c) */
#if RF230BB
#else
#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally
#endif /*RF230BB */
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
#define LINKADDR_CONF_SIZE 8 #define LINKADDR_CONF_SIZE 8
#define UIP_CONF_ICMP6 1 #define UIP_CONF_ICMP6 1

View File

@ -85,7 +85,6 @@ void clock_adjust_ticks(clock_time_t howmany);
#define CLIF #define CLIF
#define LINKADDR_CONF_SIZE 8 #define LINKADDR_CONF_SIZE 8
#define PACKETBUF_CONF_HDR_SIZE 48 /* Choose a buffersize != 0 for the messages which should be sended over the wireless interface */
/* Uncomment this lines to activate the specific drivers */ /* Uncomment this lines to activate the specific drivers */
//#define NETSTACK_CONF_NETWORK rime_driver //#define NETSTACK_CONF_NETWORK rime_driver

View File

@ -88,7 +88,6 @@ void clock_adjust_ticks(clock_time_t howmany);
#endif #endif
#define LINKADDR_CONF_SIZE 8 #define LINKADDR_CONF_SIZE 8
#define PACKETBUF_CONF_HDR_SIZE 0
//define NETSTACK_CONF_WITH_IPV6 1 //Let the makefile do this, allows hello-world to compile //define NETSTACK_CONF_WITH_IPV6 1 //Let the makefile do this, allows hello-world to compile
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
@ -100,7 +99,6 @@ void clock_adjust_ticks(clock_time_t howmany);
/* The new NETSTACK interface requires RF230BB */ /* The new NETSTACK interface requires RF230BB */
#if RF230BB #if RF230BB
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
#undef PACKETBUF_CONF_HDR_SIZE //RF230BB takes the packetbuf default for header size
#define UIP_CONF_LLH_LEN 0 #define UIP_CONF_LLH_LEN 0
/* No radio cycling */ /* No radio cycling */
@ -126,7 +124,6 @@ void clock_adjust_ticks(clock_time_t howmany);
#else #else
/* Original combined RF230/mac code will not compile with current contiki stack */ /* Original combined RF230/mac code will not compile with current contiki stack */
//#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 handles headers internally
//FTH081105 //FTH081105
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
#define SICSLOWPAN_CONF_MAXAGE 5 #define SICSLOWPAN_CONF_MAXAGE 5