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/tcpip.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 | #ifndef __LWIP_TCPIP_H__ |
pehrhovey | 0:a548a085de55 | 33 | #define __LWIP_TCPIP_H__ |
pehrhovey | 0:a548a085de55 | 34 | |
pehrhovey | 0:a548a085de55 | 35 | #include "lwip/opt.h" |
pehrhovey | 0:a548a085de55 | 36 | |
pehrhovey | 0:a548a085de55 | 37 | #if !NO_SYS /* don't build if not configured for use in lwipopts.h */ |
pehrhovey | 0:a548a085de55 | 38 | |
pehrhovey | 0:a548a085de55 | 39 | #include "lwip/api_msg.h" |
pehrhovey | 0:a548a085de55 | 40 | #include "lwip/netifapi.h" |
pehrhovey | 0:a548a085de55 | 41 | #include "lwip/pbuf.h" |
pehrhovey | 0:a548a085de55 | 42 | #include "lwip/api.h" |
pehrhovey | 0:a548a085de55 | 43 | #include "lwip/sys.h" |
pehrhovey | 0:a548a085de55 | 44 | #include "lwip/netif.h" |
pehrhovey | 0:a548a085de55 | 45 | |
pehrhovey | 0:a548a085de55 | 46 | #ifdef __cplusplus |
pehrhovey | 0:a548a085de55 | 47 | extern "C" { |
pehrhovey | 0:a548a085de55 | 48 | #endif |
pehrhovey | 0:a548a085de55 | 49 | |
pehrhovey | 0:a548a085de55 | 50 | #if LWIP_TCPIP_CORE_LOCKING |
pehrhovey | 0:a548a085de55 | 51 | /** The global semaphore to lock the stack. */ |
pehrhovey | 0:a548a085de55 | 52 | extern sys_sem_t lock_tcpip_core; |
pehrhovey | 0:a548a085de55 | 53 | #define LOCK_TCPIP_CORE() sys_sem_wait(lock_tcpip_core) |
pehrhovey | 0:a548a085de55 | 54 | #define UNLOCK_TCPIP_CORE() sys_sem_signal(lock_tcpip_core) |
pehrhovey | 0:a548a085de55 | 55 | #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m) |
pehrhovey | 0:a548a085de55 | 56 | #define TCPIP_APIMSG_ACK(m) |
pehrhovey | 0:a548a085de55 | 57 | #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m) |
pehrhovey | 0:a548a085de55 | 58 | #define TCPIP_NETIFAPI_ACK(m) |
pehrhovey | 0:a548a085de55 | 59 | #else |
pehrhovey | 0:a548a085de55 | 60 | #define LOCK_TCPIP_CORE() |
pehrhovey | 0:a548a085de55 | 61 | #define UNLOCK_TCPIP_CORE() |
pehrhovey | 0:a548a085de55 | 62 | #define TCPIP_APIMSG(m) tcpip_apimsg(m) |
pehrhovey | 0:a548a085de55 | 63 | #define TCPIP_APIMSG_ACK(m) sys_sem_signal(m->conn->op_completed) |
pehrhovey | 0:a548a085de55 | 64 | #define TCPIP_NETIFAPI(m) tcpip_netifapi(m) |
pehrhovey | 0:a548a085de55 | 65 | #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(m->sem) |
pehrhovey | 0:a548a085de55 | 66 | #endif /* LWIP_TCPIP_CORE_LOCKING */ |
pehrhovey | 0:a548a085de55 | 67 | |
pehrhovey | 0:a548a085de55 | 68 | void tcpip_init(void (* tcpip_init_done)(void *), void *arg); |
pehrhovey | 0:a548a085de55 | 69 | |
pehrhovey | 0:a548a085de55 | 70 | #if LWIP_NETCONN |
pehrhovey | 0:a548a085de55 | 71 | err_t tcpip_apimsg(struct api_msg *apimsg); |
pehrhovey | 0:a548a085de55 | 72 | #if LWIP_TCPIP_CORE_LOCKING |
pehrhovey | 0:a548a085de55 | 73 | err_t tcpip_apimsg_lock(struct api_msg *apimsg); |
pehrhovey | 0:a548a085de55 | 74 | #endif /* LWIP_TCPIP_CORE_LOCKING */ |
pehrhovey | 0:a548a085de55 | 75 | #endif /* LWIP_NETCONN */ |
pehrhovey | 0:a548a085de55 | 76 | |
pehrhovey | 0:a548a085de55 | 77 | err_t tcpip_input(struct pbuf *p, struct netif *inp); |
pehrhovey | 0:a548a085de55 | 78 | |
pehrhovey | 0:a548a085de55 | 79 | #if LWIP_NETIF_API |
pehrhovey | 0:a548a085de55 | 80 | err_t tcpip_netifapi(struct netifapi_msg *netifapimsg); |
pehrhovey | 0:a548a085de55 | 81 | #if LWIP_TCPIP_CORE_LOCKING |
pehrhovey | 0:a548a085de55 | 82 | err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); |
pehrhovey | 0:a548a085de55 | 83 | #endif /* LWIP_TCPIP_CORE_LOCKING */ |
pehrhovey | 0:a548a085de55 | 84 | #endif /* LWIP_NETIF_API */ |
pehrhovey | 0:a548a085de55 | 85 | |
pehrhovey | 0:a548a085de55 | 86 | err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block); |
pehrhovey | 0:a548a085de55 | 87 | #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) |
pehrhovey | 0:a548a085de55 | 88 | |
pehrhovey | 0:a548a085de55 | 89 | /* free pbufs or heap memory from another context without blocking */ |
pehrhovey | 0:a548a085de55 | 90 | err_t pbuf_free_callback(struct pbuf *p); |
pehrhovey | 0:a548a085de55 | 91 | err_t mem_free_callback(void *m); |
pehrhovey | 0:a548a085de55 | 92 | |
pehrhovey | 0:a548a085de55 | 93 | err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); |
pehrhovey | 0:a548a085de55 | 94 | err_t tcpip_untimeout(sys_timeout_handler h, void *arg); |
pehrhovey | 0:a548a085de55 | 95 | |
pehrhovey | 0:a548a085de55 | 96 | enum tcpip_msg_type { |
pehrhovey | 0:a548a085de55 | 97 | #if LWIP_NETCONN |
pehrhovey | 0:a548a085de55 | 98 | TCPIP_MSG_API, |
pehrhovey | 0:a548a085de55 | 99 | #endif /* LWIP_NETCONN */ |
pehrhovey | 0:a548a085de55 | 100 | TCPIP_MSG_INPKT, |
pehrhovey | 0:a548a085de55 | 101 | #if LWIP_NETIF_API |
pehrhovey | 0:a548a085de55 | 102 | TCPIP_MSG_NETIFAPI, |
pehrhovey | 0:a548a085de55 | 103 | #endif /* LWIP_NETIF_API */ |
pehrhovey | 0:a548a085de55 | 104 | TCPIP_MSG_CALLBACK, |
pehrhovey | 0:a548a085de55 | 105 | TCPIP_MSG_TIMEOUT, |
pehrhovey | 0:a548a085de55 | 106 | TCPIP_MSG_UNTIMEOUT |
pehrhovey | 0:a548a085de55 | 107 | }; |
pehrhovey | 0:a548a085de55 | 108 | |
pehrhovey | 0:a548a085de55 | 109 | struct tcpip_msg { |
pehrhovey | 0:a548a085de55 | 110 | enum tcpip_msg_type type; |
pehrhovey | 0:a548a085de55 | 111 | sys_sem_t *sem; |
pehrhovey | 0:a548a085de55 | 112 | union { |
pehrhovey | 0:a548a085de55 | 113 | #if LWIP_NETCONN |
pehrhovey | 0:a548a085de55 | 114 | struct api_msg *apimsg; |
pehrhovey | 0:a548a085de55 | 115 | #endif /* LWIP_NETCONN */ |
pehrhovey | 0:a548a085de55 | 116 | #if LWIP_NETIF_API |
pehrhovey | 0:a548a085de55 | 117 | struct netifapi_msg *netifapimsg; |
pehrhovey | 0:a548a085de55 | 118 | #endif /* LWIP_NETIF_API */ |
pehrhovey | 0:a548a085de55 | 119 | struct { |
pehrhovey | 0:a548a085de55 | 120 | struct pbuf *p; |
pehrhovey | 0:a548a085de55 | 121 | struct netif *netif; |
pehrhovey | 0:a548a085de55 | 122 | } inp; |
pehrhovey | 0:a548a085de55 | 123 | struct { |
pehrhovey | 0:a548a085de55 | 124 | void (*f)(void *ctx); |
pehrhovey | 0:a548a085de55 | 125 | void *ctx; |
pehrhovey | 0:a548a085de55 | 126 | } cb; |
pehrhovey | 0:a548a085de55 | 127 | struct { |
pehrhovey | 0:a548a085de55 | 128 | u32_t msecs; |
pehrhovey | 0:a548a085de55 | 129 | sys_timeout_handler h; |
pehrhovey | 0:a548a085de55 | 130 | void *arg; |
pehrhovey | 0:a548a085de55 | 131 | } tmo; |
pehrhovey | 0:a548a085de55 | 132 | } msg; |
pehrhovey | 0:a548a085de55 | 133 | }; |
pehrhovey | 0:a548a085de55 | 134 | |
pehrhovey | 0:a548a085de55 | 135 | #ifdef __cplusplus |
pehrhovey | 0:a548a085de55 | 136 | } |
pehrhovey | 0:a548a085de55 | 137 | #endif |
pehrhovey | 0:a548a085de55 | 138 | |
pehrhovey | 0:a548a085de55 | 139 | #endif /* !NO_SYS */ |
pehrhovey | 0:a548a085de55 | 140 | |
pehrhovey | 0:a548a085de55 | 141 | #endif /* __LWIP_TCPIP_H__ */ |