Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mamezu 0:0f6c82fcde82 1 /*
mamezu 0:0f6c82fcde82 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
mamezu 0:0f6c82fcde82 3 * All rights reserved.
mamezu 0:0f6c82fcde82 4 *
mamezu 0:0f6c82fcde82 5 * Redistribution and use in source and binary forms, with or without modification,
mamezu 0:0f6c82fcde82 6 * are permitted provided that the following conditions are met:
mamezu 0:0f6c82fcde82 7 *
mamezu 0:0f6c82fcde82 8 * 1. Redistributions of source code must retain the above copyright notice,
mamezu 0:0f6c82fcde82 9 * this list of conditions and the following disclaimer.
mamezu 0:0f6c82fcde82 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
mamezu 0:0f6c82fcde82 11 * this list of conditions and the following disclaimer in the documentation
mamezu 0:0f6c82fcde82 12 * and/or other materials provided with the distribution.
mamezu 0:0f6c82fcde82 13 * 3. The name of the author may not be used to endorse or promote products
mamezu 0:0f6c82fcde82 14 * derived from this software without specific prior written permission.
mamezu 0:0f6c82fcde82 15 *
mamezu 0:0f6c82fcde82 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mamezu 0:0f6c82fcde82 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mamezu 0:0f6c82fcde82 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mamezu 0:0f6c82fcde82 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mamezu 0:0f6c82fcde82 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mamezu 0:0f6c82fcde82 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mamezu 0:0f6c82fcde82 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mamezu 0:0f6c82fcde82 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mamezu 0:0f6c82fcde82 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mamezu 0:0f6c82fcde82 25 * OF SUCH DAMAGE.
mamezu 0:0f6c82fcde82 26 *
mamezu 0:0f6c82fcde82 27 * This file is part of the lwIP TCP/IP stack.
mamezu 0:0f6c82fcde82 28 *
mamezu 0:0f6c82fcde82 29 * Author: Adam Dunkels <adam@sics.se>
mamezu 0:0f6c82fcde82 30 *
mamezu 0:0f6c82fcde82 31 */
mamezu 0:0f6c82fcde82 32 #ifndef __LWIP_TCPIP_H__
mamezu 0:0f6c82fcde82 33 #define __LWIP_TCPIP_H__
mamezu 0:0f6c82fcde82 34
mamezu 0:0f6c82fcde82 35 #include "lwip/opt.h"
mamezu 0:0f6c82fcde82 36
mamezu 0:0f6c82fcde82 37 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
mamezu 0:0f6c82fcde82 38
mamezu 0:0f6c82fcde82 39 #include "lwip/api_msg.h"
mamezu 0:0f6c82fcde82 40 #include "lwip/netifapi.h"
mamezu 0:0f6c82fcde82 41 #include "lwip/pbuf.h"
mamezu 0:0f6c82fcde82 42 #include "lwip/api.h"
mamezu 0:0f6c82fcde82 43 #include "lwip/sys.h"
mamezu 0:0f6c82fcde82 44 #include "lwip/timers.h"
mamezu 0:0f6c82fcde82 45 #include "lwip/netif.h"
mamezu 0:0f6c82fcde82 46
mamezu 0:0f6c82fcde82 47 #ifdef __cplusplus
mamezu 0:0f6c82fcde82 48 extern "C" {
mamezu 0:0f6c82fcde82 49 #endif
mamezu 0:0f6c82fcde82 50
mamezu 0:0f6c82fcde82 51 /** Define this to something that triggers a watchdog. This is called from
mamezu 0:0f6c82fcde82 52 * tcpip_thread after processing a message. */
mamezu 0:0f6c82fcde82 53 #ifndef LWIP_TCPIP_THREAD_ALIVE
mamezu 0:0f6c82fcde82 54 #define LWIP_TCPIP_THREAD_ALIVE()
mamezu 0:0f6c82fcde82 55 #endif
mamezu 0:0f6c82fcde82 56
mamezu 0:0f6c82fcde82 57 #if LWIP_TCPIP_CORE_LOCKING
mamezu 0:0f6c82fcde82 58 /** The global semaphore to lock the stack. */
mamezu 0:0f6c82fcde82 59 extern sys_mutex_t lock_tcpip_core;
mamezu 0:0f6c82fcde82 60 #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
mamezu 0:0f6c82fcde82 61 #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
mamezu 0:0f6c82fcde82 62 #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
mamezu 0:0f6c82fcde82 63 #define TCPIP_APIMSG_ACK(m)
mamezu 0:0f6c82fcde82 64 #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
mamezu 0:0f6c82fcde82 65 #define TCPIP_NETIFAPI_ACK(m)
mamezu 0:0f6c82fcde82 66 #else /* LWIP_TCPIP_CORE_LOCKING */
mamezu 0:0f6c82fcde82 67 #define LOCK_TCPIP_CORE()
mamezu 0:0f6c82fcde82 68 #define UNLOCK_TCPIP_CORE()
mamezu 0:0f6c82fcde82 69 #define TCPIP_APIMSG(m) tcpip_apimsg(m)
mamezu 0:0f6c82fcde82 70 #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed)
mamezu 0:0f6c82fcde82 71 #define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
mamezu 0:0f6c82fcde82 72 #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem)
mamezu 0:0f6c82fcde82 73 #endif /* LWIP_TCPIP_CORE_LOCKING */
mamezu 0:0f6c82fcde82 74
mamezu 0:0f6c82fcde82 75 /** Function prototype for the init_done function passed to tcpip_init */
mamezu 0:0f6c82fcde82 76 typedef void (*tcpip_init_done_fn)(void *arg);
mamezu 0:0f6c82fcde82 77 /** Function prototype for functions passed to tcpip_callback() */
mamezu 0:0f6c82fcde82 78 typedef void (*tcpip_callback_fn)(void *ctx);
mamezu 0:0f6c82fcde82 79
mamezu 0:0f6c82fcde82 80 void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg);
mamezu 0:0f6c82fcde82 81
mamezu 0:0f6c82fcde82 82 #if LWIP_NETCONN
mamezu 0:0f6c82fcde82 83 err_t tcpip_apimsg(struct api_msg *apimsg);
mamezu 0:0f6c82fcde82 84 #if LWIP_TCPIP_CORE_LOCKING
mamezu 0:0f6c82fcde82 85 err_t tcpip_apimsg_lock(struct api_msg *apimsg);
mamezu 0:0f6c82fcde82 86 #endif /* LWIP_TCPIP_CORE_LOCKING */
mamezu 0:0f6c82fcde82 87 #endif /* LWIP_NETCONN */
mamezu 0:0f6c82fcde82 88
mamezu 0:0f6c82fcde82 89 err_t tcpip_input(struct pbuf *p, struct netif *inp);
mamezu 0:0f6c82fcde82 90
mamezu 0:0f6c82fcde82 91 #if LWIP_NETIF_API
mamezu 0:0f6c82fcde82 92 err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
mamezu 0:0f6c82fcde82 93 #if LWIP_TCPIP_CORE_LOCKING
mamezu 0:0f6c82fcde82 94 err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
mamezu 0:0f6c82fcde82 95 #endif /* LWIP_TCPIP_CORE_LOCKING */
mamezu 0:0f6c82fcde82 96 #endif /* LWIP_NETIF_API */
mamezu 0:0f6c82fcde82 97
mamezu 0:0f6c82fcde82 98 err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block);
mamezu 0:0f6c82fcde82 99 #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
mamezu 0:0f6c82fcde82 100
mamezu 0:0f6c82fcde82 101 /* free pbufs or heap memory from another context without blocking */
mamezu 0:0f6c82fcde82 102 err_t pbuf_free_callback(struct pbuf *p);
mamezu 0:0f6c82fcde82 103 err_t mem_free_callback(void *m);
mamezu 0:0f6c82fcde82 104
mamezu 0:0f6c82fcde82 105 #if LWIP_TCPIP_TIMEOUT
mamezu 0:0f6c82fcde82 106 err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
mamezu 0:0f6c82fcde82 107 err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
mamezu 0:0f6c82fcde82 108 #endif /* LWIP_TCPIP_TIMEOUT */
mamezu 0:0f6c82fcde82 109
mamezu 0:0f6c82fcde82 110 enum tcpip_msg_type {
mamezu 0:0f6c82fcde82 111 #if LWIP_NETCONN
mamezu 0:0f6c82fcde82 112 TCPIP_MSG_API,
mamezu 0:0f6c82fcde82 113 #endif /* LWIP_NETCONN */
mamezu 0:0f6c82fcde82 114 TCPIP_MSG_INPKT,
mamezu 0:0f6c82fcde82 115 #if LWIP_NETIF_API
mamezu 0:0f6c82fcde82 116 TCPIP_MSG_NETIFAPI,
mamezu 0:0f6c82fcde82 117 #endif /* LWIP_NETIF_API */
mamezu 0:0f6c82fcde82 118 #if LWIP_TCPIP_TIMEOUT
mamezu 0:0f6c82fcde82 119 TCPIP_MSG_TIMEOUT,
mamezu 0:0f6c82fcde82 120 TCPIP_MSG_UNTIMEOUT,
mamezu 0:0f6c82fcde82 121 #endif /* LWIP_TCPIP_TIMEOUT */
mamezu 0:0f6c82fcde82 122 TCPIP_MSG_CALLBACK
mamezu 0:0f6c82fcde82 123 };
mamezu 0:0f6c82fcde82 124
mamezu 0:0f6c82fcde82 125 struct tcpip_msg {
mamezu 0:0f6c82fcde82 126 enum tcpip_msg_type type;
mamezu 0:0f6c82fcde82 127 sys_sem_t *sem;
mamezu 0:0f6c82fcde82 128 union {
mamezu 0:0f6c82fcde82 129 #if LWIP_NETCONN
mamezu 0:0f6c82fcde82 130 struct api_msg *apimsg;
mamezu 0:0f6c82fcde82 131 #endif /* LWIP_NETCONN */
mamezu 0:0f6c82fcde82 132 #if LWIP_NETIF_API
mamezu 0:0f6c82fcde82 133 struct netifapi_msg *netifapimsg;
mamezu 0:0f6c82fcde82 134 #endif /* LWIP_NETIF_API */
mamezu 0:0f6c82fcde82 135 struct {
mamezu 0:0f6c82fcde82 136 struct pbuf *p;
mamezu 0:0f6c82fcde82 137 struct netif *netif;
mamezu 0:0f6c82fcde82 138 } inp;
mamezu 0:0f6c82fcde82 139 struct {
mamezu 0:0f6c82fcde82 140 tcpip_callback_fn function;
mamezu 0:0f6c82fcde82 141 void *ctx;
mamezu 0:0f6c82fcde82 142 } cb;
mamezu 0:0f6c82fcde82 143 #if LWIP_TCPIP_TIMEOUT
mamezu 0:0f6c82fcde82 144 struct {
mamezu 0:0f6c82fcde82 145 u32_t msecs;
mamezu 0:0f6c82fcde82 146 sys_timeout_handler h;
mamezu 0:0f6c82fcde82 147 void *arg;
mamezu 0:0f6c82fcde82 148 } tmo;
mamezu 0:0f6c82fcde82 149 #endif /* LWIP_TCPIP_TIMEOUT */
mamezu 0:0f6c82fcde82 150 } msg;
mamezu 0:0f6c82fcde82 151 };
mamezu 0:0f6c82fcde82 152
mamezu 0:0f6c82fcde82 153 #ifdef __cplusplus
mamezu 0:0f6c82fcde82 154 }
mamezu 0:0f6c82fcde82 155 #endif
mamezu 0:0f6c82fcde82 156
mamezu 0:0f6c82fcde82 157 #endif /* !NO_SYS */
mamezu 0:0f6c82fcde82 158
mamezu 0:0f6c82fcde82 159 #endif /* __LWIP_TCPIP_H__ */