2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
32 #ifndef __LWIP_TCPIP_H__
33 #define __LWIP_TCPIP_H__
37 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
39 #include "lwip/api_msg.h"
40 #include "lwip/netifapi.h"
41 #include "lwip/pbuf.h"
44 #include "lwip/timers.h"
45 #include "lwip/netif.h"
51 /** Define this to something that triggers a watchdog. This is called from
52 * tcpip_thread after processing a message. */
53 #ifndef LWIP_TCPIP_THREAD_ALIVE
54 #define LWIP_TCPIP_THREAD_ALIVE()
57 #if LWIP_TCPIP_CORE_LOCKING
58 /** The global semaphore to lock the stack. */
59 extern sys_mutex_t lock_tcpip_core;
60 #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
61 #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
63 #define TCIP_APIMSG_SET_ERR(m, e) (m)->msg.err = e /* catch functions that don't set err */
65 #define TCIP_APIMSG_SET_ERR(m, e)
67 #define TCPIP_APIMSG(m,f,e) do { \
68 TCIP_APIMSG_SET_ERR(m, ERR_VAL); \
71 UNLOCK_TCPIP_CORE(); \
74 #define TCPIP_APIMSG_ACK(m)
75 #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
76 #define TCPIP_NETIFAPI_ACK(m)
77 #else /* LWIP_TCPIP_CORE_LOCKING */
78 #define LOCK_TCPIP_CORE()
79 #define UNLOCK_TCPIP_CORE()
80 #define TCPIP_APIMSG(m,f,e) do { (m)->function = f; (e) = tcpip_apimsg(m); } while(0)
81 #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed)
82 #define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
83 #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem)
84 #endif /* LWIP_TCPIP_CORE_LOCKING */
86 /** Function prototype for the init_done function passed to tcpip_init */
87 typedef void (*tcpip_init_done_fn)(void *arg);
88 /** Function prototype for functions passed to tcpip_callback() */
89 typedef void (*tcpip_callback_fn)(void *ctx);
91 /* Forward declarations */
92 struct tcpip_callback_msg;
94 void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg);
97 err_t tcpip_apimsg(struct api_msg *apimsg);
98 #endif /* LWIP_NETCONN */
100 err_t tcpip_input(struct pbuf *p, struct netif *inp);
103 err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
104 #if LWIP_TCPIP_CORE_LOCKING
105 err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
106 #endif /* LWIP_TCPIP_CORE_LOCKING */
107 #endif /* LWIP_NETIF_API */
109 err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block);
110 #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
112 struct tcpip_callback_msg* tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx);
113 void tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg);
114 err_t tcpip_trycallback(struct tcpip_callback_msg* msg);
116 /* free pbufs or heap memory from another context without blocking */
117 err_t pbuf_free_callback(struct pbuf *p);
118 err_t mem_free_callback(void *m);
120 #if LWIP_TCPIP_TIMEOUT
121 err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
122 err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
123 #endif /* LWIP_TCPIP_TIMEOUT */
125 enum tcpip_msg_type {
128 #endif /* LWIP_NETCONN */
132 #endif /* LWIP_NETIF_API */
133 #if LWIP_TCPIP_TIMEOUT
136 #endif /* LWIP_TCPIP_TIMEOUT */
138 TCPIP_MSG_CALLBACK_STATIC
142 enum tcpip_msg_type type;
146 struct api_msg *apimsg;
147 #endif /* LWIP_NETCONN */
149 struct netifapi_msg *netifapimsg;
150 #endif /* LWIP_NETIF_API */
156 tcpip_callback_fn function;
159 #if LWIP_TCPIP_TIMEOUT
162 sys_timeout_handler h;
165 #endif /* LWIP_TCPIP_TIMEOUT */
175 #endif /* __LWIP_TCPIP_H__ */