ReactOS 0.4.15-dev-8102-g108db8f
tcpip.h File Reference
#include "lwip/opt.h"
#include "lwip/api_msg.h"
#include "lwip/netifapi.h"
#include "lwip/pbuf.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "lwip/netif.h"
Include dependency graph for tcpip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tcpip_msg
 

Macros

#define LWIP_TCPIP_THREAD_ALIVE()
 
#define LOCK_TCPIP_CORE()
 
#define UNLOCK_TCPIP_CORE()
 
#define TCPIP_APIMSG(m)   tcpip_apimsg(m)
 
#define TCPIP_APIMSG_ACK(m)   sys_sem_signal(&m->conn->op_completed)
 
#define TCPIP_NETIFAPI(m)   tcpip_netifapi(m)
 
#define TCPIP_NETIFAPI_ACK(m)   sys_sem_signal(&m->sem)
 
#define tcpip_callback(f, ctx)   tcpip_callback_with_block(f, ctx, 1)
 

Typedefs

typedef void(* tcpip_init_done_fn) (void *arg)
 
typedef void(* tcpip_callback_fn) (void *ctx)
 

Enumerations

enum  tcpip_msg_type { TCPIP_MSG_INPKT , TCPIP_MSG_CALLBACK , TCPIP_MSG_CALLBACK_STATIC }
 

Functions

void tcpip_init (tcpip_init_done_fn tcpip_init_done, void *arg)
 
err_t tcpip_input (struct pbuf *p, struct netif *inp)
 
err_t tcpip_callback_with_block (tcpip_callback_fn function, void *ctx, u8_t block)
 
struct tcpip_callback_msg * tcpip_callbackmsg_new (tcpip_callback_fn function, void *ctx)
 
void tcpip_callbackmsg_delete (struct tcpip_callback_msg *msg)
 
err_t tcpip_trycallback (struct tcpip_callback_msg *msg)
 
err_t pbuf_free_callback (struct pbuf *p)
 
err_t mem_free_callback (void *m)
 

Macro Definition Documentation

◆ LOCK_TCPIP_CORE

#define LOCK_TCPIP_CORE ( )

Definition at line 67 of file tcpip.h.

◆ LWIP_TCPIP_THREAD_ALIVE

#define LWIP_TCPIP_THREAD_ALIVE ( )

Define this to something that triggers a watchdog. This is called from tcpip_thread after processing a message.

Definition at line 54 of file tcpip.h.

◆ TCPIP_APIMSG

#define TCPIP_APIMSG (   m)    tcpip_apimsg(m)

Definition at line 69 of file tcpip.h.

◆ TCPIP_APIMSG_ACK

#define TCPIP_APIMSG_ACK (   m)    sys_sem_signal(&m->conn->op_completed)

Definition at line 70 of file tcpip.h.

◆ tcpip_callback

#define tcpip_callback (   f,
  ctx 
)    tcpip_callback_with_block(f, ctx, 1)

Definition at line 102 of file tcpip.h.

◆ TCPIP_NETIFAPI

#define TCPIP_NETIFAPI (   m)    tcpip_netifapi(m)

Definition at line 71 of file tcpip.h.

◆ TCPIP_NETIFAPI_ACK

#define TCPIP_NETIFAPI_ACK (   m)    sys_sem_signal(&m->sem)

Definition at line 72 of file tcpip.h.

◆ UNLOCK_TCPIP_CORE

#define UNLOCK_TCPIP_CORE ( )

Definition at line 68 of file tcpip.h.

Typedef Documentation

◆ tcpip_callback_fn

typedef void(* tcpip_callback_fn) (void *ctx)

Function prototype for functions passed to tcpip_callback()

Definition at line 78 of file tcpip.h.

◆ tcpip_init_done_fn

typedef void(* tcpip_init_done_fn) (void *arg)

Function prototype for the init_done function passed to tcpip_init

Definition at line 76 of file tcpip.h.

Enumeration Type Documentation

◆ tcpip_msg_type

Enumerator
TCPIP_MSG_INPKT 
TCPIP_MSG_CALLBACK 
TCPIP_MSG_CALLBACK_STATIC 

Definition at line 117 of file tcpip.h.

117 {
118#if LWIP_NETCONN
119 TCPIP_MSG_API,
120#endif /* LWIP_NETCONN */
122#if LWIP_NETIF_API
123 TCPIP_MSG_NETIFAPI,
124#endif /* LWIP_NETIF_API */
125#if LWIP_TCPIP_TIMEOUT
126 TCPIP_MSG_TIMEOUT,
127 TCPIP_MSG_UNTIMEOUT,
128#endif /* LWIP_TCPIP_TIMEOUT */
131};
@ TCPIP_MSG_CALLBACK_STATIC
Definition: tcpip.h:130
@ TCPIP_MSG_CALLBACK
Definition: tcpip.h:129
@ TCPIP_MSG_INPKT
Definition: tcpip.h:121

Function Documentation

◆ mem_free_callback()

err_t mem_free_callback ( void m)

A simple wrapper function that allows you to free heap memory from interrupt context.

Parameters
mthe heap memory to free
Returns
ERR_OK if callback could be enqueued, an err_t if not

Definition at line 509 of file tcpip.c.

510{
512}
#define mem_free(ptr, bsize)
Definition: types.h:124
const GLfloat * m
Definition: glext.h:10848
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
Definition: tcpip.c:214

◆ pbuf_free_callback()

err_t pbuf_free_callback ( struct pbuf p)

A simple wrapper function that allows you to free a pbuf from interrupt context.

Parameters
pThe pbuf (chain) to be dereferenced.
Returns
ERR_OK if callback could be enqueued, an err_t if not

Definition at line 496 of file tcpip.c.

497{
499}
GLfloat GLfloat p
Definition: glext.h:8902
static void pbuf_free_int(void *p)
Definition: tcpip.c:483

Referenced by LibTCPGetDataFromConnectionQueue().

◆ tcpip_callback_with_block()

err_t tcpip_callback_with_block ( tcpip_callback_fn  function,
void ctx,
u8_t  block 
)

Call a specific function in the thread context of tcpip_thread for easy access synchronization. A function called in that way may access lwIP core code without fearing concurrent access.

Parameters
fthe function to call
ctxparameter passed to f
block1 to block until the request is posted, 0 to non-blocking mode
Returns
ERR_OK if the function was called, another err_t if not

Definition at line 214 of file tcpip.c.

215{
216 struct tcpip_msg *msg;
217
218 if (sys_mbox_valid(&mbox)) {
219 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
220 if (msg == NULL) {
221 return ERR_MEM;
222 }
223
224 msg->type = TCPIP_MSG_CALLBACK;
225 msg->msg.cb.function = function;
226 msg->msg.cb.ctx = ctx;
227 if (block) {
229 } else {
230 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
231 memp_free(MEMP_TCPIP_MSG_API, msg);
232 return ERR_MEM;
233 }
234 }
235 return ERR_OK;
236 }
237 return ERR_VAL;
238}
#define msg(x)
Definition: auth_time.c:54
#define NULL
Definition: types.h:112
#define ERR_MEM
Definition: err.h:53
#define ERR_OK
Definition: err.h:52
#define ERR_VAL
Definition: err.h:58
void * memp_malloc(memp_t type)
Definition: memp.c:390
void memp_free(memp_t type, void *mem)
Definition: memp.c:435
void * ctx
Definition: tcpip.h:149
tcpip_callback_fn function
Definition: tcpip.h:148
int sys_mbox_valid(sys_mbox_t *mbox)
Definition: sys_arch.c:141
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:160
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:247
static sys_mbox_t mbox
Definition: tcpip.c:58
static unsigned int block
Definition: xmlmemory.c:101

Referenced by LibTCPBind(), LibTCPClose(), LibTCPConnect(), LibTCPFreeSocket(), LibTCPListen(), LibTCPSend(), LibTCPShutdown(), LibTCPSocket(), mem_free_callback(), and pbuf_free_callback().

◆ tcpip_callbackmsg_delete()

void tcpip_callbackmsg_delete ( struct tcpip_callback_msg *  msg)

Free a callback message allocated by tcpip_callbackmsg_new().

Parameters
msgthe message to free

Definition at line 428 of file tcpip.c.

429{
430 memp_free(MEMP_TCPIP_MSG_API, msg);
431}

◆ tcpip_callbackmsg_new()

struct tcpip_callback_msg * tcpip_callbackmsg_new ( tcpip_callback_fn  function,
void ctx 
)

Allocate a structure for a static callback message and initialize it. This is intended to be used to send "static" messages from interrupt context.

Parameters
functionthe function to call
ctxparameter passed to function
Returns
a struct pointer to pass to tcpip_trycallback().

Definition at line 411 of file tcpip.c.

412{
413 struct tcpip_msg *msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
414 if (msg == NULL) {
415 return NULL;
416 }
418 msg->msg.cb.function = function;
419 msg->msg.cb.ctx = ctx;
420 return (struct tcpip_callback_msg*)msg;
421}

◆ tcpip_init()

void tcpip_init ( tcpip_init_done_fn  initfunc,
void arg 
)

Initialize this module:

  • initialize all sub modules
  • start the tcpip_thread
Parameters
initfunca function to call when tcpip_thread is running and finished initializing
argargument to pass to initfunc

Definition at line 458 of file tcpip.c.

459{
460 lwip_init();
461
462 tcpip_init_done = initfunc;
465 LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
466 }
467#if LWIP_TCPIP_CORE_LOCKING
468 if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
469 LWIP_ASSERT("failed to create lock_tcpip_core", 0);
470 }
471#endif /* LWIP_TCPIP_CORE_LOCKING */
472
474}
void lwip_init(void)
Definition: init.c:286
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:66
#define TCPIP_THREAD_NAME
Definition: opt.h:1241
#define TCPIP_THREAD_PRIO
Definition: opt.h:1259
#define TCPIP_MBOX_SIZE
Definition: opt.h:1268
#define TCPIP_THREAD_STACKSIZE
Definition: opt.h:1250
err_t sys_mutex_new(sys_mutex_t *mutex)
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:275
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
Definition: sys_arch.c:128
static void tcpip_thread(void *arg)
Definition: tcpip.c:77
static tcpip_init_done_fn tcpip_init_done
Definition: tcpip.c:56
static void * tcpip_init_done_arg
Definition: tcpip.c:57
void * arg
Definition: msvc.h:10

Referenced by LibIPInitialize().

◆ tcpip_input()

err_t tcpip_input ( struct pbuf p,
struct netif inp 
)

Pass a received packet to tcpip_thread for input processing

Parameters
pthe received packet, p->payload pointing to the Ethernet header or to an IP header (if inp doesn't have NETIF_FLAG_ETHARP or NETIF_FLAG_ETHERNET flags)
inpthe network interface on which the packet was received

Definition at line 164 of file tcpip.c.

165{
166#if LWIP_TCPIP_CORE_LOCKING_INPUT
167 err_t ret;
168 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_input: PACKET %p/%p\n", (void *)p, (void *)inp));
170#if LWIP_ETHERNET
172 ret = ethernet_input(p, inp);
173 } else
174#endif /* LWIP_ETHERNET */
175 {
176 ret = ip_input(p, inp);
177 }
179 return ret;
180#else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
181 struct tcpip_msg *msg;
182
183 if (!sys_mbox_valid(&mbox)) {
184 return ERR_VAL;
185 }
186 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
187 if (msg == NULL) {
188 return ERR_MEM;
189 }
190
191 msg->type = TCPIP_MSG_INPKT;
192 msg->msg.inp.p = p;
193 msg->msg.inp.netif = inp;
194 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
195 memp_free(MEMP_TCPIP_MSG_INPKT, msg);
196 return ERR_MEM;
197 }
198 return ERR_OK;
199#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
200}
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:95
s8_t err_t
Definition: err.h:47
#define LOCK_TCPIP_CORE()
Definition: tcpip.h:67
#define UNLOCK_TCPIP_CORE()
Definition: tcpip.h:68
#define TCPIP_DEBUG
Definition: lwipopts.h:206
err_t ip_input(struct pbuf *p, struct netif *inp)
Definition: ip.c:305
#define NETIF_FLAG_ETHERNET
Definition: netif.h:92
#define NETIF_FLAG_ETHARP
Definition: netif.h:88
u8_t flags
Definition: netif.h:192
struct tcpip_msg::@1044::@1045 inp
int ret

Referenced by netif_init(), and TCPRegisterInterface().

◆ tcpip_trycallback()

err_t tcpip_trycallback ( struct tcpip_callback_msg *  msg)

Try to post a callback-message to the tcpip_thread mbox This is intended to be used to send "static" messages from interrupt context.

Parameters
msgpointer to the message to post
Returns
sys_mbox_trypost() return code

Definition at line 441 of file tcpip.c.

442{
443 if (!sys_mbox_valid(&mbox)) {
444 return ERR_VAL;
445 }
446 return sys_mbox_trypost(&mbox, msg);
447}