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