72 #if LWIP_TCP && TCP_QUEUE_OOSEQ 75 #if LWIP_CHECKSUM_ON_COPY 81 #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf)) 84 #define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) 86 #if !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ 87 #define PBUF_POOL_IS_EMPTY() 91 #ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL 93 #define PBUF_POOL_FREE_OOSEQ_QUEUE_CALL() do { \ 94 if (tcpip_callback_with_block(pbuf_free_ooseq_callback, NULL, 0) != ERR_OK) { \ 95 SYS_ARCH_PROTECT(old_level); \ 96 pbuf_free_ooseq_pending = 0; \ 97 SYS_ARCH_UNPROTECT(old_level); \ 102 volatile u8_t pbuf_free_ooseq_pending;
103 #define PBUF_POOL_IS_EMPTY() pbuf_pool_is_empty() 117 pbuf_free_ooseq(
void)
122 for (pcb = tcp_active_pcbs;
NULL != pcb; pcb = pcb->next) {
123 if (
NULL != pcb->ooseq) {
126 tcp_segs_free(pcb->ooseq);
138 pbuf_free_ooseq_callback(
void *arg)
147 pbuf_pool_is_empty(
void)
149 #ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL 155 queued = pbuf_free_ooseq_pending;
156 pbuf_free_ooseq_pending = 1;
161 PBUF_POOL_FREE_OOSEQ_QUEUE_CALL();
201 struct pbuf *p, *q, *r;
247 LWIP_ASSERT(
"pbuf_alloc: pbuf p->payload properly aligned",
253 LWIP_ASSERT(
"check p->payload + p->len does not overflow pbuf",
256 LWIP_ASSERT(
"PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
266 rem_len = length - p->
len;
268 while (rem_len > 0) {
283 LWIP_ASSERT(
"rem_len < max_u16_t", rem_len < 0xffff);
288 LWIP_ASSERT(
"pbuf_alloc: pbuf q->payload properly aligned",
290 LWIP_ASSERT(
"check p->payload + p->len does not overflow pbuf",
315 LWIP_ASSERT(
"pbuf_alloc: pbuf->payload properly aligned",
326 (
"pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
327 (type ==
PBUF_ROM) ?
"ROM" :
"REF"));
348 #if LWIP_SUPPORT_CUSTOM_PBUF 365 void *payload_mem,
u16_t payload_mem_len)
392 LWIP_ASSERT(
"pbuf_alloced_custom: bad pbuf layer", 0);
402 if (payload_mem !=
NULL) {
405 p->pbuf.payload =
NULL;
408 p->pbuf.len = p->pbuf.tot_len = length;
457 while (rem_len > q->
len) {
507 pbuf_header_impl(
struct pbuf *p,
s16_t header_size_increment,
u8_t force)
511 u16_t increment_magnitude;
514 if ((header_size_increment == 0) || (p ==
NULL)) {
518 if (header_size_increment < 0) {
519 increment_magnitude = -header_size_increment;
521 LWIP_ERROR(
"increment_magnitude <= p->len", (increment_magnitude <= p->
len),
return 1;);
523 increment_magnitude = header_size_increment;
528 LWIP_ASSERT(
"p->type == PBUF_RAM || p->type == PBUF_POOL",
531 LWIP_ASSERT(
"p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
547 (
"pbuf_header: failed as %p < %p (not enough space for new header size)\n",
548 (
void *)p->
payload, (
void *)(p + 1)));
557 if ((header_size_increment < 0) && (increment_magnitude <= p->
len)) {
560 }
else if ((header_size_increment > 0) && force) {
573 p->
len += header_size_increment;
574 p->
tot_len += header_size_increment;
577 (
void *)payload, (
void *)p->
payload, header_size_increment));
605 return pbuf_header_impl(p, header_size_increment, 0);
615 return pbuf_header_impl(p, header_size_increment, 1);
662 (
"pbuf_free(p == NULL) was called.\n"));
694 #if LWIP_SUPPORT_CUSTOM_PBUF 697 struct pbuf_custom *pc = (
struct pbuf_custom*)p;
698 LWIP_ASSERT(
"pc->custom_free_function != NULL", pc->custom_free_function !=
NULL);
699 pc->custom_free_function(p);
783 LWIP_ERROR(
"(h != NULL) && (t != NULL) (programmer violates API)",
784 ((h !=
NULL) && (t !=
NULL)),
return;);
858 (
"pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (
void *)q));
864 return ((tail_gone > 0) ?
NULL : q);
888 u16_t offset_to=0, offset_from=0,
len;
891 (
void*)p_to, (
void*)p_from));
894 LWIP_ERROR(
"pbuf_copy: target not big enough to hold source", ((p_to !=
NULL) &&
901 if ((p_to->
len - offset_to) >= (p_from->
len - offset_from)) {
903 len = p_from->
len - offset_from;
906 len = p_to->
len - offset_to;
912 LWIP_ASSERT(
"offset_from <= p_from->len", offset_from <= p_from->len);
913 if (offset_from >= p_from->
len) {
916 p_from = p_from->
next;
918 if (offset_to == p_to->
len) {
927 LWIP_ERROR(
"pbuf_copy() does not allow packet queues!",
932 LWIP_ERROR(
"pbuf_copy() does not allow packet queues!",
957 u16_t copied_total = 0;
959 LWIP_ERROR(
"pbuf_copy_partial: invalid buf", (buf !=
NULL),
return 0;);
960 LWIP_ERROR(
"pbuf_copy_partial: invalid dataptr", (dataptr !=
NULL),
return 0;);
964 if ((buf ==
NULL) || (dataptr ==
NULL)) {
969 for (p = buf; len != 0 && p !=
NULL; p = p->
next) {
970 if ((offset != 0) && (offset >= p->
len)) {
975 buf_copy_len = p->
len - offset;
976 if (buf_copy_len > len)
979 MEMCPY(&((
char*)dataptr)[left], &((
char*)p->
payload)[offset], buf_copy_len);
980 copied_total += buf_copy_len;
981 left += buf_copy_len;
989 #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE 1002 void pbuf_split_64k(
struct pbuf *p,
struct pbuf **rest)
1011 while ((r !=
NULL) && ((
u16_t)(tot_len_front + r->
len) > tot_len_front)) {
1012 tot_len_front += r->
len;
1022 for (i = p; i !=
NULL; i = i->
next) {
1050 u16_t offset_left = in_offset;
1051 struct pbuf* q = in;
1054 while ((q !=
NULL) && (q->
len <= offset_left)) {
1055 offset_left -= q->
len;
1058 if (out_offset !=
NULL) {
1059 *out_offset = offset_left;
1080 u16_t copied_total = 0;
1091 for (p = buf; total_copy_len != 0; p = p->
next) {
1093 buf_copy_len = total_copy_len;
1094 if (buf_copy_len > p->
len) {
1096 buf_copy_len = p->
len;
1099 MEMCPY(p->
payload, &((
const char*)dataptr)[copied_total], buf_copy_len);
1100 total_copy_len -= buf_copy_len;
1101 copied_total += buf_copy_len;
1103 LWIP_ASSERT(
"did not copy all data", total_copy_len == 0 && copied_total == len);
1119 u16_t target_offset;
1123 if ((q !=
NULL) && (q->
tot_len >= target_offset + len)) {
1125 const u8_t* src_ptr = (
const u8_t*)dataptr;
1129 remaining_len -= first_copy_len;
1130 src_ptr += first_copy_len;
1131 if (remaining_len > 0) {
1170 #if LWIP_CHECKSUM_ON_COPY 1184 pbuf_fill_chksum(
struct pbuf *p,
u16_t start_offset,
const void *dataptr,
1195 if ((start_offset >= p->
len) || (start_offset +
len > p->
len)) {
1199 dst_ptr = ((
char*)p->
payload) + start_offset;
1200 copy_chksum = LWIP_CHKSUM_COPY(dst_ptr, dataptr,
len);
1201 if ((start_offset & 1) != 0) {
1225 if ((q !=
NULL) && (q->
len > q_idx)) {
1245 if ((q !=
NULL) && (q->
len > q_idx)) {
1262 u16_t start = offset;
1266 while ((q !=
NULL) && (q->
len <= start)) {
1271 if ((q !=
NULL) && (q->
len > start)) {
1273 for (i = 0; i < n; i++) {
1300 if (p->
tot_len >= mem_len + start_offset) {
1301 for (i = start_offset; i <= max; i++) {
1325 if ((substr ==
NULL) || (substr[0] == 0) || (p->
tot_len == 0xFFFF)) {
1328 substr_len = strlen(substr);
1329 if (substr_len >= 0xFFFF) {
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
#define SYS_ARCH_SET(var, val)
#define LWIP_DBG_LEVEL_SERIOUS
void mem_free(void *rmem)
#define LWIP_DBG_LEVEL_WARNING
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
#define LWIP_SUPPORT_CUSTOM_PBUF
u16_t pbuf_memcmp(struct pbuf *p, u16_t offset, const void *s2, u16_t n)
#define MEMCPY(dst, src, len)
void memp_free(memp_t type, void *mem)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define SYS_ARCH_DECL_PROTECT(lev)
void * mem_trim(void *rmem, mem_size_t newsize)
u8_t pbuf_free(struct pbuf *p)
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
#define SIZEOF_STRUCT_PBUF
#define PBUF_TRANSPORT_HLEN
u16_t pbuf_memfind(struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
#define PBUF_POOL_BUFSIZE_ALIGNED
void pbuf_chain(struct pbuf *h, struct pbuf *t)
#define PBUF_LINK_ENCAPSULATION_HLEN
#define SWAP_BYTES_IN_WORD(w)
#define LWIP_ASSERT(message, assertion)
struct pbuf * pbuf_dechain(struct pbuf *p)
void pbuf_ref(struct pbuf *p)
#define PBUF_FLAG_IS_CUSTOM
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
#define PBUF_FLAG_TCP_FIN
u8_t pbuf_clen(struct pbuf *p)
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
void pbuf_cat(struct pbuf *h, struct pbuf *t)
u8_t pbuf_get_at(struct pbuf *p, u16_t offset)
#define PBUF_POOL_IS_EMPTY()
#define SYS_ARCH_PROTECT(lev)
#define LWIP_MEM_ALIGN(addr)
#define SYS_ARCH_UNPROTECT(lev)
void * mem_malloc(mem_size_t size)
#define LWIP_ERROR(message, expression, handler)
#define LWIP_MEM_ALIGN_SIZE(size)
void * memp_malloc(memp_t type)
u16_t pbuf_strstr(struct pbuf *p, const char *substr)
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
#define LWIP_DEBUGF(debug, message)
#define LWIP_UNUSED_ARG(x)
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)