UbixOS  2.0
pbuf.c
Go to the documentation of this file.
1 
80 /*
81  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
82  * All rights reserved.
83  *
84  * Redistribution and use in source and binary forms, with or without modification,
85  * are permitted provided that the following conditions are met:
86  *
87  * 1. Redistributions of source code must retain the above copyright notice,
88  * this list of conditions and the following disclaimer.
89  * 2. Redistributions in binary form must reproduce the above copyright notice,
90  * this list of conditions and the following disclaimer in the documentation
91  * and/or other materials provided with the distribution.
92  * 3. The name of the author may not be used to endorse or promote products
93  * derived from this software without specific prior written permission.
94  *
95  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
96  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
97  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
98  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
99  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
100  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
101  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
102  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
103  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
104  * OF SUCH DAMAGE.
105  *
106  * This file is part of the lwIP TCP/IP stack.
107  *
108  * Author: Adam Dunkels <adam@sics.se>
109  *
110  */
111 
112 #include "net/opt.h"
113 
114 #include "net/stats.h"
115 #include "net/def.h"
116 #include "net/mem.h"
117 #include "net/memp.h"
118 #include "net/pbuf.h"
119 #include "net/sys.h"
120 #if LWIP_TCP && TCP_QUEUE_OOSEQ
121 #include "net/priv/tcp_priv.h"
122 #endif
123 #if LWIP_CHECKSUM_ON_COPY
124 #include "net/inet_chksum.h"
125 #endif
126 
127 #include <string.h>
128 
129 #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
130 /* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically
131  aligned there. Therefore, PBUF_POOL_BUFSIZE_ALIGNED can be used here. */
132 #define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)
133 
134 #if !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ
135 #define PBUF_POOL_IS_EMPTY()
136 #else /* !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ */
137 
138 #if !NO_SYS
139 #ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
140 #include "net/tcpip.h"
141 #define PBUF_POOL_FREE_OOSEQ_QUEUE_CALL() do { \
142  if (tcpip_callback_with_block(pbuf_free_ooseq_callback, NULL, 0) != ERR_OK) { \
143  SYS_ARCH_PROTECT(old_level); \
144  pbuf_free_ooseq_pending = 0; \
145  SYS_ARCH_UNPROTECT(old_level); \
146  } } while(0)
147 #endif /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
148 #endif /* !NO_SYS */
149 
150 volatile u8_t pbuf_free_ooseq_pending;
151 #define PBUF_POOL_IS_EMPTY() pbuf_pool_is_empty()
152 
161 #if !NO_SYS
162 static
163 #endif /* !NO_SYS */
164 void
165 pbuf_free_ooseq(void)
166 {
167  struct tcp_pcb* pcb;
168  SYS_ARCH_SET(pbuf_free_ooseq_pending, 0);
169 
170  for (pcb = tcp_active_pcbs; NULL != pcb; pcb = pcb->next) {
171  if (NULL != pcb->ooseq) {
173  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free_ooseq: freeing out-of-sequence pbufs\n"));
174  tcp_segs_free(pcb->ooseq);
175  pcb->ooseq = NULL;
176  return;
177  }
178  }
179 }
180 
181 #if !NO_SYS
182 
185 static void
186 pbuf_free_ooseq_callback(void *arg)
187 {
188  LWIP_UNUSED_ARG(arg);
189  pbuf_free_ooseq();
190 }
191 #endif /* !NO_SYS */
192 
194 static void
195 pbuf_pool_is_empty(void)
196 {
197 #ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
198  SYS_ARCH_SET(pbuf_free_ooseq_pending, 1);
199 #else /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
200  u8_t queued;
201  SYS_ARCH_DECL_PROTECT(old_level);
202  SYS_ARCH_PROTECT(old_level);
203  queued = pbuf_free_ooseq_pending;
204  pbuf_free_ooseq_pending = 1;
205  SYS_ARCH_UNPROTECT(old_level);
206 
207  if (!queued) {
208  /* queue a call to pbuf_free_ooseq if not already queued */
209  PBUF_POOL_FREE_OOSEQ_QUEUE_CALL();
210  }
211 #endif /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
212 }
213 #endif /* !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ */
214 
247 struct pbuf *
249 {
250  struct pbuf *p, *q, *r;
251  u16_t offset;
252  s32_t rem_len; /* remaining length */
253  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F")\n", length));
254 
255  /* determine header offset */
256  switch (layer) {
257  case PBUF_TRANSPORT:
258  /* add room for transport (often TCP) layer header */
260  break;
261  case PBUF_IP:
262  /* add room for IP layer header */
264  break;
265  case PBUF_LINK:
266  /* add room for link layer header */
268  break;
269  case PBUF_RAW_TX:
270  /* add room for encapsulating link layer headers (e.g. 802.11) */
272  break;
273  case PBUF_RAW:
274  /* no offset (e.g. RX buffers or chain successors) */
275  offset = 0;
276  break;
277  default:
278  LWIP_ASSERT("pbuf_alloc: bad pbuf layer", 0);
279  return NULL;
280  }
281 
282  switch (type) {
283  case PBUF_POOL:
284  /* allocate head of pbuf chain into p */
285  p = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
286  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
287  if (p == NULL) {
289  return NULL;
290  }
291  p->type = type;
292  p->next = NULL;
293 
294  /* make the payload pointer point 'offset' bytes into pbuf data memory */
295  p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset)));
296  LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned",
297  ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
298  /* the total length of the pbuf chain is the requested size */
299  p->tot_len = length;
300  /* set the length of the first pbuf in the chain */
301  p->len = LWIP_MIN(length, PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset));
302  LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
303  ((u8_t*)p->payload + p->len <=
305  LWIP_ASSERT("PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
307  /* set reference count (needed here in case we fail) */
308  p->ref = 1;
309 
310  /* now allocate the tail of the pbuf chain */
311 
312  /* remember first pbuf for linkage in next iteration */
313  r = p;
314  /* remaining length to be allocated */
315  rem_len = length - p->len;
316  /* any remaining pbufs to be allocated? */
317  while (rem_len > 0) {
318  q = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
319  if (q == NULL) {
321  /* free chain so far allocated */
322  pbuf_free(p);
323  /* bail out unsuccessfully */
324  return NULL;
325  }
326  q->type = type;
327  q->flags = 0;
328  q->next = NULL;
329  /* make previous pbuf point to this pbuf */
330  r->next = q;
331  /* set total length of this pbuf and next in chain */
332  LWIP_ASSERT("rem_len < max_u16_t", rem_len < 0xffff);
333  q->tot_len = (u16_t)rem_len;
334  /* this pbuf length is pool size, unless smaller sized tail */
336  q->payload = (void *)((u8_t *)q + SIZEOF_STRUCT_PBUF);
337  LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
338  ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0);
339  LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
340  ((u8_t*)p->payload + p->len <=
342  q->ref = 1;
343  /* calculate remaining length to be allocated */
344  rem_len -= q->len;
345  /* remember this pbuf for linkage in next iteration */
346  r = q;
347  }
348  /* end of chain */
349  /*r->next = NULL;*/
350 
351  break;
352  case PBUF_RAM:
353  {
355 
356  /* bug #50040: Check for integer overflow when calculating alloc_len */
357  if (alloc_len < LWIP_MEM_ALIGN_SIZE(length)) {
358  return NULL;
359  }
360 
361  /* If pbuf is to be allocated in RAM, allocate memory for it. */
362  p = (struct pbuf*)mem_malloc(alloc_len);
363  }
364 
365  if (p == NULL) {
366  return NULL;
367  }
368  /* Set up internal structure of the pbuf. */
369  p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
370  p->len = p->tot_len = length;
371  p->next = NULL;
372  p->type = type;
373 
374  LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
375  ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
376  break;
377  /* pbuf references existing (non-volatile static constant) ROM payload? */
378  case PBUF_ROM:
379  /* pbuf references existing (externally allocated) RAM payload? */
380  case PBUF_REF:
381  /* only allocate memory for the pbuf structure */
382  p = (struct pbuf *)memp_malloc(MEMP_PBUF);
383  if (p == NULL) {
385  ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
386  (type == PBUF_ROM) ? "ROM" : "REF"));
387  return NULL;
388  }
389  /* caller must set this field properly, afterwards */
390  p->payload = NULL;
391  p->len = p->tot_len = length;
392  p->next = NULL;
393  p->type = type;
394  break;
395  default:
396  LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
397  return NULL;
398  }
399  /* set reference count */
400  p->ref = 1;
401  /* set flags */
402  p->flags = 0;
403  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
404  return p;
405 }
406 
407 #if LWIP_SUPPORT_CUSTOM_PBUF
408 
424 struct pbuf*
425 pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p,
426  void *payload_mem, u16_t payload_mem_len)
427 {
428  u16_t offset;
429  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloced_custom(length=%"U16_F")\n", length));
430 
431  /* determine header offset */
432  switch (l) {
433  case PBUF_TRANSPORT:
434  /* add room for transport (often TCP) layer header */
436  break;
437  case PBUF_IP:
438  /* add room for IP layer header */
440  break;
441  case PBUF_LINK:
442  /* add room for link layer header */
444  break;
445  case PBUF_RAW_TX:
446  /* add room for encapsulating link layer headers (e.g. 802.11) */
448  break;
449  case PBUF_RAW:
450  offset = 0;
451  break;
452  default:
453  LWIP_ASSERT("pbuf_alloced_custom: bad pbuf layer", 0);
454  return NULL;
455  }
456 
457  if (LWIP_MEM_ALIGN_SIZE(offset) + length > payload_mem_len) {
458  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_WARNING, ("pbuf_alloced_custom(length=%"U16_F") buffer too short\n", length));
459  return NULL;
460  }
461 
462  p->pbuf.next = NULL;
463  if (payload_mem != NULL) {
464  p->pbuf.payload = (u8_t *)payload_mem + LWIP_MEM_ALIGN_SIZE(offset);
465  } else {
466  p->pbuf.payload = NULL;
467  }
468  p->pbuf.flags = PBUF_FLAG_IS_CUSTOM;
469  p->pbuf.len = p->pbuf.tot_len = length;
470  p->pbuf.type = type;
471  p->pbuf.ref = 1;
472  return &p->pbuf;
473 }
474 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
475 
492 void
493 pbuf_realloc(struct pbuf *p, u16_t new_len)
494 {
495  struct pbuf *q;
496  u16_t rem_len; /* remaining length */
497  s32_t grow;
498 
499  LWIP_ASSERT("pbuf_realloc: p != NULL", p != NULL);
500  LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_POOL ||
501  p->type == PBUF_ROM ||
502  p->type == PBUF_RAM ||
503  p->type == PBUF_REF);
504 
505  /* desired length larger than current length? */
506  if (new_len >= p->tot_len) {
507  /* enlarging not yet supported */
508  return;
509  }
510 
511  /* the pbuf chain grows by (new_len - p->tot_len) bytes
512  * (which may be negative in case of shrinking) */
513  grow = new_len - p->tot_len;
514 
515  /* first, step over any pbufs that should remain in the chain */
516  rem_len = new_len;
517  q = p;
518  /* should this pbuf be kept? */
519  while (rem_len > q->len) {
520  /* decrease remaining length by pbuf length */
521  rem_len -= q->len;
522  /* decrease total length indicator */
523  LWIP_ASSERT("grow < max_u16_t", grow < 0xffff);
524  q->tot_len += (u16_t)grow;
525  /* proceed to next pbuf in chain */
526  q = q->next;
527  LWIP_ASSERT("pbuf_realloc: q != NULL", q != NULL);
528  }
529  /* we have now reached the new last pbuf (in q) */
530  /* rem_len == desired length for pbuf q */
531 
532  /* shrink allocated memory for PBUF_RAM */
533  /* (other types merely adjust their length fields */
534  if ((q->type == PBUF_RAM) && (rem_len != q->len)
536  && ((q->flags & PBUF_FLAG_IS_CUSTOM) == 0)
537 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
538  ) {
539  /* reallocate and adjust the length of the pbuf that will be split */
540  q = (struct pbuf *)mem_trim(q, (u16_t)((u8_t *)q->payload - (u8_t *)q) + rem_len);
541  LWIP_ASSERT("mem_trim returned q == NULL", q != NULL);
542  }
543  /* adjust length fields for new last pbuf */
544  q->len = rem_len;
545  q->tot_len = q->len;
546 
547  /* any remaining pbufs in chain? */
548  if (q->next != NULL) {
549  /* free remaining pbufs in chain */
550  pbuf_free(q->next);
551  }
552  /* q is last packet in chain */
553  q->next = NULL;
554 
555 }
556 
568 static u8_t
569 pbuf_header_impl(struct pbuf *p, s16_t header_size_increment, u8_t force)
570 {
571  u16_t type;
572  void *payload;
573  u16_t increment_magnitude;
574 
575  LWIP_ASSERT("p != NULL", p != NULL);
576  if ((header_size_increment == 0) || (p == NULL)) {
577  return 0;
578  }
579 
580  if (header_size_increment < 0) {
581  increment_magnitude = (u16_t)-header_size_increment;
582  /* Check that we aren't going to move off the end of the pbuf */
583  LWIP_ERROR("increment_magnitude <= p->len", (increment_magnitude <= p->len), return 1;);
584  } else {
585  increment_magnitude = (u16_t)header_size_increment;
586 #if 0
587  /* Can't assert these as some callers speculatively call
588  pbuf_header() to see if it's OK. Will return 1 below instead. */
589  /* Check that we've got the correct type of pbuf to work with */
590  LWIP_ASSERT("p->type == PBUF_RAM || p->type == PBUF_POOL",
591  p->type == PBUF_RAM || p->type == PBUF_POOL);
592  /* Check that we aren't going to move off the beginning of the pbuf */
593  LWIP_ASSERT("p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
594  (u8_t *)p->payload - increment_magnitude >= (u8_t *)p + SIZEOF_STRUCT_PBUF);
595 #endif
596  }
597 
598  type = p->type;
599  /* remember current payload pointer */
600  payload = p->payload;
601 
602  /* pbuf types containing payloads? */
603  if (type == PBUF_RAM || type == PBUF_POOL) {
604  /* set new payload pointer */
605  p->payload = (u8_t *)p->payload - header_size_increment;
606  /* boundary check fails? */
607  if ((u8_t *)p->payload < (u8_t *)p + SIZEOF_STRUCT_PBUF) {
609  ("pbuf_header: failed as %p < %p (not enough space for new header size)\n",
610  (void *)p->payload, (void *)((u8_t *)p + SIZEOF_STRUCT_PBUF)));
611  /* restore old payload pointer */
612  p->payload = payload;
613  /* bail out unsuccessfully */
614  return 1;
615  }
616  /* pbuf types referring to external payloads? */
617  } else if (type == PBUF_REF || type == PBUF_ROM) {
618  /* hide a header in the payload? */
619  if ((header_size_increment < 0) && (increment_magnitude <= p->len)) {
620  /* increase payload pointer */
621  p->payload = (u8_t *)p->payload - header_size_increment;
622  } else if ((header_size_increment > 0) && force) {
623  p->payload = (u8_t *)p->payload - header_size_increment;
624  } else {
625  /* cannot expand payload to front (yet!)
626  * bail out unsuccessfully */
627  return 1;
628  }
629  } else {
630  /* Unknown type */
631  LWIP_ASSERT("bad pbuf type", 0);
632  return 1;
633  }
634  /* modify pbuf length fields */
635  p->len += header_size_increment;
636  p->tot_len += header_size_increment;
637 
638  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_header: old %p new %p (%"S16_F")\n",
639  (void *)payload, (void *)p->payload, header_size_increment));
640 
641  return 0;
642 }
643 
664 u8_t
665 pbuf_header(struct pbuf *p, s16_t header_size_increment)
666 {
667  return pbuf_header_impl(p, header_size_increment, 0);
668 }
669 
674 u8_t
675 pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
676 {
677  return pbuf_header_impl(p, header_size_increment, 1);
678 }
679 
714 u8_t
715 pbuf_free(struct pbuf *p)
716 {
717  u16_t type;
718  struct pbuf *q;
719  u8_t count;
720 
721  if (p == NULL) {
722  LWIP_ASSERT("p != NULL", p != NULL);
723  /* if assertions are disabled, proceed with debug output */
725  ("pbuf_free(p == NULL) was called.\n"));
726  return 0;
727  }
728 
729  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p));
730 
731  PERF_START;
732 
733  LWIP_ASSERT("pbuf_free: sane type", p->type == PBUF_RAM || p->type == PBUF_ROM || p->type == PBUF_REF || p->type == PBUF_POOL);
734 
735  count = 0;
736  /* de-allocate all consecutive pbufs from the head of the chain that
737  * obtain a zero reference count after decrementing*/
738 
739  while (p != NULL) {
740  u16_t ref;
741  SYS_ARCH_DECL_PROTECT(old_level);
742  /* Since decrementing ref cannot be guaranteed to be a single machine operation
743  * we must protect it. We put the new ref into a local variable to prevent
744  * further protection. */
745  SYS_ARCH_PROTECT(old_level);
746  /* all pbufs in a chain are referenced at least once */
747  if (_current->id == 4)
748  LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
749  /* decrease reference count (number of pointers to pbuf) */
750  ref = --(p->ref);
751  SYS_ARCH_UNPROTECT(old_level);
752  /* this pbuf is no longer referenced to? */
753  if (ref == 0) {
754  /* remember next pbuf in chain for next iteration */
755  q = p->next;
756  LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: deallocating %p\n", (void *)p));
757  type = p->type;
758 #if LWIP_SUPPORT_CUSTOM_PBUF
759  /* is this a custom pbuf? */
760  if ((p->flags & PBUF_FLAG_IS_CUSTOM) != 0) {
761  struct pbuf_custom *pc = (struct pbuf_custom*)p;
762  LWIP_ASSERT("pc->custom_free_function != NULL", pc->custom_free_function != NULL);
763  pc->custom_free_function(p);
764  } else
765 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
766  {
767  /* is this a pbuf from the pool? */
768  if (type == PBUF_POOL) {
769  memp_free(MEMP_PBUF_POOL, p);
770  /* is this a ROM or RAM referencing pbuf? */
771  } else if (type == PBUF_ROM || type == PBUF_REF) {
772  memp_free(MEMP_PBUF, p);
773  /* type == PBUF_RAM */
774  } else {
775  mem_free(p);
776  }
777  }
778  count++;
779  /* proceed to next pbuf */
780  p = q;
781  /* p->ref > 0, this pbuf is still referenced to */
782  /* (and so the remaining pbufs in chain as well) */
783  } else {
784  LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, ref));
785  /* stop walking through the chain */
786  p = NULL;
787  }
788  }
789  PERF_STOP("pbuf_free");
790  /* return number of de-allocated pbufs */
791  return count;
792 }
793 
800 u16_t
801 pbuf_clen(const struct pbuf *p)
802 {
803  u16_t len;
804 
805  len = 0;
806  while (p != NULL) {
807  ++len;
808  p = p->next;
809  }
810  return len;
811 }
812 
820 void
821 pbuf_ref(struct pbuf *p)
822 {
823  /* pbuf given? */
824  if (p != NULL) {
825  SYS_ARCH_INC(p->ref, 1);
826  LWIP_ASSERT("pbuf ref overflow", p->ref > 0);
827  }
828 }
829 
840 void
841 pbuf_cat(struct pbuf *h, struct pbuf *t)
842 {
843  struct pbuf *p;
844 
845  LWIP_ERROR("(h != NULL) && (t != NULL) (programmer violates API)",
846  ((h != NULL) && (t != NULL)), return;);
847 
848  /* proceed to last pbuf of chain */
849  for (p = h; p->next != NULL; p = p->next) {
850  /* add total length of second chain to all totals of first chain */
851  p->tot_len += t->tot_len;
852  }
853  /* { p is last pbuf of first h chain, p->next == NULL } */
854  LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len);
855  LWIP_ASSERT("p->next == NULL", p->next == NULL);
856  /* add total length of second chain to last pbuf total of first chain */
857  p->tot_len += t->tot_len;
858  /* chain last pbuf of head (p) with first of tail (t) */
859  p->next = t;
860  /* p->next now references t, but the caller will drop its reference to t,
861  * so netto there is no change to the reference count of t.
862  */
863 }
864 
882 void
883 pbuf_chain(struct pbuf *h, struct pbuf *t)
884 {
885  pbuf_cat(h, t);
886  /* t is now referenced by h */
887  pbuf_ref(t);
888  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t));
889 }
890 
899 struct pbuf *
900 pbuf_dechain(struct pbuf *p)
901 {
902  struct pbuf *q;
903  u8_t tail_gone = 1;
904  /* tail */
905  q = p->next;
906  /* pbuf has successor in chain? */
907  if (q != NULL) {
908  /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
909  LWIP_ASSERT("p->tot_len == p->len + q->tot_len", q->tot_len == p->tot_len - p->len);
910  /* enforce invariant if assertion is disabled */
911  q->tot_len = p->tot_len - p->len;
912  /* decouple pbuf from remainder */
913  p->next = NULL;
914  /* total length of pbuf p is its own length only */
915  p->tot_len = p->len;
916  /* q is no longer referenced by p, free it */
917  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_dechain: unreferencing %p\n", (void *)q));
918  tail_gone = pbuf_free(q);
919  if (tail_gone > 0) {
921  ("pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (void *)q));
922  }
923  /* return remaining tail or NULL if deallocated */
924  }
925  /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
926  LWIP_ASSERT("p->tot_len == p->len", p->tot_len == p->len);
927  return ((tail_gone > 0) ? NULL : q);
928 }
929 
948 err_t
949 pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
950 {
951  u16_t offset_to=0, offset_from=0, len;
952 
953  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n",
954  (const void*)p_to, (const void*)p_from));
955 
956  /* is the target big enough to hold the source? */
957  LWIP_ERROR("pbuf_copy: target not big enough to hold source", ((p_to != NULL) &&
958  (p_from != NULL) && (p_to->tot_len >= p_from->tot_len)), return ERR_ARG;);
959 
960  /* iterate through pbuf chain */
961  do
962  {
963  /* copy one part of the original chain */
964  if ((p_to->len - offset_to) >= (p_from->len - offset_from)) {
965  /* complete current p_from fits into current p_to */
966  len = p_from->len - offset_from;
967  } else {
968  /* current p_from does not fit into current p_to */
969  len = p_to->len - offset_to;
970  }
971  MEMCPY((u8_t*)p_to->payload + offset_to, (u8_t*)p_from->payload + offset_from, len);
972  offset_to += len;
973  offset_from += len;
974  LWIP_ASSERT("offset_to <= p_to->len", offset_to <= p_to->len);
975  LWIP_ASSERT("offset_from <= p_from->len", offset_from <= p_from->len);
976  if (offset_from >= p_from->len) {
977  /* on to next p_from (if any) */
978  offset_from = 0;
979  p_from = p_from->next;
980  }
981  if (offset_to == p_to->len) {
982  /* on to next p_to (if any) */
983  offset_to = 0;
984  p_to = p_to->next;
985  LWIP_ERROR("p_to != NULL", (p_to != NULL) || (p_from == NULL) , return ERR_ARG;);
986  }
987 
988  if ((p_from != NULL) && (p_from->len == p_from->tot_len)) {
989  /* don't copy more than one packet! */
990  LWIP_ERROR("pbuf_copy() does not allow packet queues!",
991  (p_from->next == NULL), return ERR_VAL;);
992  }
993  if ((p_to != NULL) && (p_to->len == p_to->tot_len)) {
994  /* don't copy more than one packet! */
995  LWIP_ERROR("pbuf_copy() does not allow packet queues!",
996  (p_to->next == NULL), return ERR_VAL;);
997  }
998  } while (p_from);
999  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy: end of chain reached.\n"));
1000  return ERR_OK;
1001 }
1002 
1015 u16_t
1016 pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
1017 {
1018  const struct pbuf *p;
1019  u16_t left;
1020  u16_t buf_copy_len;
1021  u16_t copied_total = 0;
1022 
1023  LWIP_ERROR("pbuf_copy_partial: invalid buf", (buf != NULL), return 0;);
1024  LWIP_ERROR("pbuf_copy_partial: invalid dataptr", (dataptr != NULL), return 0;);
1025 
1026  left = 0;
1027 
1028  if ((buf == NULL) || (dataptr == NULL)) {
1029  return 0;
1030  }
1031 
1032  /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
1033  for (p = buf; len != 0 && p != NULL; p = p->next) {
1034  if ((offset != 0) && (offset >= p->len)) {
1035  /* don't copy from this buffer -> on to the next */
1036  offset -= p->len;
1037  } else {
1038  /* copy from this buffer. maybe only partially. */
1039  buf_copy_len = p->len - offset;
1040  if (buf_copy_len > len) {
1041  buf_copy_len = len;
1042  }
1043  /* copy the necessary parts of the buffer */
1044  MEMCPY(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
1045  copied_total += buf_copy_len;
1046  left += buf_copy_len;
1047  len -= buf_copy_len;
1048  offset = 0;
1049  }
1050  }
1051  return copied_total;
1052 }
1053 
1054 #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
1055 
1067 void pbuf_split_64k(struct pbuf *p, struct pbuf **rest)
1068 {
1069  *rest = NULL;
1070  if ((p != NULL) && (p->next != NULL)) {
1071  u16_t tot_len_front = p->len;
1072  struct pbuf *i = p;
1073  struct pbuf *r = p->next;
1074 
1075  /* continue until the total length (summed up as u16_t) overflows */
1076  while ((r != NULL) && ((u16_t)(tot_len_front + r->len) > tot_len_front)) {
1077  tot_len_front += r->len;
1078  i = r;
1079  r = r->next;
1080  }
1081  /* i now points to last packet of the first segment. Set next
1082  pointer to NULL */
1083  i->next = NULL;
1084 
1085  if (r != NULL) {
1086  /* Update the tot_len field in the first part */
1087  for (i = p; i != NULL; i = i->next) {
1088  i->tot_len -= r->tot_len;
1089  LWIP_ASSERT("tot_len/len mismatch in last pbuf",
1090  (i->next != NULL) || (i->tot_len == i->len));
1091  }
1092  if (p->flags & PBUF_FLAG_TCP_FIN) {
1093  r->flags |= PBUF_FLAG_TCP_FIN;
1094  }
1095 
1096  /* tot_len field in rest does not need modifications */
1097  /* reference counters do not need modifications */
1098  *rest = r;
1099  }
1100  }
1101 }
1102 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1103 
1104 /* Actual implementation of pbuf_skip() but returning const pointer... */
1105 static const struct pbuf*
1106 pbuf_skip_const(const struct pbuf* in, u16_t in_offset, u16_t* out_offset)
1107 {
1108  u16_t offset_left = in_offset;
1109  const struct pbuf* q = in;
1110 
1111  /* get the correct pbuf */
1112  while ((q != NULL) && (q->len <= offset_left)) {
1113  offset_left -= q->len;
1114  q = q->next;
1115  }
1116  if (out_offset != NULL) {
1117  *out_offset = offset_left;
1118  }
1119  return q;
1120 }
1121 
1131 struct pbuf*
1132 pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset)
1133 {
1134  const struct pbuf* out = pbuf_skip_const(in, in_offset, out_offset);
1135  return LWIP_CONST_CAST(struct pbuf*, out);
1136 }
1137 
1149 err_t
1150 pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
1151 {
1152  struct pbuf *p;
1153  u16_t buf_copy_len;
1154  u16_t total_copy_len = len;
1155  u16_t copied_total = 0;
1156 
1157  LWIP_ERROR("pbuf_take: invalid buf", (buf != NULL), return ERR_ARG;);
1158  LWIP_ERROR("pbuf_take: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
1159  LWIP_ERROR("pbuf_take: buf not large enough", (buf->tot_len >= len), return ERR_MEM;);
1160 
1161  if ((buf == NULL) || (dataptr == NULL) || (buf->tot_len < len)) {
1162  return ERR_ARG;
1163  }
1164 
1165  /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
1166  for (p = buf; total_copy_len != 0; p = p->next) {
1167  LWIP_ASSERT("pbuf_take: invalid pbuf", p != NULL);
1168  buf_copy_len = total_copy_len;
1169  if (buf_copy_len > p->len) {
1170  /* this pbuf cannot hold all remaining data */
1171  buf_copy_len = p->len;
1172  }
1173  /* copy the necessary parts of the buffer */
1174  MEMCPY(p->payload, &((const char*)dataptr)[copied_total], buf_copy_len);
1175  total_copy_len -= buf_copy_len;
1176  copied_total += buf_copy_len;
1177  }
1178  LWIP_ASSERT("did not copy all data", total_copy_len == 0 && copied_total == len);
1179  return ERR_OK;
1180 }
1181 
1193 err_t
1194 pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
1195 {
1196  u16_t target_offset;
1197  struct pbuf* q = pbuf_skip(buf, offset, &target_offset);
1198 
1199  /* return requested data if pbuf is OK */
1200  if ((q != NULL) && (q->tot_len >= target_offset + len)) {
1201  u16_t remaining_len = len;
1202  const u8_t* src_ptr = (const u8_t*)dataptr;
1203  /* copy the part that goes into the first pbuf */
1204  u16_t first_copy_len = LWIP_MIN(q->len - target_offset, len);
1205  MEMCPY(((u8_t*)q->payload) + target_offset, dataptr, first_copy_len);
1206  remaining_len -= first_copy_len;
1207  src_ptr += first_copy_len;
1208  if (remaining_len > 0) {
1209  return pbuf_take(q->next, src_ptr, remaining_len);
1210  }
1211  return ERR_OK;
1212  }
1213  return ERR_MEM;
1214 }
1215 
1229 struct pbuf*
1230 pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
1231 {
1232  struct pbuf *q;
1233  err_t err;
1234  if (p->next == NULL) {
1235  return p;
1236  }
1237  q = pbuf_alloc(layer, p->tot_len, PBUF_RAM);
1238  if (q == NULL) {
1239  /* @todo: what do we do now? */
1240  return p;
1241  }
1242  err = pbuf_copy(q, p);
1243  LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
1244  LWIP_ASSERT("pbuf_copy failed", err == ERR_OK);
1245  pbuf_free(p);
1246  return q;
1247 }
1248 
1249 #if LWIP_CHECKSUM_ON_COPY
1250 
1262 err_t
1263 pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
1264  u16_t len, u16_t *chksum)
1265 {
1266  u32_t acc;
1267  u16_t copy_chksum;
1268  char *dst_ptr;
1269  LWIP_ASSERT("p != NULL", p != NULL);
1270  LWIP_ASSERT("dataptr != NULL", dataptr != NULL);
1271  LWIP_ASSERT("chksum != NULL", chksum != NULL);
1272  LWIP_ASSERT("len != 0", len != 0);
1273 
1274  if ((start_offset >= p->len) || (start_offset + len > p->len)) {
1275  return ERR_ARG;
1276  }
1277 
1278  dst_ptr = ((char*)p->payload) + start_offset;
1279  copy_chksum = LWIP_CHKSUM_COPY(dst_ptr, dataptr, len);
1280  if ((start_offset & 1) != 0) {
1281  copy_chksum = SWAP_BYTES_IN_WORD(copy_chksum);
1282  }
1283  acc = *chksum;
1284  acc += copy_chksum;
1285  *chksum = FOLD_U32T(acc);
1286  return ERR_OK;
1287 }
1288 #endif /* LWIP_CHECKSUM_ON_COPY */
1289 
1299 u8_t
1300 pbuf_get_at(const struct pbuf* p, u16_t offset)
1301 {
1302  int ret = pbuf_try_get_at(p, offset);
1303  if (ret >= 0) {
1304  return (u8_t)ret;
1305  }
1306  return 0;
1307 }
1308 
1317 int
1318 pbuf_try_get_at(const struct pbuf* p, u16_t offset)
1319 {
1320  u16_t q_idx;
1321  const struct pbuf* q = pbuf_skip_const(p, offset, &q_idx);
1322 
1323  /* return requested data if pbuf is OK */
1324  if ((q != NULL) && (q->len > q_idx)) {
1325  return ((u8_t*)q->payload)[q_idx];
1326  }
1327  return -1;
1328 }
1329 
1339 void
1340 pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data)
1341 {
1342  u16_t q_idx;
1343  struct pbuf* q = pbuf_skip(p, offset, &q_idx);
1344 
1345  /* write requested data if pbuf is OK */
1346  if ((q != NULL) && (q->len > q_idx)) {
1347  ((u8_t*)q->payload)[q_idx] = data;
1348  }
1349 }
1350 
1362 u16_t
1363 pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n)
1364 {
1365  u16_t start = offset;
1366  const struct pbuf* q = p;
1367  u16_t i;
1368 
1369  /* pbuf long enough to perform check? */
1370  if(p->tot_len < (offset + n)) {
1371  return 0xffff;
1372  }
1373 
1374  /* get the correct pbuf from chain. We know it succeeds because of p->tot_len check above. */
1375  while ((q != NULL) && (q->len <= start)) {
1376  start -= q->len;
1377  q = q->next;
1378  }
1379 
1380  /* return requested data if pbuf is OK */
1381  for (i = 0; i < n; i++) {
1382  /* We know pbuf_get_at() succeeds because of p->tot_len check above. */
1383  u8_t a = pbuf_get_at(q, start + i);
1384  u8_t b = ((const u8_t*)s2)[i];
1385  if (a != b) {
1386  return i+1;
1387  }
1388  }
1389  return 0;
1390 }
1391 
1404 u16_t
1405 pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset)
1406 {
1407  u16_t i;
1408  u16_t max = p->tot_len - mem_len;
1409  if (p->tot_len >= mem_len + start_offset) {
1410  for (i = start_offset; i <= max; i++) {
1411  u16_t plus = pbuf_memcmp(p, i, mem, mem_len);
1412  if (plus == 0) {
1413  return i;
1414  }
1415  }
1416  }
1417  return 0xFFFF;
1418 }
1419 
1431 u16_t
1432 pbuf_strstr(const struct pbuf* p, const char* substr)
1433 {
1434  size_t substr_len;
1435  if ((substr == NULL) || (substr[0] == 0) || (p->tot_len == 0xFFFF)) {
1436  return 0xFFFF;
1437  }
1438  substr_len = strlen(substr);
1439  if (substr_len >= 0xFFFF) {
1440  return 0xFFFF;
1441  }
1442  return pbuf_memfind(p, substr, (u16_t)substr_len, 0);
1443 }
pbuf_memfind
u16_t pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition: pbuf.c:1405
PBUF_POOL
Definition: pbuf.h:123
pbuf_skip
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Definition: pbuf.c:1132
pbuf_try_get_at
int pbuf_try_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1318
PBUF_FLAG_IS_CUSTOM
#define PBUF_FLAG_IS_CUSTOM
Definition: pbuf.h:131
sys.h
S16_F
#define S16_F
Definition: arch.h:151
opt.h
pbuf::len
u16_t len
Definition: pbuf.h:159
PBUF_LINK
Definition: pbuf.h:85
s16_t
int16_t s16_t
Definition: arch.h:125
def.h
SYS_ARCH_SET
#define SYS_ARCH_SET(var, val)
Definition: sys.h:402
PERF_STOP
#define PERF_STOP(x)
Definition: perf.h:21
pbuf::ref
u16_t ref
Definition: pbuf.h:172
PBUF_POOL_IS_EMPTY
#define PBUF_POOL_IS_EMPTY()
Definition: pbuf.c:135
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
tcpip.h
PBUF_ROM
Definition: pbuf.h:112
pbuf.h
PBUF_RAW
Definition: pbuf.h:94
pbuf_strstr
u16_t pbuf_strstr(const struct pbuf *p, const char *substr)
Definition: pbuf.c:1432
mem
Definition: mem.c:264
SYS_ARCH_UNPROTECT
#define SYS_ARCH_UNPROTECT(lev)
Definition: sys.h:363
u16_t
uint16_t u16_t
Definition: arch.h:124
string.h
PERF_START
#define PERF_START
Definition: perf.h:20
PBUF_IP
Definition: pbuf.h:80
pbuf::tot_len
u16_t tot_len
Definition: pbuf.h:156
u32_t
uint32_t u32_t
Definition: arch.h:126
pbuf_take
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1150
pbuf::next
struct pbuf * next
Definition: pbuf.h:144
PBUF_TRANSPORT
Definition: pbuf.h:76
pbuf_free
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:715
SIZEOF_STRUCT_PBUF
#define SIZEOF_STRUCT_PBUF
Definition: pbuf.c:129
strlen
int strlen(const char *str)
Definition: strlen.c:55
PBUF_TRANSPORT_HLEN
#define PBUF_TRANSPORT_HLEN
Definition: pbuf.h:61
memp_malloc
void * memp_malloc(memp_t type)
Definition: memp.c:385
LWIP_DBG_TRACE
#define LWIP_DBG_TRACE
Definition: debug.h:83
mem_free
void mem_free(void *mem)
Definition: mem.c:419
PBUF_FLAG_TCP_FIN
#define PBUF_FLAG_TCP_FIN
Definition: pbuf.h:139
LWIP_MIN
#define LWIP_MIN(x, y)
Definition: def.h:55
memp_free
void memp_free(memp_t type, void *mem)
Definition: memp.c:469
pbuf::flags
u8_t flags
Definition: pbuf.h:165
SWAP_BYTES_IN_WORD
#define SWAP_BYTES_IN_WORD(w)
Definition: inet_chksum.h:47
taskStruct::id
pidType id
Definition: sched.h:63
stats.h
ERR_MEM
Definition: err.h:65
pbuf_copy_partial
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1016
LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:57
LWIP_ERROR
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:135
pbuf_alloc
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:248
s32_t
int32_t s32_t
Definition: arch.h:127
pbuf_clen
u16_t pbuf_clen(const struct pbuf *p)
Definition: pbuf.c:801
PBUF_IP_HLEN
#define PBUF_IP_HLEN
Definition: pbuf.h:65
u8_t
uint8_t u8_t
Definition: arch.h:122
pbuf_coalesce
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
Definition: pbuf.c:1230
PBUF_LINK_HLEN
#define PBUF_LINK_HLEN
Definition: lwipopts.h:209
buf
Definition: buf.h:35
pbuf_header_force
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:675
tcp_priv.h
pbuf_layer
pbuf_layer
Definition: pbuf.h:72
LWIP_SUPPORT_CUSTOM_PBUF
#define LWIP_SUPPORT_CUSTOM_PBUF
Definition: pbuf.h:55
pbuf_get_at
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1300
LWIP_MEM_ALIGN_SIZE
#define LWIP_MEM_ALIGN_SIZE(size)
Definition: arch.h:221
pbuf_type
pbuf_type
Definition: pbuf.h:101
pbuf_realloc
void pbuf_realloc(struct pbuf *p, u16_t new_len)
Definition: pbuf.c:493
SYS_ARCH_INC
#define SYS_ARCH_INC(var, val)
Definition: sys.h:375
pbuf_copy
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:949
ERR_ARG
Definition: err.h:96
LWIP_UNUSED_ARG
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:315
pbuf_take_at
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1194
SYS_ARCH_DECL_PROTECT
#define SYS_ARCH_DECL_PROTECT(lev)
Definition: sys.h:361
SYS_ARCH_PROTECT
#define SYS_ARCH_PROTECT(lev)
Definition: sys.h:362
MEM_ALIGNMENT
#define MEM_ALIGNMENT
Definition: lwipopts.h:54
pbuf_chain
void pbuf_chain(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:883
LWIP_MEM_ALIGN
#define LWIP_MEM_ALIGN(addr)
Definition: arch.h:236
pbuf_ref
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:821
pbuf_cat
void pbuf_cat(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:841
PBUF_RAM
Definition: pbuf.h:108
pbuf_memcmp
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Definition: pbuf.c:1363
U16_F
#define U16_F
Definition: arch.h:148
PBUF_RAW_TX
Definition: pbuf.h:91
mem_trim
void * mem_trim(void *mem, mem_size_t size)
Definition: mem.c:478
_current
kTask_t * _current
Definition: sched.c:50
ERR_OK
Definition: err.h:63
err_t
s8_t err_t
Definition: err.h:57
mem_ptr_t
uintptr_t mem_ptr_t
Definition: arch.h:128
PBUF_POOL_BUFSIZE_ALIGNED
#define PBUF_POOL_BUFSIZE_ALIGNED
Definition: pbuf.c:132
mem_malloc
void * mem_malloc(mem_size_t size)
Definition: mem.c:603
pbuf_dechain
struct pbuf * pbuf_dechain(struct pbuf *p)
Definition: pbuf.c:900
PBUF_DEBUG
#define PBUF_DEBUG
Definition: lwipopts.h:435
MEMCPY
#define MEMCPY(dst, src, len)
Definition: lwipopts.h:43
LWIP_DBG_LEVEL_WARNING
#define LWIP_DBG_LEVEL_WARNING
Definition: debug.h:55
pbuf_header
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:665
memp.h
mem_size_t
u16_t mem_size_t
Definition: mem.h:67
pbuf::type
u8_t type
Definition: pbuf.h:162
mem.h
pbuf_put_at
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition: pbuf.c:1340
ERR_VAL
Definition: err.h:75
FOLD_U32T
#define FOLD_U32T(u)
Definition: inet_chksum.h:52
pbuf
Definition: pbuf.h:142
PBUF_LINK_ENCAPSULATION_HLEN
#define PBUF_LINK_ENCAPSULATION_HLEN
Definition: lwipopts.h:211
LWIP_DEBUGF
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:164
LWIP_CONST_CAST
#define LWIP_CONST_CAST(target_type, val)
Definition: arch.h:187
inet_chksum.h
PBUF_REF
Definition: pbuf.h:116
pbuf::payload
void * payload
Definition: pbuf.h:147
NULL
#define NULL
Definition: fat_string.h:17