packetbuf: No more splitting of header and data
This commit is contained in:
parent
0af4a18c09
commit
6fb6fd5bb9
|
@ -54,17 +54,15 @@ struct packetbuf_addr packetbuf_addrs[PACKETBUF_NUM_ADDRS];
|
|||
|
||||
|
||||
static uint16_t buflen, bufptr;
|
||||
static uint8_t hdrptr;
|
||||
static uint8_t hdrlen;
|
||||
|
||||
/* The declarations below ensure that the packet buffer is aligned on
|
||||
an even 32-bit boundary. On some platforms (most notably the
|
||||
msp430 or OpenRISC), having a potentially misaligned packet buffer may lead to
|
||||
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 *packetbufptr;
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
|
@ -78,9 +76,8 @@ void
|
|||
packetbuf_clear(void)
|
||||
{
|
||||
buflen = bufptr = 0;
|
||||
hdrptr = PACKETBUF_HDR_SIZE;
|
||||
hdrlen = 0;
|
||||
|
||||
packetbufptr = &packetbuf[PACKETBUF_HDR_SIZE];
|
||||
packetbuf_attr_clear();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -91,7 +88,7 @@ packetbuf_copyfrom(const void *from, uint16_t len)
|
|||
|
||||
packetbuf_clear();
|
||||
l = MIN(PACKETBUF_SIZE, len);
|
||||
memcpy(packetbufptr, from, l);
|
||||
memcpy(packetbuf, from, l);
|
||||
buflen = l;
|
||||
return l;
|
||||
}
|
||||
|
@ -99,14 +96,13 @@ packetbuf_copyfrom(const void *from, uint16_t len)
|
|||
void
|
||||
packetbuf_compact(void)
|
||||
{
|
||||
int i, len;
|
||||
int16_t i;
|
||||
|
||||
if(bufptr > 0) {
|
||||
len = packetbuf_datalen() + PACKETBUF_HDR_SIZE;
|
||||
for(i = PACKETBUF_HDR_SIZE; i < len; i++) {
|
||||
packetbuf[i] = packetbuf[bufptr + i];
|
||||
if(bufptr) {
|
||||
/* shift data to the left */
|
||||
for(i = 0; i < buflen; i++) {
|
||||
packetbuf[hdrlen + i] = packetbuf[packetbuf_hdrlen() + i];
|
||||
}
|
||||
|
||||
bufptr = 0;
|
||||
}
|
||||
}
|
||||
|
@ -114,24 +110,29 @@ packetbuf_compact(void)
|
|||
int
|
||||
packetbuf_copyto(void *to)
|
||||
{
|
||||
if(PACKETBUF_HDR_SIZE - hdrptr + buflen > PACKETBUF_SIZE) {
|
||||
/* Too large packet */
|
||||
if(hdrlen + buflen > PACKETBUF_SIZE) {
|
||||
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, packetbuf_hdrptr(), hdrlen);
|
||||
memcpy((uint8_t *)to + hdrlen, packetbuf_dataptr(), buflen);
|
||||
return hdrlen + buflen;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
packetbuf_hdralloc(int size)
|
||||
{
|
||||
if(hdrptr >= size && packetbuf_totlen() + size <= PACKETBUF_SIZE) {
|
||||
hdrptr -= size;
|
||||
return 1;
|
||||
int16_t i;
|
||||
|
||||
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
|
||||
|
@ -156,13 +157,13 @@ packetbuf_set_datalen(uint16_t len)
|
|||
void *
|
||||
packetbuf_dataptr(void)
|
||||
{
|
||||
return (void *)(&packetbuf[bufptr + PACKETBUF_HDR_SIZE]);
|
||||
return packetbuf + packetbuf_hdrlen();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void *
|
||||
packetbuf_hdrptr(void)
|
||||
{
|
||||
return (void *)(&packetbuf[hdrptr]);
|
||||
return packetbuf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
|
@ -174,16 +175,7 @@ packetbuf_datalen(void)
|
|||
uint8_t
|
||||
packetbuf_hdrlen(void)
|
||||
{
|
||||
uint8_t hdrlen;
|
||||
|
||||
hdrlen = PACKETBUF_HDR_SIZE - hdrptr;
|
||||
if(hdrlen) {
|
||||
/* outbound packet */
|
||||
return hdrlen;
|
||||
} else {
|
||||
/* inbound packet */
|
||||
return bufptr;
|
||||
}
|
||||
return bufptr + hdrlen;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
|
|
|
@ -66,15 +66,6 @@
|
|||
#define PACKETBUF_SIZE 128
|
||||
#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
|
||||
#define PACKETBUF_WITH_PACKET_TYPE PACKETBUF_CONF_WITH_PACKET_TYPE
|
||||
#else
|
||||
|
@ -100,15 +91,6 @@ void packetbuf_clear(void);
|
|||
* the packetbuf. The data is either stored in the packetbuf,
|
||||
* 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);
|
||||
|
||||
|
@ -116,11 +98,6 @@ void *packetbuf_dataptr(void);
|
|||
* \brief Get a pointer to the header in the packetbuf, for outbound packets
|
||||
* \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);
|
||||
|
||||
|
@ -128,12 +105,6 @@ void *packetbuf_hdrptr(void);
|
|||
* \brief Get the 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);
|
||||
|
||||
|
@ -142,17 +113,6 @@ uint8_t packetbuf_hdrlen(void);
|
|||
* \brief Get the 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);
|
||||
|
||||
|
@ -166,10 +126,6 @@ uint16_t packetbuf_totlen(void);
|
|||
/**
|
||||
* \brief Set the length of the data in the packetbuf
|
||||
* \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);
|
||||
|
||||
|
@ -213,7 +169,7 @@ int packetbuf_copyfrom(const void *from, uint16_t len);
|
|||
*
|
||||
* The external buffer to which the packetbuf is to be
|
||||
* 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
|
||||
* returned.
|
||||
*
|
||||
|
|
|
@ -138,15 +138,12 @@ typedef unsigned short uip_stats_t;
|
|||
|
||||
/* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */
|
||||
#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 */
|
||||
#define RDC_CONF_HARDWARE_ACK 1
|
||||
/* TX routine does automatic cca and optional backoff */
|
||||
#define RDC_CONF_HARDWARE_CSMA 1
|
||||
/* Allow MCU sleeping between channel checks */
|
||||
#define RDC_CONF_MCU_SLEEP 0
|
||||
#else
|
||||
#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally
|
||||
#endif /*RF230BB */
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
|
|
|
@ -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) */
|
||||
/* 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
|
||||
#define LINKADDR_CONF_SIZE 8
|
||||
#define UIP_CONF_ICMP6 1
|
||||
|
|
|
@ -85,7 +85,6 @@ void clock_adjust_ticks(clock_time_t howmany);
|
|||
#define CLIF
|
||||
|
||||
#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 */
|
||||
//#define NETSTACK_CONF_NETWORK rime_driver
|
||||
|
|
|
@ -88,7 +88,6 @@ void clock_adjust_ticks(clock_time_t howmany);
|
|||
#endif
|
||||
|
||||
#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
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
|
@ -100,7 +99,6 @@ void clock_adjust_ticks(clock_time_t howmany);
|
|||
/* The new NETSTACK interface requires RF230BB */
|
||||
#if RF230BB
|
||||
#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
|
||||
|
||||
/* No radio cycling */
|
||||
|
@ -126,7 +124,6 @@ void clock_adjust_ticks(clock_time_t howmany);
|
|||
|
||||
#else
|
||||
/* Original combined RF230/mac code will not compile with current contiki stack */
|
||||
//#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 handles headers internally
|
||||
//FTH081105
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#define SICSLOWPAN_CONF_MAXAGE 5
|
||||
|
|
Loading…
Reference in a new issue