73#if LWIP_TCP && TCP_QUEUE_OOSEQ
76#if LWIP_CHECKSUM_ON_COPY
82#define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
85#define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)
87#if !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ
88#define PBUF_POOL_IS_EMPTY()
92#ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
94#define PBUF_POOL_FREE_OOSEQ_QUEUE_CALL() do { \
95 if(tcpip_callback_with_block(pbuf_free_ooseq_callback, NULL, 0) != ERR_OK) { \
96 SYS_ARCH_PROTECT(old_level); \
97 pbuf_free_ooseq_pending = 0; \
98 SYS_ARCH_UNPROTECT(old_level); \
103volatile u8_t pbuf_free_ooseq_pending;
104#define PBUF_POOL_IS_EMPTY() pbuf_pool_is_empty()
124 pbuf_free_ooseq_pending = 0;
127 for (pcb = tcp_active_pcbs;
NULL != pcb; pcb = pcb->next) {
128 if (
NULL != pcb->ooseq) {
131 tcp_segs_free(pcb->ooseq);
143pbuf_free_ooseq_callback(
void *arg)
152pbuf_pool_is_empty(
void)
154#ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
157 pbuf_free_ooseq_pending = 1;
163 queued = pbuf_free_ooseq_pending;
164 pbuf_free_ooseq_pending = 1;
169 PBUF_POOL_FREE_OOSEQ_QUEUE_CALL();
209 struct pbuf *p, *q, *r;
250 LWIP_ASSERT(
"pbuf_alloc: pbuf p->payload properly aligned",
256 LWIP_ASSERT(
"check p->payload + p->len does not overflow pbuf",
257 ((
u8_t*)p->payload + p->len <=
259 LWIP_ASSERT(
"PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
269 rem_len =
length - p->len;
271 while (rem_len > 0) {
286 LWIP_ASSERT(
"rem_len < max_u16_t", rem_len < 0xffff);
291 LWIP_ASSERT(
"pbuf_alloc: pbuf q->payload properly aligned",
293 LWIP_ASSERT(
"check p->payload + p->len does not overflow pbuf",
294 ((
u8_t*)p->payload + p->len <=
314 p->len = p->tot_len =
length;
318 LWIP_ASSERT(
"pbuf_alloc: pbuf->payload properly aligned",
329 (
"pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
335 p->len = p->tot_len =
length;
351#if LWIP_SUPPORT_CUSTOM_PBUF
368 void *payload_mem,
u16_t payload_mem_len)
391 LWIP_ASSERT(
"pbuf_alloced_custom: bad pbuf layer", 0);
401 if (payload_mem !=
NULL) {
404 p->pbuf.payload =
NULL;
407 p->pbuf.len = p->pbuf.tot_len =
length;
456 while (rem_len > q->
len) {
515 u16_t increment_magnitude;
518 if ((header_size_increment == 0) || (p ==
NULL)) {
522 if (header_size_increment < 0){
523 increment_magnitude = -header_size_increment;
525 LWIP_ERROR(
"increment_magnitude <= p->len", (increment_magnitude <= p->
len),
return 1;);
527 increment_magnitude = header_size_increment;
532 LWIP_ASSERT(
"p->type == PBUF_RAM || p->type == PBUF_POOL",
535 LWIP_ASSERT(
"p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
551 (
"pbuf_header: failed as %p < %p (not enough space for new header size)\n",
552 (
void *)p->
payload, (
void *)(p + 1)));
561 if ((header_size_increment < 0) && (increment_magnitude <= p->
len)) {
575 p->
len += header_size_increment;
576 p->
tot_len += header_size_increment;
628 (
"pbuf_free(p == NULL) was called.\n"));
660#if LWIP_SUPPORT_CUSTOM_PBUF
663 struct pbuf_custom *pc = (
struct pbuf_custom*)p;
664 LWIP_ASSERT(
"pc->custom_free_function != NULL", pc->custom_free_function !=
NULL);
665 pc->custom_free_function(p);
749 LWIP_ERROR(
"(h != NULL) && (t != NULL) (programmer violates API)",
750 ((h !=
NULL) && (t !=
NULL)),
return;);
824 (
"pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (
void *)q));
830 return ((tail_gone > 0) ?
NULL : q);
854 u16_t offset_to=0, offset_from=0,
len;
857 (
void*)p_to, (
void*)p_from));
860 LWIP_ERROR(
"pbuf_copy: target not big enough to hold source", ((p_to !=
NULL) &&
867 if ((p_to->
len - offset_to) >= (p_from->
len - offset_from)) {
869 len = p_from->
len - offset_from;
872 len = p_to->
len - offset_to;
878 LWIP_ASSERT(
"offset_from <= p_from->len", offset_from <= p_from->
len);
879 if (offset_from >= p_from->
len) {
882 p_from = p_from->
next;
884 if (offset_to == p_to->
len) {
893 LWIP_ERROR(
"pbuf_copy() does not allow packet queues!\n",
898 LWIP_ERROR(
"pbuf_copy() does not allow packet queues!\n",
923 u16_t copied_total = 0;
925 LWIP_ERROR(
"pbuf_copy_partial: invalid buf", (buf !=
NULL),
return 0;);
926 LWIP_ERROR(
"pbuf_copy_partial: invalid dataptr", (dataptr !=
NULL),
return 0;);
930 if((buf ==
NULL) || (dataptr ==
NULL)) {
936 if ((offset != 0) && (offset >= p->
len)) {
941 buf_copy_len = p->
len - offset;
942 if (buf_copy_len >
len)
945 MEMCPY(&((
char*)dataptr)[left], &((
char*)p->
payload)[offset], buf_copy_len);
946 copied_total += buf_copy_len;
947 left += buf_copy_len;
971 u16_t copied_total = 0;
974 LWIP_ERROR(
"pbuf_take: invalid dataptr", (dataptr !=
NULL),
return 0;);
981 for(p = buf; total_copy_len != 0; p = p->
next) {
983 buf_copy_len = total_copy_len;
984 if (buf_copy_len > p->
len) {
986 buf_copy_len = p->
len;
989 MEMCPY(p->
payload, &((
char*)dataptr)[copied_total], buf_copy_len);
990 total_copy_len -= buf_copy_len;
991 copied_total += buf_copy_len;
993 LWIP_ASSERT(
"did not copy all data", total_copy_len == 0 && copied_total ==
len);
1028#if LWIP_CHECKSUM_ON_COPY
1042pbuf_fill_chksum(
struct pbuf *p,
u16_t start_offset,
const void *dataptr,
1053 if ((start_offset >= p->
len) || (start_offset +
len > p->
len)) {
1057 dst_ptr = ((
char*)p->
payload) + start_offset;
1058 copy_chksum = LWIP_CHKSUM_COPY(dst_ptr, dataptr,
len);
1059 if ((start_offset & 1) != 0) {
1079 u16_t copy_from = offset;
1083 while ((q !=
NULL) && (q->
len <= copy_from)) {
1084 copy_from -= q->
len;
1088 if ((q !=
NULL) && (q->
len > copy_from)) {
1106 u16_t start = offset;
1110 while ((q !=
NULL) && (q->
len <= start)) {
1115 if ((q !=
NULL) && (q->
len > start)) {
1117 for(i = 0; i < n; i++) {
1144 if (p->
tot_len >= mem_len + start_offset) {
1145 for(i = start_offset; i <= max; ) {
1171 if ((substr ==
NULL) || (substr[0] == 0) || (p->
tot_len == 0xFFFF)) {
1174 substr_len = strlen(substr);
1175 if (substr_len >= 0xFFFF) {
#define LWIP_UNUSED_ARG(x)
#define LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DEBUGF(debug, message)
#define LWIP_DBG_LEVEL_WARNING
#define LWIP_ERROR(message, expression, handler)
#define LWIP_ASSERT(message, assertion)
#define SWAP_BYTES_IN_WORD(w)
void * mem_malloc(mem_size_t size)
void mem_free(void *rmem)
void * mem_trim(void *rmem, mem_size_t newsize)
#define LWIP_MEM_ALIGN(addr)
#define LWIP_MEM_ALIGN_SIZE(size)
void * memp_malloc(memp_t type)
void memp_free(memp_t type, void *mem)
#define MEMCPY(dst, src, len)
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
#define PBUF_POOL_BUFSIZE_ALIGNED
void pbuf_realloc(struct pbuf *p, u16_t new_len)
void pbuf_ref(struct pbuf *p)
void pbuf_cat(struct pbuf *h, struct pbuf *t)
void pbuf_chain(struct pbuf *h, struct pbuf *t)
#define SIZEOF_STRUCT_PBUF
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u8_t pbuf_clen(struct pbuf *p)
u16_t pbuf_memcmp(struct pbuf *p, u16_t offset, const void *s2, u16_t n)
u8_t pbuf_get_at(struct pbuf *p, u16_t offset)
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
u8_t pbuf_free(struct pbuf *p)
u16_t pbuf_memfind(struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
struct pbuf * pbuf_dechain(struct pbuf *p)
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
u16_t pbuf_strstr(struct pbuf *p, const char *substr)
#define PBUF_POOL_IS_EMPTY()
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
#define PBUF_FLAG_IS_CUSTOM
#define PBUF_TRANSPORT_HLEN
#define SYS_ARCH_UNPROTECT(lev)
#define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_DECL_PROTECT(lev)