Microchip® Advanced Software Framework

api_msg.h File Reference
#include "lwip/opt.h"
#include <stddef.h>
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include "lwip/igmp.h"
#include "lwip/api.h"

Data Structures

struct  api_msg
 This struct contains a function to execute in another thread context and a struct api_msg_msg that serves as an argument for this function. More...
 
struct  api_msg_msg
 This struct includes everything that is necessary to execute a function for a netconn in another thread context (mainly used to process netconns in the tcpip_thread context to be thread safe). More...
 
struct  dns_api_msg
 As lwip_netconn_do_gethostbyname requires more arguments but doesn't require a netconn, it has its own struct (to avoid struct api_msg getting bigger than necessary). More...
 

Macros

#define API_MSG_M_DEF(m)   *m
 
#define LWIP_API_MSG_SEM(msg)   (&(msg)->conn->op_completed)
 
#define LWIP_NETCONN_SCOPE
 
#define NETCONN_SHUT_RD   1
 
#define NETCONN_SHUT_RDWR   (NETCONN_SHUT_RD | NETCONN_SHUT_WR)
 
#define NETCONN_SHUT_WR   2
 

Functions

LWIP_NETCONN_SCOPE void lwip_netconn_do_bind (struct api_msg_msg *msg)
 Bind a pcb contained in a netconn Called from netconn_bind. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_close (struct api_msg_msg *msg)
 Close or half-shutdown a TCP pcb contained in a netconn Called from netconn_close In contrast to closing sockets, the netconn is not deallocated. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_connect (struct api_msg_msg *msg)
 Connect a pcb contained inside a netconn Called from netconn_connect. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_delconn (struct api_msg_msg *msg)
 Delete the pcb inside a netconn. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_disconnect (struct api_msg_msg *msg)
 Connect a pcb contained inside a netconn Only used for UDP netconns. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_getaddr (struct api_msg_msg *msg)
 Return a connection's local or remote address Called from netconn_getaddr. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_gethostbyname (void *arg)
 Execute a DNS query Called from netconn_gethostbyname. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_join_leave_group (struct api_msg_msg *msg)
 Join multicast groups for UDP netconns. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_listen (struct api_msg_msg *msg)
 Set a TCP pcb contained in a netconn into listen mode Called from netconn_listen. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_newconn (struct api_msg_msg *msg)
 Create a new pcb of a specific type inside a netconn. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_recv (struct api_msg_msg *msg)
 Indicate data has been received from a TCP pcb contained in a netconn Called from netconn_recv. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_send (struct api_msg_msg *msg)
 Send some data on a RAW or UDP pcb contained in a netconn Called from netconn_send. More...
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_shutdown (struct api_msg_msg *msg)
 
LWIP_NETCONN_SCOPE void lwip_netconn_do_write (struct api_msg_msg *msg)
 Send some data on a TCP pcb contained in a netconn Called from netconn_write. More...
 
LWIP_NETCONN_SCOPE struct netconnnetconn_alloc (enum netconn_type t, netconn_callback callback)
 Create a new netconn (of a specific type) that has a callback function. More...
 
LWIP_NETCONN_SCOPE void netconn_free (struct netconn *conn)
 Delete a netconn and all its resources. More...
 

#define API_MSG_M_DEF (   m)    *m
#define LWIP_NETCONN_SCOPE
#define NETCONN_SHUT_RD   1
#define NETCONN_SHUT_WR   2

LWIP_NETCONN_SCOPE void lwip_netconn_do_bind ( struct api_msg_msg msg)

Bind a pcb contained in a netconn Called from netconn_bind.

Parameters
msgthe api_msg_msg pointing to the connection and containing the IP address and port to bind to

References API_EXPR_REF, api_msg_msg::bc, api_msg_msg::conn, api_msg_msg::err, ERR_IS_FATAL, ERR_VAL, netconn::last_err, api_msg_msg::msg, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::pcb, netconn::raw, raw_bind(), netconn::tcp, tcp_bind(), TCPIP_APIMSG_ACK, netconn::type, netconn::udp, and udp_bind().

Referenced by netconn_bind().

LWIP_NETCONN_SCOPE void lwip_netconn_do_close ( struct api_msg_msg msg)

Close or half-shutdown a TCP pcb contained in a netconn Called from netconn_close In contrast to closing sockets, the netconn is not deallocated.

Parameters
msgthe api_msg_msg pointing to the connection

References api_msg_msg::conn, netconn::current_msg, api_msg_msg::err, ERR_CONN, ERR_INPROGRESS, LWIP_API_MSG_SEM, LWIP_ASSERT, lwip_netconn_do_close_internal(), api_msg_msg::msg, NETCONN_CLOSE, netconn_drain(), NETCONN_LISTEN, NETCONN_NONE, NETCONN_SHUT_RD, NETCONN_SHUT_RDWR, NETCONN_TCP, NETCONNTYPE_GROUP, NULL, netconn::pcb, api_msg_msg::sd, netconn::state, sys_sem_signal(), netconn::tcp, netconn::type, and netconn::write_offset.

Referenced by netconn_close_shutdown().

LWIP_NETCONN_SCOPE void lwip_netconn_do_disconnect ( struct api_msg_msg msg)

Connect a pcb contained inside a netconn Only used for UDP netconns.

Called from netconn_disconnect.

Parameters
msgthe api_msg_msg pointing to the connection to disconnect

References api_msg_msg::conn, api_msg_msg::err, ERR_OK, ERR_VAL, NETCONN_UDP, NETCONNTYPE_GROUP, netconn::pcb, TCPIP_APIMSG_ACK, netconn::type, netconn::udp, and udp_disconnect().

Referenced by netconn_disconnect().

LWIP_NETCONN_SCOPE void lwip_netconn_do_gethostbyname ( void arg)

Execute a DNS query Called from netconn_gethostbyname.

Parameters
argthe dns_api_msg pointing to the query

References API_EXPR_DEREF, API_EXPR_REF, dns_gethostbyname(), ERR_INPROGRESS, lwip_netconn_do_dns_found(), dns_api_msg::name, and sys_sem_signal().

Referenced by netconn_gethostbyname().

LWIP_NETCONN_SCOPE void lwip_netconn_do_join_leave_group ( struct api_msg_msg msg)
LWIP_NETCONN_SCOPE void lwip_netconn_do_newconn ( struct api_msg_msg msg)

Create a new pcb of a specific type inside a netconn.

Called from netconn_new_with_proto_and_callback.

Parameters
msgthe api_msg_msg describing the connection type

References api_msg_msg::conn, api_msg_msg::err, ERR_OK, NULL, netconn::pcb, pcb_new(), netconn::tcp, and TCPIP_APIMSG_ACK.

Referenced by netconn_new_with_proto_and_callback().

LWIP_NETCONN_SCOPE void lwip_netconn_do_recv ( struct api_msg_msg msg)

Indicate data has been received from a TCP pcb contained in a netconn Called from netconn_recv.

Parameters
msgthe api_msg_msg pointing to the connection

References api_msg_msg::conn, api_msg_msg::err, ERR_OK, LISTEN, api_msg_msg::msg, NETCONN_TCP, NETCONNTYPE_GROUP, NULL, netconn::pcb, api_msg_msg::r, netconn::tcp, tcp_accepted, tcp_recved(), TCPIP_APIMSG_ACK, and netconn::type.

Referenced by netconn_accept(), netconn_recv_data(), and netconn_recved().

LWIP_NETCONN_SCOPE void lwip_netconn_do_send ( struct api_msg_msg msg)
LWIP_NETCONN_SCOPE void lwip_netconn_do_shutdown ( struct api_msg_msg msg)
LWIP_NETCONN_SCOPE struct netconn* netconn_alloc ( enum netconn_type  t,
netconn_callback  callback 
)

Create a new netconn (of a specific type) that has a callback function.

The corresponding pcb is NOT created!

Parameters
tthe type of 'connection' to create (
See Also
enum netconn_type)
Parameters
protothe IP protocol for RAW IP pcbs
callbacka function to call on status changes (RX available, TX'ed)
Returns
a newly allocated struct netconn or NULL on memory error

References netconn::acceptmbox, netconn::callback, netconn::current_msg, DEFAULT_RAW_RECVMBOX_SIZE, DEFAULT_TCP_RECVMBOX_SIZE, DEFAULT_UDP_RECVMBOX_SIZE, ERR_OK, netconn::flags, netconn::last_err, LWIP_ASSERT, memp_free(), memp_malloc(), NETCONN_NONE, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::op_completed, netconn::pcb, netconn::recvmbox, netconn::state, sys_mbox_free(), sys_mbox_new(), sys_mbox_set_invalid(), sys_sem_new(), netconn::tcp, netconn::type, and netconn::write_offset.

Referenced by accept_function(), and netconn_new_with_proto_and_callback().

LWIP_NETCONN_SCOPE void netconn_free ( struct netconn conn)

Delete a netconn and all its resources.

The pcb is NOT freed (since we might not be in the right thread context do this).

Parameters
connthe netconn to free

References netconn::acceptmbox, LWIP_ASSERT, memp_free(), NULL, netconn::op_completed, netconn::pcb, netconn::recvmbox, sys_mbox_valid(), sys_sem_free(), sys_sem_set_invalid(), and netconn::tcp.

Referenced by accept_function(), netconn_delete(), and netconn_drain().