- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# pbuf.h

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
    00003  * All rights reserved.
    00004  *
    00005  * Redistribution and use in source and binary forms, with or without
    00006  * modification, are permitted provided that the following conditions
    00007  * are met:
    00008  * 1. Redistributions of source code must retain the above copyright
    00009  *    notice, this list of conditions and the following disclaimer.
    00010  * 2. Redistributions in binary form must reproduce the above copyright
    00011  *    notice, this list of conditions and the following disclaimer in the
    00012  *    documentation and/or other materials provided with the distribution.
    00013  * 3. Neither the name of the Institute nor the names of its contributors
    00014  *    may be used to endorse or promote products derived from this software
    00015  *    without specific prior written permission.
    00016  *
    00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
    00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
    00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00027  * SUCH DAMAGE.
    00028  *
    00029  * This file is part of the lwIP TCP/IP stack.
    00030  *
    00031  * Author: Adam Dunkels <adam@sics.se>
    00032  *
    00033  * $Id: pbuf_8h-source.html 88 2016-01-12 00:11:29Z reddawg $
    00034  */
    00035 /*-----------------------------------------------------------------------------------*/
    00036 #ifndef __LWIP_PBUF_H__
    00037 #define __LWIP_PBUF_H__
    00038
    00039 #include "net/debug.h"
    00040 #include "net/arch.h"
    00041
    00042
    00043 #define PBUF_TRANSPORT_HLEN 20
    00044 #define PBUF_IP_HLEN        20
    00045
    00046 typedef enum {
    00047   PBUF_TRANSPORT,
    00048   PBUF_IP,
    00049   PBUF_LINK,
    00050   PBUF_RAW
    00051 } pbuf_layer;
    00052
    00053 typedef enum {
    00054   PBUF_RAM,
    00055   PBUF_ROM,
    00056   PBUF_POOL
    00057 } pbuf_flag;
    00058
    00059 /* Definitions for the pbuf flag field (these are not the flags that
    00060    are passed to pbuf_alloc()). */
    00061 #define PBUF_FLAG_RAM   0x00    /* Flags that pbuf data is stored in RAM. */
    00062 #define PBUF_FLAG_ROM   0x01    /* Flags that pbuf data is stored in ROM. */
    00063 #define PBUF_FLAG_POOL  0x02    /* Flags that the pbuf comes from the
    00064                                    pbuf pool. */
    00065
    00066 struct pbuf {
    00067   struct pbuf *next;
    00068
    00069   /* high 4 bits, flags, low 4 bits reference count */
    00070   uInt8 flags, ref;
    00071   void *payload;
    00072
    00073   /* Total length of buffer + additionally chained buffers. */
    00074   uInt16 tot_len;
    00075   /* Length of this buffer. */
    00076   uInt16 len;
    00077
    00078 };
    00079
    00080 /* pbuf_init():
    00081
    00082    Initializes the pbuf module. The num parameter determines how many
    00083    pbufs that should be allocated to the pbuf pool, and the size
    00084    parameter specifies the size of the data allocated to those.  */
    00085 void pbuf_init(void);
    00086
    00087 /* pbuf_alloc():
    00088
    00089    Allocates a pbuf at protocol layer l. The actual memory allocated
    00090    for the pbuf is determined by the layer at which the pbuf is
    00091    allocated and the requested size (from the size parameter). The
    00092    flag parameter decides how and where the pbuf should be allocated
    00093    as follows:
    00094
    00095    * PBUF_RAM: buffer memory for pbuf is allocated as one large
    00096                chunk. This includesprotocol headers as well.
    00097
    00098    * RBUF_ROM: no buffer memory is allocated for the pbuf, even for
    00099                 protocol headers.  Additional headers must be
    00100                 prepended by allocating another pbuf and chain in to
    00101                 the front of the ROM pbuf.
    00102
    00103    * PBUF_ROOL: the pbuf is allocated as a pbuf chain, with pbufs from
    00104                 the pbuf pool that is allocated during pbuf_init().  */
    00105 struct pbuf *pbuf_alloc(pbuf_layer l, uInt16 size, pbuf_flag flag);
    00106
    00107 /* pbuf_realloc():
    00108
    00109    Shrinks the pbuf to the size given by the size parameter.
    00110  */
    00111 void pbuf_realloc(struct pbuf *p, uInt16 size);
    00112
    00113 /* pbuf_header():
    00114
    00115    Tries to move the p->payload pointer header_size number of bytes
    00116    upward within the pbuf. The return value is non-zero if it
    00117    fails. If so, an additional pbuf should be allocated for the header
    00118    and it should be chained to the front. */
    00119 uInt8 pbuf_header(struct pbuf *p, Int16 header_size);
    00120
    00121 /* pbuf_ref():
    00122
    00123    Increments the reference count of the pbuf p.
    00124  */
    00125 void pbuf_ref(struct pbuf *p);
    00126
    00127 /* pbuf_free():
    00128
    00129    Decrements the reference count and deallocates the pbuf if the
    00130    reference count is zero. If the pbuf is a chain all pbufs in the
    00131    chain are deallocated.  */
    00132 uInt8 pbuf_free(struct pbuf *p);
    00133
    00134 /* pbuf_clen():
    00135
    00136    Returns the length of the pbuf chain. */
    00137 uInt8 pbuf_clen(struct pbuf *p);
    00138
    00139 /* pbuf_chain():
    00140
    00141    Chains pbuf t on the end of pbuf h. Pbuf h will have it's tot_len
    00142    field adjusted accordingly. Pbuf t should no be used any more after
    00143    a call to this function, since pbuf t is now a part of pbuf h.  */
    00144 void pbuf_chain(struct pbuf *h, struct pbuf *t);
    00145
    00146 /* pbuf_dechain():
    00147
    00148    Picks off the first pbuf from the pbuf chain p. Returns the tail of
    00149    the pbuf chain or NULL if the pbuf p was not chained. */
    00150 struct pbuf *pbuf_dechain(struct pbuf *p);
    00151
    00152 #endif /* __LWIP_PBUF_H__ */