]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/ethernet/lwIP_130/src/include/lwip/api.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / Common / ethernet / lwIP_130 / src / include / lwip / api.h
1 /*\r
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.\r
3  * All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without modification,\r
6  * are permitted provided that the following conditions are met:\r
7  *\r
8  * 1. Redistributions of source code must retain the above copyright notice,\r
9  *    this list of conditions and the following disclaimer.\r
10  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
11  *    this list of conditions and the following disclaimer in the documentation\r
12  *    and/or other materials provided with the distribution.\r
13  * 3. The name of the author may not be used to endorse or promote products\r
14  *    derived from this software without specific prior written permission.\r
15  *\r
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT\r
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\r
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY\r
25  * OF SUCH DAMAGE.\r
26  *\r
27  * This file is part of the lwIP TCP/IP stack.\r
28  *\r
29  * Author: Adam Dunkels <adam@sics.se>\r
30  *\r
31  */\r
32 #ifndef __LWIP_API_H__\r
33 #define __LWIP_API_H__\r
34 \r
35 #include "lwip/opt.h"\r
36 \r
37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */\r
38 \r
39 #include "lwip/netbuf.h"\r
40 #include "lwip/sys.h"\r
41 #include "lwip/ip_addr.h"\r
42 #include "lwip/err.h"\r
43 \r
44 #ifdef __cplusplus\r
45 extern "C" {\r
46 #endif\r
47 \r
48 /* Throughout this file, IP addresses and port numbers are expected to be in\r
49  * the same byte order as in the corresponding pcb.\r
50  */\r
51 \r
52 /* Flags for netconn_write */\r
53 #define NETCONN_NOFLAG 0x00\r
54 #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */\r
55 #define NETCONN_COPY   0x01\r
56 #define NETCONN_MORE   0x02\r
57 \r
58 /* Helpers to process several netconn_types by the same code */\r
59 #define NETCONNTYPE_GROUP(t)    (t&0xF0)\r
60 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)\r
61 \r
62 enum netconn_type {\r
63   NETCONN_INVALID    = 0,\r
64   /* NETCONN_TCP Group */\r
65   NETCONN_TCP        = 0x10,\r
66   /* NETCONN_UDP Group */\r
67   NETCONN_UDP        = 0x20,\r
68   NETCONN_UDPLITE    = 0x21,\r
69   NETCONN_UDPNOCHKSUM= 0x22,\r
70   /* NETCONN_RAW Group */\r
71   NETCONN_RAW        = 0x40\r
72 };\r
73 \r
74 enum netconn_state {\r
75   NETCONN_NONE,\r
76   NETCONN_WRITE,\r
77   NETCONN_LISTEN,\r
78   NETCONN_CONNECT,\r
79   NETCONN_CLOSE\r
80 };\r
81 \r
82 enum netconn_evt {\r
83   NETCONN_EVT_RCVPLUS,\r
84   NETCONN_EVT_RCVMINUS,\r
85   NETCONN_EVT_SENDPLUS,\r
86   NETCONN_EVT_SENDMINUS\r
87 };\r
88 \r
89 #if LWIP_IGMP\r
90 enum netconn_igmp {\r
91   NETCONN_JOIN,\r
92   NETCONN_LEAVE\r
93 };\r
94 #endif /* LWIP_IGMP */\r
95 \r
96 /* forward-declare some structs to avoid to include their headers */\r
97 struct ip_pcb;\r
98 struct tcp_pcb;\r
99 struct udp_pcb;\r
100 struct raw_pcb;\r
101 struct netconn;\r
102 \r
103 /** A callback prototype to inform about events for a netconn */\r
104 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);\r
105 \r
106 /** A netconn descriptor */\r
107 struct netconn {\r
108   /** type of the netconn (TCP, UDP or RAW) */\r
109   enum netconn_type type;\r
110   /** current state of the netconn */\r
111   enum netconn_state state;\r
112   /** the lwIP internal protocol control block */\r
113   union {\r
114     struct ip_pcb  *ip;\r
115     struct tcp_pcb *tcp;\r
116     struct udp_pcb *udp;\r
117     struct raw_pcb *raw;\r
118   } pcb;\r
119   /** the last error this netconn had */\r
120   err_t err;\r
121   /** sem that is used to synchroneously execute functions in the core context */\r
122   sys_sem_t op_completed;\r
123   /** mbox where received packets are stored until they are fetched\r
124       by the netconn application thread (can grow quite big) */\r
125   sys_mbox_t recvmbox;\r
126   /** mbox where new connections are stored until processed\r
127       by the application thread */\r
128   sys_mbox_t acceptmbox;\r
129   /** only used for socket layer */\r
130   int socket;\r
131 #if LWIP_SO_RCVTIMEO\r
132   /** timeout to wait for new data to be received\r
133       (or connections to arrive for listening netconns) */\r
134   int recv_timeout;\r
135 #endif /* LWIP_SO_RCVTIMEO */\r
136 #if LWIP_SO_RCVBUF\r
137   /** maximum amount of bytes queued in recvmbox */\r
138   int recv_bufsize;\r
139 #endif /* LWIP_SO_RCVBUF */\r
140   u16_t recv_avail;\r
141   /** TCP: when data passed to netconn_write doesn't fit into the send buffer,\r
142       this temporarily stores the message. */\r
143   struct api_msg_msg *write_msg;\r
144   /** TCP: when data passed to netconn_write doesn't fit into the send buffer,\r
145       this temporarily stores how much is already sent. */\r
146   int write_offset;\r
147 #if LWIP_TCPIP_CORE_LOCKING\r
148   /** TCP: when data passed to netconn_write doesn't fit into the send buffer,\r
149       this temporarily stores whether to wake up the original application task\r
150       if data couldn't be sent in the first try. */\r
151   u8_t write_delayed;\r
152 #endif /* LWIP_TCPIP_CORE_LOCKING */\r
153   /** A callback function that is informed about events for this netconn */\r
154   netconn_callback callback;\r
155 };\r
156 \r
157 /* Register an Network connection event */\r
158 #define API_EVENT(c,e,l) if (c->callback) {         \\r
159                            (*c->callback)(c, e, l); \\r
160                          }\r
161 \r
162 /* Network connection functions: */\r
163 #define netconn_new(t)                  netconn_new_with_proto_and_callback(t, 0, NULL)\r
164 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)\r
165 struct\r
166 netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,\r
167                                    netconn_callback callback);\r
168 err_t             netconn_delete  (struct netconn *conn);\r
169 enum netconn_type netconn_type    (struct netconn *conn);\r
170 \r
171 err_t             netconn_getaddr (struct netconn *conn,\r
172                                    struct ip_addr *addr,\r
173                                    u16_t *port,\r
174                                    u8_t local);\r
175 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)\r
176 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)\r
177 \r
178 err_t             netconn_bind    (struct netconn *conn,\r
179                                    struct ip_addr *addr,\r
180                                    u16_t port);\r
181 err_t             netconn_connect (struct netconn *conn,\r
182                                    struct ip_addr *addr,\r
183                                    u16_t port);\r
184 err_t             netconn_disconnect (struct netconn *conn);\r
185 err_t             netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);\r
186 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)\r
187 struct netconn *  netconn_accept  (struct netconn *conn);\r
188 struct netbuf *   netconn_recv    (struct netconn *conn);\r
189 err_t             netconn_sendto  (struct netconn *conn,\r
190                                    struct netbuf *buf, struct ip_addr *addr, u16_t port);\r
191 err_t             netconn_send    (struct netconn *conn,\r
192                                    struct netbuf *buf);\r
193 err_t             netconn_write   (struct netconn *conn,\r
194                                    const void *dataptr, int size,\r
195                                    u8_t apiflags);\r
196 err_t             netconn_close   (struct netconn *conn);\r
197 \r
198 #if LWIP_IGMP\r
199 err_t             netconn_join_leave_group (struct netconn *conn,\r
200                                             struct ip_addr *multiaddr,\r
201                                             struct ip_addr *interface,\r
202                                             enum netconn_igmp join_or_leave);\r
203 #endif /* LWIP_IGMP */\r
204 #if LWIP_DNS\r
205 err_t             netconn_gethostbyname(const char *name, struct ip_addr *addr);\r
206 #endif /* LWIP_DNS */\r
207 \r
208 #define netconn_err(conn)          ((conn)->err)\r
209 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)\r
210 \r
211 #ifdef __cplusplus\r
212 }\r
213 #endif\r
214 \r
215 #endif /* LWIP_NETCONN */\r
216 \r
217 #endif /* __LWIP_API_H__ */\r