* is the first pbuf of a pbuf chain.
*/
struct pbuf *
-pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
+pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
{
struct pbuf *p, *q, *r;
u16_t offset;
return NULL;
}
- switch (flag) {
+ switch (type) {
case PBUF_POOL:
/* allocate head of pbuf chain into p */
p = memp_malloc(MEMP_PBUF_POOL);
if (p == NULL) {
return NULL;
}
- p->type = PBUF_TYPE_POOL;
- p->flgs = 0;
+ p->type = type;
p->next = NULL;
/* make the payload pointer point 'offset' bytes into pbuf data memory */
/* bail out unsuccesfully */
return NULL;
}
- q->type = PBUF_TYPE_POOL;
+ q->type = type;
q->flgs = 0;
q->next = NULL;
/* make previous pbuf point to this pbuf */
p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
p->len = p->tot_len = length;
p->next = NULL;
- p->type = PBUF_TYPE_RAM;
- p->flgs = 0;
+ p->type = type;
LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
p = memp_malloc(MEMP_PBUF);
if (p == NULL) {
LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 2, ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
- (flag == PBUF_ROM) ? "ROM" : "REF"));
+ (type == PBUF_ROM) ? "ROM" : "REF"));
return NULL;
}
/* caller must set this field properly, afterwards */
p->payload = NULL;
p->len = p->tot_len = length;
p->next = NULL;
- p->type = ((flag == PBUF_ROM) ? PBUF_TYPE_ROM : PBUF_TYPE_REF);
- p->flgs = 0;
+ p->type = type;
break;
default:
- LWIP_ASSERT("pbuf_alloc: erroneous flag", 0);
+ LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
return NULL;
}
/* set reference count */
p->ref = 1;
+ /* set flgs */
+ p->flgs = 0;
LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
return p;
}
u16_t rem_len; /* remaining length */
s32_t grow;
- LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_TYPE_POOL ||
- p->type == PBUF_TYPE_ROM ||
- p->type == PBUF_TYPE_RAM ||
- p->type == PBUF_TYPE_REF);
+ LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_POOL ||
+ p->type == PBUF_ROM ||
+ p->type == PBUF_RAM ||
+ p->type == PBUF_REF);
/* desired length larger than current length? */
if (new_len >= p->tot_len) {
/* shrink allocated memory for PBUF_RAM */
/* (other types merely adjust their length fields */
- if ((q->type == PBUF_TYPE_RAM) && (rem_len != q->len)) {
+ if ((q->type == PBUF_RAM) && (rem_len != q->len)) {
/* reallocate and adjust the length of the pbuf that will be split */
mem_realloc(q, (u8_t *)q->payload - (u8_t *)q + rem_len);
}
/* Can't assert these as some callers speculatively call
pbuf_header() to see if it's OK. Will return 1 below instead. */
/* Check that we've got the correct type of pbuf to work with */
- LWIP_ASSERT("p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_POOL",
- p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_POOL);
+ LWIP_ASSERT("p->type == PBUF_RAM || p->type == PBUF_POOL",
+ p->type == PBUF_RAM || p->type == PBUF_POOL);
/* Check that we aren't going to move off the beginning of the pbuf */
LWIP_ASSERT("p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
(u8_t *)p->payload - increment_magnitude >= (u8_t *)p + SIZEOF_STRUCT_PBUF);
payload = p->payload;
/* pbuf types containing payloads? */
- if (type == PBUF_TYPE_RAM || type == PBUF_TYPE_POOL) {
+ if (type == PBUF_RAM || type == PBUF_POOL) {
/* set new payload pointer */
p->payload = (u8_t *)p->payload - header_size_increment;
/* boundary check fails? */
return 1;
}
/* pbuf types refering to external payloads? */
- } else if (type == PBUF_TYPE_REF || type == PBUF_TYPE_ROM) {
+ } else if (type == PBUF_REF || type == PBUF_ROM) {
/* hide a header in the payload? */
if ((header_size_increment < 0) && (increment_magnitude <= p->len)) {
/* increase payload pointer */
}
else {
/* Unknown type */
- LWIP_ASSERT("bad pbuf flag type", 0);
+ LWIP_ASSERT("bad pbuf type", 0);
return 1;
}
/* modify pbuf length fields */
PERF_START;
LWIP_ASSERT("pbuf_free: sane type",
- p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_ROM ||
- p->type == PBUF_TYPE_REF || p->type == PBUF_TYPE_POOL);
+ p->type == PBUF_RAM || p->type == PBUF_ROM ||
+ p->type == PBUF_REF || p->type == PBUF_POOL);
count = 0;
/* de-allocate all consecutive pbufs from the head of the chain that
LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_free: deallocating %p\n", (void *)p));
type = p->type;
/* is this a pbuf from the pool? */
- if (type == PBUF_TYPE_POOL) {
+ if (type == PBUF_POOL) {
memp_free(MEMP_PBUF_POOL, p);
/* is this a ROM or RAM referencing pbuf? */
- } else if (type == PBUF_TYPE_ROM || type == PBUF_TYPE_REF) {
+ } else if (type == PBUF_ROM || type == PBUF_REF) {
memp_free(MEMP_PBUF, p);
- /* type == PBUF_TYPE_RAM */
+ /* type == PBUF_RAM */
} else {
mem_free(p);
}
} pbuf_layer;
typedef enum {
- PBUF_RAM,
- PBUF_ROM,
- PBUF_REF,
- PBUF_POOL
-} pbuf_flag;
-
-/* Definitions for the pbuf flag field. These are NOT the flags that
- * are passed to pbuf_alloc(). */
-#define PBUF_TYPE_RAM 0x00U /* pbuf data is stored in RAM */
-#define PBUF_TYPE_ROM 0x01U /* pbuf data is stored in ROM */
-#define PBUF_TYPE_POOL 0x02U /* pbuf comes from the pbuf pool */
-#define PBUF_TYPE_REF 0x04U /* pbuf payload refers to RAM */
+ PBUF_RAM, /* pbuf data is stored in RAM */
+ PBUF_ROM, /* pbuf data is stored in ROM */
+ PBUF_REF, /* pbuf comes from the pbuf pool */
+ PBUF_POOL /* pbuf payload refers to RAM */
+} pbuf_type;
+
/** indicates this packet's data should be immediately passed to the application */
-#define PBUF_FLAG_PUSH 0x40U
+#define PBUF_FLAG_PUSH 0x01U
/** indicates this packet was broadcast on the link */
-#define PBUF_FLAG_LINK_BROADCAST 0x80U
+#define PBUF_FLAG_LINK_BROADCAST 0x02U
struct pbuf {
/** next pbuf in singly linked pbuf chain */
/** length of this buffer */
u16_t len;
- /** type of pbuf, see PBUF_TYPE_ */
- u8_t type;
+ /** pbuf_type as u8_t instead of enum to save space */
+ u8_t /*pbuf_type*/ type;
/** misc flags */
u8_t flgs;
-
+
/**
* the reference count always equals the number of pointers
* that refer to this pbuf. This can be pointers from an application,
/* Initializes the pbuf module. This call is empty for now, but may not be in future. */
#define pbuf_init()
-struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
+struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_type type);
void pbuf_realloc(struct pbuf *p, u16_t size);
u8_t pbuf_header(struct pbuf *p, s16_t header_size);
void pbuf_ref(struct pbuf *p);