UbixOS  2.0
tcpip.c File Reference
#include <net/opt.h>
#include <net/priv/tcpip_priv.h>
#include <net/sys.h>
#include <net/memp.h>
#include <net/mem.h>
#include <net/init.h>
#include <net/ip.h>
#include <net/pbuf.h>
#include <net/etharp.h>
#include <netif/ethernet.h>
Include dependency graph for tcpip.c:

Go to the source code of this file.

Macros

#define TCPIP_MBOX_FETCH(mbox, msg)   sys_mbox_fetch(mbox, msg)
 
#define TCPIP_MSG_VAR_ALLOC(name)   API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)
 
#define TCPIP_MSG_VAR_DECLARE(name)   API_VAR_DECLARE(struct tcpip_msg, name)
 
#define TCPIP_MSG_VAR_FREE(name)   API_VAR_FREE(MEMP_TCPIP_MSG_API, name)
 
#define TCPIP_MSG_VAR_REF(name)   API_VAR_REF(name)
 

Functions

err_t mem_free_callback (void *m)
 
err_t pbuf_free_callback (struct pbuf *p)
 
err_t tcpip_api_call (tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
 
err_t tcpip_callback_with_block (tcpip_callback_fn function, void *ctx, u8_t block)
 
void tcpip_callbackmsg_delete (struct tcpip_callback_msg *msg)
 
struct tcpip_callback_msg * tcpip_callbackmsg_new (tcpip_callback_fn function, void *ctx)
 
void tcpip_init (tcpip_init_done_fn initfunc, void *arg)
 
err_t tcpip_inpkt (struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
 
err_t tcpip_input (struct pbuf *p, struct netif *inp)
 
err_t tcpip_send_msg_wait_sem (tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem)
 
err_t tcpip_trycallback (struct tcpip_callback_msg *msg)
 

Macro Definition Documentation

◆ TCPIP_MBOX_FETCH

#define TCPIP_MBOX_FETCH (   mbox,
  msg 
)    sys_mbox_fetch(mbox, msg)

Definition at line 67 of file tcpip.c.

◆ TCPIP_MSG_VAR_ALLOC

#define TCPIP_MSG_VAR_ALLOC (   name)    API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)

Definition at line 49 of file tcpip.c.

◆ TCPIP_MSG_VAR_DECLARE

#define TCPIP_MSG_VAR_DECLARE (   name)    API_VAR_DECLARE(struct tcpip_msg, name)

Definition at line 48 of file tcpip.c.

◆ TCPIP_MSG_VAR_FREE

#define TCPIP_MSG_VAR_FREE (   name)    API_VAR_FREE(MEMP_TCPIP_MSG_API, name)

Definition at line 50 of file tcpip.c.

◆ TCPIP_MSG_VAR_REF

#define TCPIP_MSG_VAR_REF (   name)    API_VAR_REF(name)

Definition at line 47 of file tcpip.c.

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 491 of file tcpip.c.

References mem_free(), and tcpip_callback_with_block().

Here is the call graph for this function:

◆ 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 480 of file tcpip.c.

References tcpip_callback_with_block().

Here is the call graph for this function:

◆ tcpip_api_call()

err_t tcpip_api_call ( tcpip_api_call_fn  fn,
struct tcpip_api_call_data call 
)

Synchronously calls function in TCPIP thread and waits for its completion. It is recommended to use LWIP_TCPIP_CORE_LOCKING (preferred) or LWIP_NETCONN_SEM_PER_THREAD. If not, a semaphore is created and destroyed on every call which is usually an expensive/slow operation.

Parameters
fnFunction to call
callCall parameters
Returns
Return value from tcpip_api_call_fn

Definition at line 356 of file tcpip.c.

References ERR_OK, LOCK_TCPIP_CORE, LWIP_ASSERT, tcpip_msg::msg, tcpip_api_call_data::sem, sys_mbox_valid_val, sys_sem_new(), TCPIP_MSG_VAR_DECLARE, and UNLOCK_TCPIP_CORE.

Here is the call graph for this function:

◆ 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
functionthe 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 229 of file tcpip.c.

References LWIP_ASSERT, tcpip_msg::msg, and sys_mbox_valid_val.

Referenced by 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 421 of file tcpip.c.

References memp_free(), and tcpip_msg::msg.

Here is the call graph for this function:

◆ 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 405 of file tcpip.c.

References tcpip_msg::ctx, memp_malloc(), tcpip_msg::msg, NULL, and TCPIP_MSG_CALLBACK_STATIC.

Here is the call graph for this function:

◆ 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 446 of file tcpip.c.

References lwip_init().

Referenced by net_init().

Here is the call graph for this function:

◆ tcpip_inpkt()

err_t tcpip_inpkt ( struct pbuf p,
struct netif inp,
netif_input_fn  input_fn 
)

Pass a received packet to tcpip_thread for input processing

Parameters
pthe received packet
inpthe network interface on which the packet was received
input_fninput function to call

Definition at line 161 of file tcpip.c.

References tcpip_msg::inp, tcpip_msg::input_fn, LOCK_TCPIP_CORE, LWIP_ASSERT, LWIP_DEBUGF, tcpip_msg::msg, tcpip_msg::p, sys_mbox_valid_val, TCPIP_DEBUG, and UNLOCK_TCPIP_CORE.

Referenced by tcpip_input().

◆ tcpip_input()

err_t tcpip_input ( struct pbuf p,
struct netif inp 
)

Pass a received packet to tcpip_thread for input processing with ethernet_input or ip_input. Don't call directly, pass to netif_add() and call netif->input().

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 204 of file tcpip.c.

References tcpip_msg::inp, NETIF_FLAG_ETHARP, NETIF_FLAG_ETHERNET, tcpip_msg::p, and tcpip_inpkt().

Referenced by net_init(), and netif_init().

Here is the call graph for this function:

◆ tcpip_send_msg_wait_sem()

err_t tcpip_send_msg_wait_sem ( tcpip_callback_fn  fn,
void *  apimsg,
sys_sem_t sem 
)

Sends a message to TCPIP thread to call a function. Caller thread blocks on on a provided semaphore, which ist NOT automatically signalled by TCPIP thread, this has to be done by the user. It is recommended to use LWIP_TCPIP_CORE_LOCKING since this is the way with least runtime overhead.

Parameters
fnfunction to be called from TCPIP thread
apimsgargument to API function
semsemaphore to wait on
Returns
ERR_OK if the function was called, another err_t if not

Definition at line 322 of file tcpip.c.

References ERR_OK, LOCK_TCPIP_CORE, LWIP_ASSERT, LWIP_UNUSED_ARG, tcpip_msg::msg, tcpip_msg::sem, sys_mbox_valid_val, sys_sem_valid(), TCPIP_MSG_VAR_DECLARE, and UNLOCK_TCPIP_CORE.

Here is the call graph for this function:

◆ 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 432 of file tcpip.c.

References LWIP_ASSERT, and sys_mbox_valid_val.