1/* 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 * OF SUCH DAMAGE. 26 * 27 * This file is part of the lwIP TCP/IP stack. 28 * 29 * Author: Adam Dunkels <adam@sics.se> 30 * 31 */ 32 33#ifndef __LWIP_PBUF_H__ 34#define __LWIP_PBUF_H__ 35 36#include "lwip/opt.h" 37#include "lwip/err.h" 38 39#include <net_interfaces/flags.h> 40 41#ifdef __cplusplus 42extern "C" { 43#endif 44 45/* FIXME: this might be the bad place for this #define */ 46#define PBUF_PKT_SIZE 2048 // NOTE: size of each pbuf struct. 47 48#define PBUF_TRANSPORT_HLEN 20 49#define PBUF_IP_HLEN 20 50 51 typedef enum { 52 PBUF_TRANSPORT, 53 PBUF_IP, 54 PBUF_LINK, 55 PBUF_RAW 56 } pbuf_layer; 57 58 typedef enum { 59 PBUF_RAM, /* pbuf data is stored in RAM */ 60 PBUF_ROM, /* pbuf data is stored in ROM */ 61 PBUF_REF, /* pbuf comes from the pbuf pool */ 62 PBUF_POOL /* pbuf payload refers to RAM */ 63 } pbuf_type; 64 65 66/** indicates this packet's data should be immediately passed to the application */ 67#define PBUF_FLAG_PUSH 0x01U 68 69 struct pbuf { 70 /** next pbuf in singly linked pbuf chain */ 71 struct pbuf *next; 72 73 /** pointer to the actual data in the buffer */ 74 void *payload; 75 76 /** 77 * total length of this buffer and all next buffers in chain 78 * belonging to the same packet. 79 * 80 * For non-queue packet chains this is the invariant: 81 * p->tot_len == p->len + (p->next? p->next->tot_len: 0) 82 */ 83 u16_t tot_len; 84 85 /** length of this buffer */ 86 u16_t len; 87 88 /** pbuf_type as u8_t instead of enum to save space */ 89 u8_t /*pbuf_type */ type; 90 91 /** misc flags */ 92 u8_t flags; 93 94 /** 95 * the reference count always equals the number of pointers 96 * that refer to this pbuf. This can be pointers from an application, 97 * the stack itself, or pbuf->next pointers from a chain. 98 */ 99 u16_t ref; 100 101 /* buff len is the size of buffer allocated to this pbuf */ 102 u16_t buff_len; 103 104 uint64_t nicflags; 105 }; 106 107/* Initializes the pbuf module. This call is empty for now, but may not be in future. */ 108#define pbuf_init() 109 110//#define pbuf_free(a) do{ pbuf_free_tagged((a)); } while(0) 111#define pbuf_free(a) pbuf_free_tagged((a), (__func__), (__LINE__)) 112#define pbuf_ref(a) pbuf_ref_tagged((a), (__func__), (__LINE__)) 113#define pbuf_alloc(l, len, t) pbuf_alloc_tagged((l), (len), (t), (__func__), (__LINE__)) 114 115 void pbuf_ref_tagged(struct pbuf *p, const char *func_name, int line_no); 116 struct pbuf *pbuf_alloc_tagged(pbuf_layer layer, u16_t length, pbuf_type type, 117 const char *func_name, int line_no); 118// u8_t pbuf_free(struct pbuf *p); 119 u8_t pbuf_free_tagged(struct pbuf * p, const char *func_name, int line_no); 120 121 uint16_t free_pbuf_pool_count(void); 122 void pbuf_realloc(struct pbuf *p, u16_t size); 123 u8_t pbuf_header(struct pbuf *p, s16_t header_size); 124// void pbuf_ref(struct pbuf *p); 125 void pbuf_ref_chain(struct pbuf *p); 126// u8_t pbuf_free(struct pbuf *p); 127 u8_t pbuf_clen(struct pbuf *p); 128 void pbuf_cat(struct pbuf *head, struct pbuf *tail); 129 void pbuf_chain(struct pbuf *head, struct pbuf *tail); 130 struct pbuf *pbuf_dechain(struct pbuf *p); 131 err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from); 132 u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, 133 u16_t offset); 134 err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len); 135 struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer); 136 137#ifdef __cplusplus 138} 139#endif 140#endif /* __LWIP_PBUF_H__ */ 141