37 #ifndef LWIP_HDR_API_H
38 #define LWIP_HDR_API_H
42 #if LWIP_NETCONN || LWIP_SOCKET
61 #define NETCONN_NOFLAG 0x00
62 #define NETCONN_NOCOPY 0x00
63 #define NETCONN_COPY 0x01
64 #define NETCONN_MORE 0x02
65 #define NETCONN_DONTBLOCK 0x04
69 #define NETCONN_FLAG_NON_BLOCKING 0x02
71 #define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
74 #define NETCONN_FLAG_CHECK_WRITESPACE 0x10
79 #define NETCONN_FLAG_IPV6_V6ONLY 0x20
84 #define NETCONNTYPE_GROUP(t) ((t)&0xF0)
85 #define NETCONNTYPE_DATAGRAM(t) ((t)&0xE0)
87 #define NETCONN_TYPE_IPV6 0x08
88 #define NETCONNTYPE_ISIPV6(t) (((t)&NETCONN_TYPE_IPV6) != 0)
89 #define NETCONNTYPE_ISUDPLITE(t) (((t)&0xF3) == NETCONN_UDPLITE)
90 #define NETCONNTYPE_ISUDPNOCHKSUM(t) (((t)&0xF3) == NETCONN_UDPNOCHKSUM)
92 #define NETCONNTYPE_ISIPV6(t) (0)
93 #define NETCONNTYPE_ISUDPLITE(t) ((t) == NETCONN_UDPLITE)
94 #define NETCONNTYPE_ISUDPNOCHKSUM(t) ((t) == NETCONN_UDPNOCHKSUM)
106 NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6 ,
111 NETCONN_UDPLITE = 0x21,
113 NETCONN_UDPNOCHKSUM = 0x22,
117 NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6 ,
119 NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6 ,
121 NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6 ,
128 , NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6
170 NETCONN_EVT_RCVMINUS,
171 NETCONN_EVT_SENDPLUS,
172 NETCONN_EVT_SENDMINUS,
176 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
186 #define NETCONN_DNS_DEFAULT NETCONN_DNS_IPV4_IPV6
187 #define NETCONN_DNS_IPV4 0
188 #define NETCONN_DNS_IPV6 1
189 #define NETCONN_DNS_IPV4_IPV6 2
190 #define NETCONN_DNS_IPV6_IPV4 3
202 typedef void (* netconn_callback)(
struct netconn *,
enum netconn_evt,
u16_t len);
207 enum netconn_type type;
209 enum netconn_state state;
219 #if !LWIP_NETCONN_SEM_PER_THREAD
267 struct api_msg *current_msg;
270 netconn_callback callback;
274 #define API_EVENT(c,e,l) if (c->callback) { \
275 (*c->callback)(c, e, l); \
279 #define NETCONN_SET_SAFE_ERR(conn, err) do { if ((conn) != NULL) { \
280 SYS_ARCH_DECL_PROTECT(netconn_set_safe_err_lev); \
281 SYS_ARCH_PROTECT(netconn_set_safe_err_lev); \
282 if (!ERR_IS_FATAL((conn)->last_err)) { \
283 (conn)->last_err = err; \
285 SYS_ARCH_UNPROTECT(netconn_set_safe_err_lev); \
293 #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
294 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
295 struct netconn *netconn_new_with_proto_and_callback(
enum netconn_type t,
u8_t proto,
296 netconn_callback callback);
297 err_t netconn_delete(
struct netconn *conn);
299 #define netconn_type(conn) (conn->type)
304 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
306 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
310 err_t netconn_disconnect (
struct netconn *conn);
311 err_t netconn_listen_with_backlog(
struct netconn *conn,
u8_t backlog);
313 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
314 err_t netconn_accept(
struct netconn *conn,
struct netconn **new_conn);
315 err_t netconn_recv(
struct netconn *conn,
struct netbuf **new_buf);
316 err_t netconn_recv_tcp_pbuf(
struct netconn *conn,
struct pbuf **new_buf);
317 err_t netconn_sendto(
struct netconn *conn,
struct netbuf *
buf,
319 err_t netconn_send(
struct netconn *conn,
struct netbuf *
buf);
320 err_t netconn_write_partly(
struct netconn *conn,
const void *dataptr,
size_t size,
321 u8_t apiflags,
size_t *bytes_written);
323 #define netconn_write(conn, dataptr, size, apiflags) \
324 netconn_write_partly(conn, dataptr, size, apiflags, NULL)
325 err_t netconn_close(
struct netconn *conn);
326 err_t netconn_shutdown(
struct netconn *conn,
u8_t shut_rx,
u8_t shut_tx);
328 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
329 err_t netconn_join_leave_group(
struct netconn *conn,
const ip_addr_t *multiaddr,
330 const ip_addr_t *netif_addr,
enum netconn_igmp join_or_leave);
333 #if LWIP_IPV4 && LWIP_IPV6
335 #define netconn_gethostbyname(name, addr) netconn_gethostbyname_addrtype(name, addr, NETCONN_DNS_DEFAULT)
338 #define netconn_gethostbyname_addrtype(name, addr, dns_addrtype) netconn_gethostbyname(name, addr)
342 #define netconn_err(conn) ((conn)->last_err)
343 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
346 #define netconn_set_nonblocking(conn, val) do { if(val) { \
347 (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
349 (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
351 #define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
357 #define netconn_set_ipv6only(conn, val) do { if(val) { \
358 (conn)->flags |= NETCONN_FLAG_IPV6_V6ONLY; \
360 (conn)->flags &= ~ NETCONN_FLAG_IPV6_V6ONLY; }} while(0)
364 #define netconn_get_ipv6only(conn) (((conn)->flags & NETCONN_FLAG_IPV6_V6ONLY) != 0)
369 #define netconn_set_sendtimeout(conn, timeout) ((conn)->send_timeout = (timeout))
371 #define netconn_get_sendtimeout(conn) ((conn)->send_timeout)
375 #define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout))
377 #define netconn_get_recvtimeout(conn) ((conn)->recv_timeout)
381 #define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize))
383 #define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize)
386 #if LWIP_NETCONN_SEM_PER_THREAD
387 void netconn_thread_init(
void);
388 void netconn_thread_cleanup(
void);
390 #define netconn_thread_init()
391 #define netconn_thread_cleanup()