32 #ifndef __LWIP_API_H__
33 #define __LWIP_API_H__
41 #include "lwip/netbuf.h"
43 #include "lwip/ip_addr.h"
55 #define NETCONN_NOFLAG 0x00
56 #define NETCONN_NOCOPY 0x00
57 #define NETCONN_COPY 0x01
58 #define NETCONN_MORE 0x02
59 #define NETCONN_DONTBLOCK 0x04
65 #define NETCONN_FLAG_WRITE_DELAYED 0x01
67 #define NETCONN_FLAG_NON_BLOCKING 0x02
69 #define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
72 #define NETCONN_FLAG_NO_AUTO_RECVED 0x08
75 #define NETCONN_FLAG_CHECK_WRITESPACE 0x10
79 #define NETCONNTYPE_GROUP(t) (t&0xF0)
80 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
89 NETCONN_UDPLITE = 0x21,
90 NETCONN_UDPNOCHKSUM= 0x22,
108 NETCONN_EVT_RCVMINUS,
109 NETCONN_EVT_SENDPLUS,
110 NETCONN_EVT_SENDMINUS,
131 typedef void (* netconn_callback)(
struct netconn *,
enum netconn_evt, u16_t len);
136 enum netconn_type type;
138 enum netconn_state state;
149 sys_sem_t op_completed;
156 sys_mbox_t acceptmbox;
185 struct api_msg_msg *current_msg;
188 netconn_callback callback;
192 #define API_EVENT(c,e,l) if (c->callback) { \
193 (*c->callback)(c, e, l); \
197 #define NETCONN_SET_SAFE_ERR(conn, err) do { \
198 SYS_ARCH_DECL_PROTECT(lev); \
199 SYS_ARCH_PROTECT(lev); \
200 if (!ERR_IS_FATAL((conn)->last_err)) { \
201 (conn)->last_err = err; \
203 SYS_ARCH_UNPROTECT(lev); \
207 #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
208 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
210 netconn *netconn_new_with_proto_and_callback(
enum netconn_type t, u8_t proto,
211 netconn_callback callback);
212 err_t netconn_delete(
struct netconn *conn);
214 #define netconn_type(conn) (conn->type)
216 err_t netconn_getaddr(
struct netconn *conn, ip_addr_t *addr,
217 u16_t *port, u8_t local);
218 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
219 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
221 err_t netconn_bind(
struct netconn *conn, ip_addr_t *addr, u16_t port);
222 err_t netconn_connect(
struct netconn *conn, ip_addr_t *addr, u16_t port);
223 err_t netconn_disconnect (
struct netconn *conn);
224 err_t netconn_listen_with_backlog(
struct netconn *conn, u8_t backlog);
225 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
226 err_t netconn_accept(
struct netconn *conn,
struct netconn **new_conn);
227 err_t netconn_recv(
struct netconn *conn,
struct netbuf **new_buf);
228 err_t netconn_recv_tcp_pbuf(
struct netconn *conn,
struct pbuf **new_buf);
229 void netconn_recved(
struct netconn *conn, u32_t length);
230 err_t netconn_sendto(
struct netconn *conn,
struct netbuf *buf,
231 ip_addr_t *addr, u16_t port);
232 err_t netconn_send(
struct netconn *conn,
struct netbuf *buf);
233 err_t netconn_write(
struct netconn *conn,
const void *dataptr,
size_t size,
235 err_t netconn_close(
struct netconn *conn);
236 err_t netconn_shutdown(
struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
239 err_t netconn_join_leave_group(
struct netconn *conn, ip_addr_t *multiaddr,
240 ip_addr_t *netif_addr,
enum netconn_igmp join_or_leave);
243 err_t netconn_gethostbyname(
const char *name, ip_addr_t *addr);
246 #define netconn_err(conn) ((conn)->last_err)
247 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
250 #define netconn_set_nonblocking(conn, val) do { if(val) { \
251 (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
253 (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
255 #define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
258 #define netconn_set_noautorecved(conn, val) do { if(val) { \
259 (conn)->flags |= NETCONN_FLAG_NO_AUTO_RECVED; \
261 (conn)->flags &= ~ NETCONN_FLAG_NO_AUTO_RECVED; }} while(0)
263 #define netconn_get_noautorecved(conn) (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0)
267 #define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout))
269 #define netconn_get_recvtimeout(conn) ((conn)->recv_timeout)
273 #define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize))
275 #define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize)