00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LWIP_API_H__
00033 #define __LWIP_API_H__
00034
00035 #include "lwip/opt.h"
00036
00037 #if LWIP_NETCONN
00038
00039 #include <stddef.h>
00040
00041 #include "lwip/netbuf.h"
00042 #include "lwip/sys.h"
00043 #include "lwip/ip_addr.h"
00044 #include "lwip/err.h"
00045
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049
00050
00051
00052
00053
00054
00055 #define NETCONN_NOFLAG 0x00
00056 #define NETCONN_NOCOPY 0x00
00057 #define NETCONN_COPY 0x01
00058 #define NETCONN_MORE 0x02
00059
00060
00061 #define NETCONNTYPE_GROUP(t) (t&0xF0)
00062 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
00063
00064 enum netconn_type {
00065 NETCONN_INVALID = 0,
00066
00067 NETCONN_TCP = 0x10,
00068
00069 NETCONN_UDP = 0x20,
00070 NETCONN_UDPLITE = 0x21,
00071 NETCONN_UDPNOCHKSUM= 0x22,
00072
00073 NETCONN_RAW = 0x40
00074 };
00075
00076 enum netconn_state {
00077 NETCONN_NONE,
00078 NETCONN_WRITE,
00079 NETCONN_LISTEN,
00080 NETCONN_CONNECT,
00081 NETCONN_CLOSE
00082 };
00083
00084 enum netconn_evt {
00085 NETCONN_EVT_RCVPLUS,
00086 NETCONN_EVT_RCVMINUS,
00087 NETCONN_EVT_SENDPLUS,
00088 NETCONN_EVT_SENDMINUS
00089 };
00090
00091 #if LWIP_IGMP
00092 enum netconn_igmp {
00093 NETCONN_JOIN,
00094 NETCONN_LEAVE
00095 };
00096 #endif
00097
00098
00099 struct ip_pcb;
00100 struct tcp_pcb;
00101 struct udp_pcb;
00102 struct raw_pcb;
00103 struct netconn;
00104
00105
00106 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
00107
00108
00109 struct netconn {
00110
00111 enum netconn_type type;
00112
00113 enum netconn_state state;
00114
00115 union {
00116 struct ip_pcb *ip;
00117 struct tcp_pcb *tcp;
00118 struct udp_pcb *udp;
00119 struct raw_pcb *raw;
00120 } pcb;
00121
00122 err_t err;
00123
00124 sys_sem_t op_completed;
00125
00126
00127 sys_mbox_t recvmbox;
00128
00129
00130 sys_mbox_t acceptmbox;
00131
00132 int socket;
00133 #if LWIP_SO_RCVTIMEO
00134
00135
00136 int recv_timeout;
00137 #endif
00138 #if LWIP_SO_RCVBUF
00139
00140 int recv_bufsize;
00141 #endif
00142 s16_t recv_avail;
00143 #if LWIP_TCP
00144
00145
00146 struct api_msg_msg *write_msg;
00147
00148
00149 size_t write_offset;
00150 #if LWIP_TCPIP_CORE_LOCKING
00151
00152
00153
00154 u8_t write_delayed;
00155 #endif
00156 #endif
00157
00158 netconn_callback callback;
00159 };
00160
00161
00162 #define API_EVENT(c,e,l) if (c->callback) { \
00163 (*c->callback)(c, e, l); \
00164 }
00165
00166
00167 #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
00168 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
00169 struct
00170 netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
00171 netconn_callback callback);
00172 err_t netconn_delete (struct netconn *conn);
00173
00174 #define netconn_type(conn) (conn->type)
00175
00176 err_t netconn_getaddr (struct netconn *conn,
00177 struct ip_addr *addr,
00178 u16_t *port,
00179 u8_t local);
00180 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
00181 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
00182
00183 err_t netconn_bind (struct netconn *conn,
00184 struct ip_addr *addr,
00185 u16_t port);
00186 err_t netconn_connect (struct netconn *conn,
00187 struct ip_addr *addr,
00188 u16_t port);
00189 err_t netconn_disconnect (struct netconn *conn);
00190 err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
00191 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
00192 struct netconn * netconn_accept (struct netconn *conn);
00193 struct netbuf * netconn_recv (struct netconn *conn);
00194 err_t netconn_sendto (struct netconn *conn,
00195 struct netbuf *buf, struct ip_addr *addr, u16_t port);
00196 err_t netconn_send (struct netconn *conn,
00197 struct netbuf *buf);
00198 err_t netconn_write (struct netconn *conn,
00199 const void *dataptr, size_t size,
00200 u8_t apiflags);
00201 err_t netconn_close (struct netconn *conn);
00202
00203 #if LWIP_IGMP
00204 err_t netconn_join_leave_group (struct netconn *conn,
00205 struct ip_addr *multiaddr,
00206 struct ip_addr *interface,
00207 enum netconn_igmp join_or_leave);
00208 #endif
00209 #if LWIP_DNS
00210 err_t netconn_gethostbyname(const char *name, struct ip_addr *addr);
00211 #endif
00212
00213 #define netconn_err(conn) ((conn)->err)
00214 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
00215
00216 #ifdef __cplusplus
00217 }
00218 #endif
00219
00220 #endif
00221
00222 #endif