486 |
} |
} |
487 |
|
|
488 |
/** |
/** |
489 |
* Tries to add a header to the payload. |
* Tries to expand the payload with towards the front. |
490 |
* |
* |
491 |
* Adjusts the ->payload pointer so that space for a header appears in |
* Adjusts the ->payload pointer so that space for a header appears in |
492 |
* the pbuf. Also, the ->tot_len and ->len fields are adjusted. |
* the pbuf. Also, the ->tot_len and ->len fields are adjusted. |
494 |
* @param hdr_decrement Number of bytes to decrement header size. |
* @param hdr_decrement Number of bytes to decrement header size. |
495 |
* (Using a negative value increases the header size.) |
* (Using a negative value increases the header size.) |
496 |
* |
* |
497 |
* @return 1 on failure, 0 on succes. |
* @return 1 on failure, 0 on success. |
498 |
*/ |
*/ |
499 |
u8_t |
u8_t |
500 |
pbuf_header(struct pbuf *p, s16_t header_size) |
pbuf_header(struct pbuf *p, s16_t header_size) |
503 |
|
|
504 |
/* remember current payload pointer */ |
/* remember current payload pointer */ |
505 |
payload = p->payload; |
payload = p->payload; |
|
/* set new payload pointer */ |
|
|
p->payload = (u8_t *)p->payload - header_size; |
|
506 |
|
|
507 |
/* pbuf types containing payloads? */ |
/* pbuf types containing payloads? */ |
508 |
if (p->flags == PBUF_FLAG_RAM || |
if (p->flags == PBUF_FLAG_RAM || p->flags == PBUF_FLAG_POOL) { |
509 |
p->flags == PBUF_FLAG_POOL) { |
/* set new payload pointer */ |
510 |
|
p->payload = (u8_t *)p->payload - header_size; |
511 |
/* boundary check fails? */ |
/* boundary check fails? */ |
512 |
if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf)) { |
if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf)) { |
513 |
DEBUGF( PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p\n", |
DEBUGF( PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p\n", |
518 |
/* bail out unsuccesfully */ |
/* bail out unsuccesfully */ |
519 |
return 1; |
return 1; |
520 |
} |
} |
521 |
|
/* pbuf types refering to payloads? */ |
522 |
|
} else if (p->flags == PBUF_FLAG_REF || p->flags == PBUF_FLAG_ROM) { |
523 |
|
/* hide a header in the payload? */ |
524 |
|
if ((header_size < 0) && (header_size - p->len <= 0)) { |
525 |
|
/* increase payload pointer */ |
526 |
|
p->payload = (u8_t *)p->payload - header_size; |
527 |
|
} else { |
528 |
|
/* cannot expand payload to front (yet!) |
529 |
|
* bail out unsuccesfully */ |
530 |
|
return 1; |
531 |
|
} |
532 |
} |
} |
|
|
|
533 |
DEBUGF( PBUF_DEBUG, ("pbuf_header: old %p new %p (%d)\n", payload, p->payload, header_size) ); |
DEBUGF( PBUF_DEBUG, ("pbuf_header: old %p new %p (%d)\n", payload, p->payload, header_size) ); |
534 |
/* modify pbuf length fields */ |
/* modify pbuf length fields */ |
535 |
p->len += header_size; |
p->len += header_size; |