From d478c0f7f15fc884914c2cfc164588e43152f882 Mon Sep 17 00:00:00 2001 From: Konrad Krentz Date: Fri, 17 Jul 2015 05:40:45 -0700 Subject: [PATCH 1/7] packetbuf: Deleted functions that are never called --- core/net/packetbuf.c | 29 ----------------------------- core/net/packetbuf.h | 31 ------------------------------- 2 files changed, 60 deletions(-) diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index c7e2a9898..3cc2e1ac7 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -83,12 +83,6 @@ packetbuf_clear(void) packetbuf_attr_clear(); } /*---------------------------------------------------------------------------*/ -void -packetbuf_clear_hdr(void) -{ - hdrptr = PACKETBUF_HDR_SIZE; -} -/*---------------------------------------------------------------------------*/ int packetbuf_copyfrom(const void *from, uint16_t len) { @@ -117,23 +111,6 @@ packetbuf_compact(void) } /*---------------------------------------------------------------------------*/ int -packetbuf_copyto_hdr(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]); - } - PRINTF("\n"); - } -#endif /* DEBUG_LEVEL */ - memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr); - return PACKETBUF_HDR_SIZE - hdrptr; -} -/*---------------------------------------------------------------------------*/ -int packetbuf_copyto(void *to) { #if DEBUG_LEVEL > 0 @@ -176,12 +153,6 @@ packetbuf_hdralloc(int size) return 0; } /*---------------------------------------------------------------------------*/ -void -packetbuf_hdr_remove(int size) -{ - hdrptr += size; -} -/*---------------------------------------------------------------------------*/ int packetbuf_hdrreduce(int size) { diff --git a/core/net/packetbuf.h b/core/net/packetbuf.h index 12b0d9dce..fe3472536 100644 --- a/core/net/packetbuf.h +++ b/core/net/packetbuf.h @@ -92,21 +92,6 @@ */ void packetbuf_clear(void); -/** - * \brief Clear and reset the header of the packetbuf - * - * This function clears the header of the packetbuf and - * resets all the internal state pointers pertaining to - * the header (header size, header pointer, but not - * external data pointer). It is used before after sending - * a packet in the packetbuf, to be able to reuse the - * packet buffer for a later retransmission. - * - */ -void packetbuf_clear_hdr(void); - -void packetbuf_hdr_remove(int bytes); - /** * \brief Get a pointer to the data in the packetbuf * \return Pointer to the packetbuf data @@ -235,22 +220,6 @@ int packetbuf_copyfrom(const void *from, uint16_t len); */ int packetbuf_copyto(void *to); -/** - * \brief Copy the header portion of the packetbuf to an external buffer - * \param to A pointer to the buffer to which the data is to be copied - * \retval The number of bytes that was copied to the external buffer - * - * This function copies the header portion of the packetbuf - * to an external buffer. - * - * The external buffer to which the packetbuf is to be - * copied must be able to accomodate at least - * PACKETBUF_HDR_SIZE bytes. The number of bytes that was - * copied to the external buffer is returned. - * - */ -int packetbuf_copyto_hdr(uint8_t *to); - /** * \brief Extend the header of the packetbuf, for outbound packets * \param size The number of bytes the header should be extended From a1b91d8b59398249816e67f89fc8553e194cff16 Mon Sep 17 00:00:00 2001 From: kkrentz Date: Wed, 3 Feb 2016 06:41:15 -0800 Subject: [PATCH 2/7] packetbuf: Removed commented code --- core/net/packetbuf.c | 2 -- core/net/packetbuf.h | 4 ---- 2 files changed, 6 deletions(-) diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index 3cc2e1ac7..774ff2f60 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -243,7 +243,6 @@ packetbuf_attr_copyfrom(struct packetbuf_attr *attrs, int packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val) { -/* packetbuf_attrs[type].type = type; */ packetbuf_attrs[type].val = val; return 1; } @@ -257,7 +256,6 @@ packetbuf_attr(uint8_t type) int packetbuf_set_addr(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); return 1; } diff --git a/core/net/packetbuf.h b/core/net/packetbuf.h index fe3472536..cca365f6e 100644 --- a/core/net/packetbuf.h +++ b/core/net/packetbuf.h @@ -253,11 +253,9 @@ int packetbuf_hdrreduce(int size); typedef uint16_t packetbuf_attr_t; struct packetbuf_attr { -/* uint8_t type; */ packetbuf_attr_t val; }; struct packetbuf_addr { -/* uint8_t type; */ linkaddr_t addr; }; @@ -380,7 +378,6 @@ static const linkaddr_t *packetbuf_addr(uint8_t type); static inline int packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val) { -/* packetbuf_attrs[type].type = type; */ packetbuf_attrs[type].val = val; return 1; } @@ -393,7 +390,6 @@ packetbuf_attr(uint8_t type) static inline int packetbuf_set_addr(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); return 1; } From 11c03eef797ed03820374fc307010c0d76eb636e Mon Sep 17 00:00:00 2001 From: kkrentz Date: Wed, 3 Feb 2016 06:42:18 -0800 Subject: [PATCH 3/7] packetbuf: Removed function prototypes --- core/net/packetbuf.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/net/packetbuf.h b/core/net/packetbuf.h index cca365f6e..0afd02a74 100644 --- a/core/net/packetbuf.h +++ b/core/net/packetbuf.h @@ -370,11 +370,6 @@ enum { extern struct packetbuf_attr packetbuf_attrs[]; extern struct packetbuf_addr packetbuf_addrs[]; -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 inline int packetbuf_set_attr(uint8_t type, const packetbuf_attr_t val) { From 1014018c2d5fa4a61b57f7ba6f56f7ffc18f6029 Mon Sep 17 00:00:00 2001 From: kkrentz Date: Wed, 3 Feb 2016 08:08:12 -0800 Subject: [PATCH 4/7] packetbuf: Removed debugging stuff --- core/net/packetbuf.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index 774ff2f60..cfc831fd8 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -113,26 +113,6 @@ packetbuf_compact(void) int packetbuf_copyto(void *to) { -#if DEBUG_LEVEL > 0 - { - int i; - char buffer[1000]; - char *bufferptr = buffer; - int bufferlen = 0; - - bufferptr[0] = 0; - for(i = hdrptr; i < PACKETBUF_HDR_SIZE; ++i) { - bufferptr += sprintf(bufferptr, "0x%02x, ", packetbuf[i]); - } - PRINTF("packetbuf_write: header: %s\n", buffer); - bufferptr = buffer; - bufferptr[0] = 0; - for(i = bufptr; ((i < buflen + bufptr) && (bufferlen < (sizeof(buffer) - 10))); ++i) { - bufferlen += sprintf(bufferptr + bufferlen, "0x%02x, ", packetbufptr[i]); - } - PRINTF("packetbuf_write: data: %s\n", buffer); - } -#endif /* DEBUG_LEVEL */ if(PACKETBUF_HDR_SIZE - hdrptr + buflen > PACKETBUF_SIZE) { /* Too large packet */ return 0; From 3d79292e441fe66e78b161f8963481f0eb6c2067 Mon Sep 17 00:00:00 2001 From: kkrentz Date: Wed, 3 Feb 2016 07:59:22 -0800 Subject: [PATCH 5/7] packetbuf: Simplified packetbuf_attr_clear --- core/net/packetbuf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index cfc831fd8..1e6b9a57f 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -195,9 +195,7 @@ void packetbuf_attr_clear(void) { int i; - for(i = 0; i < PACKETBUF_NUM_ATTRS; ++i) { - packetbuf_attrs[i].val = 0; - } + memset(packetbuf_attrs, 0, sizeof(packetbuf_attrs)); for(i = 0; i < PACKETBUF_NUM_ADDRS; ++i) { linkaddr_copy(&packetbuf_addrs[i].addr, &linkaddr_null); } From 0af4a18c09d6759f8285e017c216b04b8c2414ac Mon Sep 17 00:00:00 2001 From: kkrentz Date: Wed, 3 Feb 2016 08:09:13 -0800 Subject: [PATCH 6/7] packetbuf: Use MIN macro --- core/net/packetbuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index 1e6b9a57f..a2f295816 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -47,6 +47,7 @@ #include "contiki-net.h" #include "net/packetbuf.h" #include "net/rime/rime.h" +#include "sys/cc.h" struct packetbuf_attr packetbuf_attrs[PACKETBUF_NUM_ATTRS]; struct packetbuf_addr packetbuf_addrs[PACKETBUF_NUM_ADDRS]; @@ -89,7 +90,7 @@ packetbuf_copyfrom(const void *from, uint16_t len) uint16_t l; packetbuf_clear(); - l = len > PACKETBUF_SIZE? PACKETBUF_SIZE: len; + l = MIN(PACKETBUF_SIZE, len); memcpy(packetbufptr, from, l); buflen = l; return l; From 6fb6fd5bb9639941d141028ac205f89b9d4a7c8a Mon Sep 17 00:00:00 2001 From: kkrentz Date: Thu, 4 Feb 2016 03:25:47 -0800 Subject: [PATCH 7/7] packetbuf: No more splitting of header and data --- core/net/packetbuf.c | 62 ++++++++++++---------------- core/net/packetbuf.h | 46 +-------------------- platform/avr-raven/contiki-conf.h | 3 -- platform/avr-ravenusb/contiki-conf.h | 5 --- platform/avr-rcb/contiki-conf.h | 1 - platform/avr-zigbit/contiki-conf.h | 3 -- 6 files changed, 28 insertions(+), 92 deletions(-) diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index a2f295816..4869263cf 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -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 @@ -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 diff --git a/core/net/packetbuf.h b/core/net/packetbuf.h index 0afd02a74..3d6386d26 100644 --- a/core/net/packetbuf.h +++ b/core/net/packetbuf.h @@ -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. * diff --git a/platform/avr-raven/contiki-conf.h b/platform/avr-raven/contiki-conf.h index ab770540d..45ea5fb22 100644 --- a/platform/avr-raven/contiki-conf.h +++ b/platform/avr-raven/contiki-conf.h @@ -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 diff --git a/platform/avr-ravenusb/contiki-conf.h b/platform/avr-ravenusb/contiki-conf.h index 71d56e248..8eab7cce9 100644 --- a/platform/avr-ravenusb/contiki-conf.h +++ b/platform/avr-ravenusb/contiki-conf.h @@ -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 diff --git a/platform/avr-rcb/contiki-conf.h b/platform/avr-rcb/contiki-conf.h index 298a33cd0..68ce8f3b6 100644 --- a/platform/avr-rcb/contiki-conf.h +++ b/platform/avr-rcb/contiki-conf.h @@ -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 diff --git a/platform/avr-zigbit/contiki-conf.h b/platform/avr-zigbit/contiki-conf.h index f84df8863..c01c6555c 100644 --- a/platform/avr-zigbit/contiki-conf.h +++ b/platform/avr-zigbit/contiki-conf.h @@ -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