annotate packages/net/lwip_tcpip/current/src/api/netbuf.c @ 3292:7f8e529b4d82 default tip

Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
author vae
date Wed, 29 Apr 2015 23:31:48 +0000
parents d6c0c0e0431c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2934
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
1 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
2 * @file
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
3 * Network buffer management
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
4 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
5 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
6
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
7 /*
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
9 * All rights reserved.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
10 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
11 * Redistribution and use in source and binary forms, with or without modification,
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
12 * are permitted provided that the following conditions are met:
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
13 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
14 * 1. Redistributions of source code must retain the above copyright notice,
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
15 * this list of conditions and the following disclaimer.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
17 * this list of conditions and the following disclaimer in the documentation
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
18 * and/or other materials provided with the distribution.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
19 * 3. The name of the author may not be used to endorse or promote products
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
20 * derived from this software without specific prior written permission.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
21 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
31 * OF SUCH DAMAGE.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
32 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
33 * This file is part of the lwIP TCP/IP stack.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
34 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
35 * Author: Adam Dunkels <adam@sics.se>
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
36 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
37 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
38
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
39 #include "lwip/opt.h"
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
40
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
41 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
42
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
43 #include "lwip/netbuf.h"
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
44 #include "lwip/memp.h"
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
45
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
46 #include <string.h>
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
47
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
48 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
49 * Create (allocate) and initialize a new netbuf.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
50 * The netbuf doesn't yet contain a packet buffer!
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
51 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
52 * @return a pointer to a new netbuf
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
53 * NULL on lack of memory
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
54 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
55 struct
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
56 netbuf *netbuf_new(void)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
57 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
58 struct netbuf *buf;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
59
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
60 buf = memp_malloc(MEMP_NETBUF);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
61 if (buf != NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
62 buf->p = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
63 buf->ptr = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
64 buf->addr = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
65 buf->port = 0;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
66 #if LWIP_NETBUF_RECVINFO
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
67 buf->toaddr = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
68 buf->toport = 0;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
69 #endif /* LWIP_NETBUF_RECVINFO */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
70 return buf;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
71 } else {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
72 return NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
73 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
74 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
75
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
76 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
77 * Deallocate a netbuf allocated by netbuf_new().
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
78 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
79 * @param buf pointer to a netbuf allocated by netbuf_new()
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
80 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
81 void
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
82 netbuf_delete(struct netbuf *buf)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
83 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
84 if (buf != NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
85 if (buf->p != NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
86 pbuf_free(buf->p);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
87 buf->p = buf->ptr = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
88 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
89 memp_free(MEMP_NETBUF, buf);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
90 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
91 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
92
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
93 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
94 * Allocate memory for a packet buffer for a given netbuf.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
95 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
96 * @param buf the netbuf for which to allocate a packet buffer
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
97 * @param size the size of the packet buffer to allocate
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
98 * @return pointer to the allocated memory
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
99 * NULL if no memory could be allocated
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
100 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
101 void *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
102 netbuf_alloc(struct netbuf *buf, u16_t size)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
103 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
104 LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
105
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
106 /* Deallocate any previously allocated memory. */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
107 if (buf->p != NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
108 pbuf_free(buf->p);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
109 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
110 buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
111 if (buf->p == NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
112 return NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
113 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
114 LWIP_ASSERT("check that first pbuf can hold size",
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
115 (buf->p->len >= size));
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
116 buf->ptr = buf->p;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
117 return buf->p->payload;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
118 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
119
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
120 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
121 * Free the packet buffer included in a netbuf
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
122 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
123 * @param buf pointer to the netbuf which contains the packet buffer to free
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
124 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
125 void
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
126 netbuf_free(struct netbuf *buf)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
127 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
128 LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
129 if (buf->p != NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
130 pbuf_free(buf->p);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
131 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
132 buf->p = buf->ptr = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
133 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
134
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
135 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
136 * Let a netbuf reference existing (non-volatile) data.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
137 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
138 * @param buf netbuf which should reference the data
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
139 * @param dataptr pointer to the data to reference
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
140 * @param size size of the data
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
141 * @return ERR_OK if data is referenced
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
142 * ERR_MEM if data couldn't be referenced due to lack of memory
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
143 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
144 err_t
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
145 netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
146 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
147 LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
148 if (buf->p != NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
149 pbuf_free(buf->p);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
150 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
151 buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
152 if (buf->p == NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
153 buf->ptr = NULL;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
154 return ERR_MEM;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
155 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
156 buf->p->payload = (void*)dataptr;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
157 buf->p->len = buf->p->tot_len = size;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
158 buf->ptr = buf->p;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
159 return ERR_OK;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
160 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
161
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
162 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
163 * Chain one netbuf to another (@see pbuf_chain)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
164 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
165 * @param head the first netbuf
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
166 * @param tail netbuf to chain after head, freed by this function, may not be reference after returning
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
167 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
168 void
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
169 netbuf_chain(struct netbuf *head, struct netbuf *tail)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
170 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
171 LWIP_ERROR("netbuf_ref: invalid head", (head != NULL), return;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
172 LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
173 pbuf_cat(head->p, tail->p);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
174 head->ptr = head->p;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
175 memp_free(MEMP_NETBUF, tail);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
176 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
177
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
178 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
179 * Get the data pointer and length of the data inside a netbuf.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
180 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
181 * @param buf netbuf to get the data from
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
182 * @param dataptr pointer to a void pointer where to store the data pointer
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
183 * @param len pointer to an u16_t where the length of the data is stored
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
184 * @return ERR_OK if the information was retreived,
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
185 * ERR_BUF on error.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
186 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
187 err_t
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
188 netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
189 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
190 LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
191 LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
192 LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
193
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
194 if (buf->ptr == NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
195 return ERR_BUF;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
196 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
197 *dataptr = buf->ptr->payload;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
198 *len = buf->ptr->len;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
199 return ERR_OK;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
200 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
201
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
202 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
203 * Move the current data pointer of a packet buffer contained in a netbuf
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
204 * to the next part.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
205 * The packet buffer itself is not modified.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
206 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
207 * @param buf the netbuf to modify
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
208 * @return -1 if there is no next part
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
209 * 1 if moved to the next part but now there is no next part
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
210 * 0 if moved to the next part and there are still more parts
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
211 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
212 s8_t
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
213 netbuf_next(struct netbuf *buf)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
214 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
215 LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return -1;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
216 if (buf->ptr->next == NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
217 return -1;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
218 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
219 buf->ptr = buf->ptr->next;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
220 if (buf->ptr->next == NULL) {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
221 return 1;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
222 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
223 return 0;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
224 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
225
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
226 /**
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
227 * Move the current data pointer of a packet buffer contained in a netbuf
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
228 * to the beginning of the packet.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
229 * The packet buffer itself is not modified.
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
230 *
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
231 * @param buf the netbuf to modify
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
232 */
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
233 void
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
234 netbuf_first(struct netbuf *buf)
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
235 {
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
236 LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
237 buf->ptr = buf->p;
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
238 }
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
239
d6c0c0e0431c * net/lwip_tcpip/current/*: Major update of lwIP TCP/IP stack to version 1.3.2.
jld
parents:
diff changeset
240 #endif /* LWIP_NETCONN */