#include "lwip/opt.h"
#include <stddef.h>
#include "lwip/netbuf.h"
#include "lwip/sys.h"
#include "lwip/ip_addr.h"
#include "lwip/err.h"
Data Structures | |
struct | netconn |
A netconn descriptor. More... | |
Macros | |
#define | API_EVENT(c, e, l) |
Register an Network connection event. More... | |
#define | netconn_addr(c, i, p) netconn_getaddr(c,i,p,1) |
#define | NETCONN_COPY 0x01 |
#define | NETCONN_DONTBLOCK 0x04 |
#define | netconn_err(conn) ((conn)->last_err) |
#define | NETCONN_FLAG_CHECK_WRITESPACE 0x10 |
If a nonblocking write has been rejected before, poll_tcp needs to check if the netconn is writable again. More... | |
#define | NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 |
Was the last connect action a non-blocking one? More... | |
#define | NETCONN_FLAG_NO_AUTO_RECVED 0x08 |
If this is set, a TCP netconn must call netconn_recved() to update the TCP receive window (done automatically if not set). More... | |
#define | NETCONN_FLAG_NON_BLOCKING 0x02 |
Should this netconn avoid blocking? More... | |
#define | NETCONN_FLAG_WRITE_DELAYED 0x01 |
TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores whether to wake up the original application task if data couldn't be sent in the first try. More... | |
#define | netconn_get_noautorecved(conn) (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0) |
TCP: Get the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) More... | |
#define | netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0) |
Get the blocking status of netconn calls (. More... | |
#define | netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG) |
#define | NETCONN_MORE 0x02 |
#define | netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL) |
#define | netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c) |
#define | NETCONN_NOCOPY 0x00 /* Only for source code compatibility */ |
#define | NETCONN_NOFLAG 0x00 |
#define | netconn_peer(c, i, p) netconn_getaddr(c,i,p,0) |
#define | netconn_recv_bufsize(conn) ((conn)->recv_bufsize) |
#define | netconn_set_noautorecved(conn, val) |
TCP: Set the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) More... | |
#define | netconn_set_nonblocking(conn, val) |
Set the blocking status of netconn calls (. More... | |
#define | NETCONN_SET_SAFE_ERR(conn, err) |
Set conn->last_err to err but don't overwrite fatal errors. More... | |
#define | netconn_type(conn) (conn->type) |
Get the type of a netconn (as enum netconn_type). More... | |
#define | NETCONNTYPE_DATAGRAM(t) (t&0xE0) |
#define | NETCONNTYPE_GROUP(t) (t&0xF0) |
Typedefs | |
typedef void(* | netconn_callback )(struct netconn *, enum netconn_evt, u16_t len) |
A callback prototype to inform about events for a netconn. More... | |
Enumerations | |
enum | netconn_evt { NETCONN_EVT_RCVPLUS, NETCONN_EVT_RCVMINUS, NETCONN_EVT_SENDPLUS, NETCONN_EVT_SENDMINUS, NETCONN_EVT_ERROR } |
Use to inform the callback function about changes. More... | |
enum | netconn_state { NETCONN_NONE, NETCONN_WRITE, NETCONN_LISTEN, NETCONN_CONNECT, NETCONN_CLOSE } |
Current state of the netconn. More... | |
enum | netconn_type { NETCONN_INVALID = 0, NETCONN_TCP = 0x10, NETCONN_UDP = 0x20, NETCONN_UDPLITE = 0x21, NETCONN_UDPNOCHKSUM = 0x22, NETCONN_RAW = 0x40 } |
Protocol family and type of the netconn. More... | |
Functions | |
err_t | netconn_accept (struct netconn *conn, struct netconn **new_conn) |
Accept a new connection on a TCP listening netconn. More... | |
err_t | netconn_bind (struct netconn *conn, ip_addr_t *addr, u16_t port) |
Bind a netconn to a specific local IP address and port. More... | |
err_t | netconn_close (struct netconn *conn) |
Close a TCP netconn (doesn't delete it). More... | |
err_t | netconn_connect (struct netconn *conn, ip_addr_t *addr, u16_t port) |
Connect a netconn to a specific remote IP address and port. More... | |
err_t | netconn_delete (struct netconn *conn) |
Close a netconn 'connection' and free its resources. More... | |
err_t | netconn_disconnect (struct netconn *conn) |
Disconnect a netconn from its current peer (only valid for UDP netconns). More... | |
err_t | netconn_getaddr (struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local) |
Get the local or remote IP address and port of a netconn. More... | |
err_t | netconn_listen_with_backlog (struct netconn *conn, u8_t backlog) |
Set a TCP netconn into listen mode. More... | |
struct netconn * | netconn_new_with_proto_and_callback (enum netconn_type t, u8_t proto, netconn_callback callback) |
Create a new netconn (of a specific type) that has a callback function. More... | |
err_t | netconn_recv (struct netconn *conn, struct netbuf **new_buf) |
Receive data (in form of a netbuf containing a packet buffer) from a netconn. More... | |
err_t | netconn_recv_tcp_pbuf (struct netconn *conn, struct pbuf **new_buf) |
Receive data (in form of a pbuf) from a TCP netconn. More... | |
void | netconn_recved (struct netconn *conn, u32_t length) |
TCP: update the receive window: by calling this, the application tells the stack that it has processed data and is able to accept new data. More... | |
err_t | netconn_send (struct netconn *conn, struct netbuf *buf) |
Send data over a UDP or RAW netconn (that is already connected). More... | |
err_t | netconn_sendto (struct netconn *conn, struct netbuf *buf, ip_addr_t *addr, u16_t port) |
Send data (in form of a netbuf) to a specific remote IP address and port. More... | |
err_t | netconn_shutdown (struct netconn *conn, u8_t shut_rx, u8_t shut_tx) |
Shut down one or both sides of a TCP netconn (doesn't delete it). More... | |
err_t | netconn_write (struct netconn *conn, const void *dataptr, size_t size, u8_t apiflags) |
Send data over a TCP netconn. More... | |
#define API_EVENT | ( | c, | |
e, | |||
l | |||
) |
Register an Network connection event.
Referenced by accept_function(), do_close_internal(), do_connected(), do_delconn(), do_writemore(), err_tcp(), netconn_accept(), netconn_recv_data(), poll_tcp(), recv_raw(), recv_tcp(), recv_udp(), and sent_tcp().
#define netconn_addr | ( | c, | |
i, | |||
p | |||
) | netconn_getaddr(c,i,p,1) |
#define NETCONN_COPY 0x01 |
Referenced by lwip_send(), and prvweb_ParseHTMLRequest().
#define NETCONN_DONTBLOCK 0x04 |
Referenced by do_writemore(), and lwip_send().
#define netconn_err | ( | conn | ) | ((conn)->last_err) |
#define NETCONN_FLAG_CHECK_WRITESPACE 0x10 |
If a nonblocking write has been rejected before, poll_tcp needs to check if the netconn is writable again.
Referenced by do_writemore(), poll_tcp(), and sent_tcp().
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 |
Was the last connect action a non-blocking one?
#define NETCONN_FLAG_NO_AUTO_RECVED 0x08 |
If this is set, a TCP netconn must call netconn_recved() to update the TCP receive window (done automatically if not set).
#define NETCONN_FLAG_NON_BLOCKING 0x02 |
Should this netconn avoid blocking?
#define NETCONN_FLAG_WRITE_DELAYED 0x01 |
TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores whether to wake up the original application task if data couldn't be sent in the first try.
Referenced by do_write(), and do_writemore().
#define netconn_get_noautorecved | ( | conn | ) | (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0) |
TCP: Get the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED)
Referenced by netconn_recv_data(), and netconn_recved().
#define netconn_is_nonblocking | ( | conn | ) | (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0) |
Get the blocking status of netconn calls (.
Referenced by do_connect(), do_writemore(), lwip_accept(), lwip_fcntl(), lwip_recvfrom(), and lwip_send().
#define netconn_listen | ( | conn | ) | netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG) |
Referenced by portTASK_FUNCTION().
#define NETCONN_MORE 0x02 |
Referenced by lwip_send().
#define netconn_new | ( | t | ) | netconn_new_with_proto_and_callback(t, 0, NULL) |
Referenced by portTASK_FUNCTION().
#define netconn_new_with_callback | ( | t, | |
c | |||
) | netconn_new_with_proto_and_callback(t, 0, c) |
Referenced by lwip_socket().
#define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */ |
#define NETCONN_NOFLAG 0x00 |
#define netconn_peer | ( | c, | |
i, | |||
p | |||
) | netconn_getaddr(c,i,p,0) |
Referenced by lwip_accept().
#define netconn_recv_bufsize | ( | conn | ) | ((conn)->recv_bufsize) |
#define netconn_set_noautorecved | ( | conn, | |
val | |||
) |
TCP: Set the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED)
Referenced by lwip_accept(), and lwip_socket().
#define netconn_set_nonblocking | ( | conn, | |
val | |||
) |
Set the blocking status of netconn calls (.
Referenced by lwip_fcntl(), and lwip_ioctl().
#define NETCONN_SET_SAFE_ERR | ( | conn, | |
err | |||
) |
Set conn->last_err to err but don't overwrite fatal errors.
Referenced by do_connected(), netconn_accept(), netconn_bind(), netconn_close_shutdown(), netconn_connect(), netconn_disconnect(), netconn_getaddr(), netconn_listen_with_backlog(), netconn_recv(), netconn_recv_data(), netconn_send(), netconn_write(), and recv_tcp().
#define netconn_type | ( | conn | ) | (conn->type) |
Get the type of a netconn (as enum netconn_type).
#define NETCONNTYPE_DATAGRAM | ( | t | ) | (t&0xE0) |
#define NETCONNTYPE_GROUP | ( | t | ) | (t&0xF0) |
Referenced by do_bind(), do_connect(), do_delconn(), do_disconnect(), do_getaddr(), do_send(), lwip_getsockopt(), lwip_getsockopt_internal(), lwip_setsockopt(), netconn_alloc(), and pcb_new().
typedef void(* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len) |
A callback prototype to inform about events for a netconn.
enum netconn_evt |
enum netconn_state |
enum netconn_type |
Accept a new connection on a TCP listening netconn.
conn | the TCP listen netconn |
new_conn | pointer where the new connection is stored |
References netconn::acceptmbox, API_EVENT, api_msg_msg::conn, do_recv(), ERR_ABRT, ERR_ARG, ERR_IS_FATAL, ERR_OK, ERR_TIMEOUT, api_msg::function, netconn::last_err, LWIP_ERROR(), LWIP_UNUSED_ARG, api_msg::msg, NETCONN_EVT_RCVMINUS, NETCONN_SET_SAFE_ERR, NULL, sys_arch_mbox_fetch(), SYS_ARCH_TIMEOUT, sys_mbox_valid(), and TCPIP_APIMSG.
Referenced by lwip_accept(), and portTASK_FUNCTION().
Bind a netconn to a specific local IP address and port.
Binding one netconn twice might not always be checked correctly!
conn | the netconn to bind |
addr | the local IP address to bind the netconn to (use IP_ADDR_ANY to bind to all addresses) |
port | the local port to bind the netconn to (not used for RAW) |
References api_msg_msg::bc, api_msg_msg::conn, do_bind(), ERR_ARG, api_msg::function, LWIP_ERROR(), api_msg_msg::msg, api_msg::msg, NETCONN_SET_SAFE_ERR, NULL, and TCPIP_APIMSG.
Referenced by lwip_bind(), and portTASK_FUNCTION().
Close a TCP netconn (doesn't delete it).
conn | the TCP netconn to close |
References netconn_close_shutdown(), and NETCONN_SHUT_RDWR.
Referenced by prvweb_ParseHTMLRequest().
Connect a netconn to a specific remote IP address and port.
conn | the netconn to connect |
addr | the remote IP address to connect to |
port | the remote port to connect to (no used for RAW) |
References api_msg_msg::bc, api_msg_msg::conn, do_connect(), ERR_ARG, api_msg::function, LWIP_ERROR(), api_msg_msg::msg, api_msg::msg, NETCONN_SET_SAFE_ERR, NULL, and tcpip_apimsg().
Referenced by lwip_connect().
Close a netconn 'connection' and free its resources.
UDP and RAW connection are completely closed, TCP pcbs might still be in a waitstate after this returns.
conn | the netconn to delete |
References api_msg_msg::conn, do_delconn(), ERR_OK, api_msg::function, api_msg::msg, netconn_free(), NULL, and tcpip_apimsg().
Referenced by lwip_accept(), lwip_close(), lwip_socket(), and prvweb_ParseHTMLRequest().
Disconnect a netconn from its current peer (only valid for UDP netconns).
conn | the netconn to disconnect |
References api_msg_msg::conn, do_disconnect(), ERR_ARG, api_msg::function, LWIP_ERROR(), api_msg::msg, NETCONN_SET_SAFE_ERR, NULL, and TCPIP_APIMSG.
Referenced by lwip_connect().
Get the local or remote IP address and port of a netconn.
For RAW netconns, this returns the protocol instead of a port!
conn | the netconn to query |
addr | a pointer to which to save the IP address |
port | a pointer to which to save the port (or protocol for RAW) |
local | 1 to get the local IP address, 0 to get the remote one |
References api_msg_msg::ad, api_msg_msg::conn, do_getaddr(), ERR_ARG, api_msg::function, LWIP_ERROR(), api_msg_msg::msg, api_msg::msg, NETCONN_SET_SAFE_ERR, NULL, and TCPIP_APIMSG.
Referenced by lwip_getaddrname(), and lwip_recvfrom().
Set a TCP netconn into listen mode.
conn | the tcp netconn to set to listen mode |
backlog | the listen backlog, only used if TCP_LISTEN_BACKLOG==1 |
References api_msg_msg::conn, do_listen(), ERR_ARG, api_msg::function, LWIP_ERROR(), LWIP_UNUSED_ARG, api_msg_msg::msg, api_msg::msg, NETCONN_SET_SAFE_ERR, NULL, and TCPIP_APIMSG.
Referenced by lwip_listen().
struct netconn* netconn_new_with_proto_and_callback | ( | enum netconn_type | t, |
u8_t | proto, | ||
netconn_callback | callback | ||
) |
Create a new netconn (of a specific type) that has a callback function.
The corresponding pcb is also created.
t | the type of 'connection' to create ( |
proto | the IP protocol for RAW IP pcbs |
callback | a function to call on status changes (RX available, TX'ed) |
References api_msg_msg::conn, do_newconn(), ERR_OK, api_msg::function, LWIP_ASSERT, memp_free(), api_msg_msg::msg, api_msg::msg, api_msg_msg::n, netconn_alloc(), NULL, sys_mbox_free(), sys_mbox_valid(), sys_sem_free(), sys_sem_valid(), and TCPIP_APIMSG.
Referenced by lwip_socket().
Receive data (in form of a netbuf containing a packet buffer) from a netconn.
conn | the netconn from which to receive data |
new_buf | pointer where a new netbuf is stored when received data |
References netbuf::addr, ERR_ARG, ERR_CONN, ERR_MEM, ERR_OK, ip_addr_set_any, LWIP_ASSERT, LWIP_ERROR(), memp_free(), memp_malloc(), netconn_recv_data(), NETCONN_SET_SAFE_ERR, NETCONN_TCP, NULL, netbuf::p, netbuf::port, netbuf::ptr, netconn::recvmbox, sys_mbox_valid(), and netconn::type.
Referenced by lwip_recvfrom(), and prvweb_ParseHTMLRequest().
Receive data (in form of a pbuf) from a TCP netconn.
conn | the netconn from which to receive data |
new_buf | pointer where a new pbuf is stored when received data |
References ERR_ARG, LWIP_ERROR(), netconn_recv_data(), NETCONN_TCP, and NULL.
Referenced by lwip_recvfrom().
TCP: update the receive window: by calling this, the application tells the stack that it has processed data and is able to accept new data.
ATTENTION: use with care, this is mainly used for sockets! Can only be used when calling netconn_set_noautorecved(conn, 1) before.
conn | the netconn for which to update the receive window |
length | amount of data processed (ATTENTION: this must be accurate!) |
References api_msg_msg::conn, do_recv(), api_msg::function, LWIP_UNUSED_ARG, api_msg_msg::msg, api_msg::msg, netconn_get_noautorecved, NETCONN_TCP, NULL, api_msg_msg::r, TCPIP_APIMSG, and netconn::type.
Referenced by lwip_recvfrom().
Send data over a UDP or RAW netconn (that is already connected).
conn | the UDP or RAW netconn over which to send data |
buf | a netbuf containing the data to send |
References API_LIB_DEBUG, api_msg_msg::b, api_msg_msg::conn, do_send(), ERR_ARG, api_msg::function, LWIP_DEBUGF, LWIP_ERROR(), api_msg_msg::msg, api_msg::msg, NETCONN_SET_SAFE_ERR, NULL, netbuf::p, TCPIP_APIMSG, pbuf::tot_len, and U16_F.
Referenced by lwip_sendto(), and netconn_sendto().
Send data (in form of a netbuf) to a specific remote IP address and port.
Only to be used for UDP and RAW netconns (not TCP).
conn | the netconn over which to send data |
buf | a netbuf containing the data to send |
addr | the remote IP address to which to send the data |
port | the remote port to which to send the data |
References netbuf::addr, ERR_VAL, ip_addr_set, netconn_send(), NULL, and netbuf::port.
Shut down one or both sides of a TCP netconn (doesn't delete it).
conn | the TCP netconn to shut down |
References netconn_close_shutdown(), NETCONN_SHUT_RD, and NETCONN_SHUT_WR.
Referenced by lwip_shutdown().
Send data over a TCP netconn.
conn | the TCP netconn over which to send data |
dataptr | pointer to the application buffer that contains the data to send |
size | size of the application data to send |
apiflags | combination of following flags :
|
References api_msg_msg::conn, do_write(), ERR_ARG, ERR_OK, ERR_VAL, api_msg::function, LWIP_ERROR(), api_msg_msg::msg, api_msg::msg, NETCONN_SET_SAFE_ERR, NETCONN_TCP, NULL, TCPIP_APIMSG, netconn::type, and api_msg_msg::w.
Referenced by lwip_send(), and prvweb_ParseHTMLRequest().