1 |
606 |
jeremybenn |
|
2 |
|
|
/**
|
3 |
|
|
* \addtogroup uip
|
4 |
|
|
* @{
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* \file
|
9 |
|
|
* Header file for the uIP TCP/IP stack.
|
10 |
|
|
* \author Adam Dunkels <adam@dunkels.com>
|
11 |
|
|
* \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
|
12 |
|
|
* \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
|
13 |
|
|
*
|
14 |
|
|
* The uIP TCP/IP stack header file contains definitions for a number
|
15 |
|
|
* of C macros that are used by uIP programs as well as internal uIP
|
16 |
|
|
* structures, TCP/IP header structures and function declarations.
|
17 |
|
|
*
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/*
|
21 |
|
|
* Copyright (c) 2001-2003, Adam Dunkels.
|
22 |
|
|
* All rights reserved.
|
23 |
|
|
*
|
24 |
|
|
* Redistribution and use in source and binary forms, with or without
|
25 |
|
|
* modification, are permitted provided that the following conditions
|
26 |
|
|
* are met:
|
27 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
28 |
|
|
* notice, this list of conditions and the following disclaimer.
|
29 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
30 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
31 |
|
|
* documentation and/or other materials provided with the distribution.
|
32 |
|
|
* 3. The name of the author may not be used to endorse or promote
|
33 |
|
|
* products derived from this software without specific prior
|
34 |
|
|
* written permission.
|
35 |
|
|
*
|
36 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
37 |
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
38 |
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
39 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
40 |
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
41 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
42 |
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
43 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
44 |
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
45 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
46 |
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
47 |
|
|
*
|
48 |
|
|
* This file is part of the uIP TCP/IP stack.
|
49 |
|
|
*
|
50 |
|
|
* $Id: uip.h 2 2011-07-17 20:13:17Z filepang@gmail.com $
|
51 |
|
|
*
|
52 |
|
|
*/
|
53 |
|
|
#ifndef __UIP_H__
|
54 |
|
|
#define __UIP_H__
|
55 |
|
|
|
56 |
|
|
#include "net/uipopt.h"
|
57 |
|
|
#include "uip-conf.h"
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Representation of an IP address.
|
61 |
|
|
*
|
62 |
|
|
*/
|
63 |
|
|
#if UIP_CONF_IPV6 != 0
|
64 |
|
|
typedef union uip_ip6addr_t
|
65 |
|
|
{
|
66 |
|
|
u8_t u8[16]; /* Initializer, must come first!!! */
|
67 |
|
|
u16_t u16[8];
|
68 |
|
|
} uip_ip6addr_t;
|
69 |
|
|
|
70 |
|
|
typedef uip_ip6addr_t uip_ipaddr_t;
|
71 |
|
|
#else /* UIP_CONF_IPV6 */
|
72 |
|
|
typedef union uip_ip4addr_t
|
73 |
|
|
{
|
74 |
|
|
u8_t u8[4]; /* Initializer, must come first!!! */
|
75 |
|
|
u16_t u16[2];
|
76 |
|
|
} uip_ip4addr_t;
|
77 |
|
|
typedef uip_ip4addr_t uip_ipaddr_t;
|
78 |
|
|
#endif /* UIP_CONF_IPV6 */
|
79 |
|
|
|
80 |
|
|
/*---------------------------------------------------------------------------*/
|
81 |
|
|
|
82 |
|
|
/** \brief 16 bit 802.15.4 address */
|
83 |
|
|
struct uip_802154_shortaddr
|
84 |
|
|
{
|
85 |
|
|
u8_t addr[2];
|
86 |
|
|
};
|
87 |
|
|
|
88 |
|
|
/** \brief 64 bit 802.15.4 address */
|
89 |
|
|
struct uip_802154_longaddr
|
90 |
|
|
{
|
91 |
|
|
u8_t addr[8];
|
92 |
|
|
};
|
93 |
|
|
|
94 |
|
|
/** \brief 802.11 address */
|
95 |
|
|
struct uip_80211_addr
|
96 |
|
|
{
|
97 |
|
|
u8_t addr[6];
|
98 |
|
|
};
|
99 |
|
|
|
100 |
|
|
/** \brief 802.3 address */
|
101 |
|
|
#include "net/pack_struct_start.h"
|
102 |
|
|
struct uip_eth_addr
|
103 |
|
|
{
|
104 |
|
|
u8_t addr[6];
|
105 |
|
|
}
|
106 |
|
|
#include "net/pack_struct_end.h"
|
107 |
|
|
|
108 |
|
|
#ifdef UIP_CONF_LL_802154
|
109 |
|
|
|
110 |
|
|
/** \brief 802.15.4 address */
|
111 |
|
|
typedef struct uip_802154_longaddr uip_lladdr_t;
|
112 |
|
|
#define UIP_802154_SHORTADDR_LEN 2
|
113 |
|
|
#define UIP_802154_LONGADDR_LEN 8
|
114 |
|
|
#define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
|
115 |
|
|
#else /*UIP_CONF_LL_802154*/
|
116 |
|
|
#ifdef UIP_CONF_LL_80211
|
117 |
|
|
/** \brief 802.11 address */
|
118 |
|
|
typedef struct uip_80211_addr uip_lladdr_t;
|
119 |
|
|
#define UIP_LLADDR_LEN 6
|
120 |
|
|
#else /*UIP_CONF_LL_80211*/
|
121 |
|
|
|
122 |
|
|
/** \brief Ethernet address */
|
123 |
|
|
typedef struct uip_eth_addr uip_lladdr_t;
|
124 |
|
|
|
125 |
|
|
#define UIP_LLADDR_LEN 6
|
126 |
|
|
#endif /*UIP_CONF_LL_80211*/
|
127 |
|
|
#endif /*UIP_CONF_LL_802154*/
|
128 |
|
|
|
129 |
|
|
//_RB_#include "net/tcpip.h"
|
130 |
|
|
|
131 |
|
|
/*---------------------------------------------------------------------------*/
|
132 |
|
|
|
133 |
|
|
/* First, the functions that should be called from the
|
134 |
|
|
* system. Initialization, the periodic timer, and incoming packets are
|
135 |
|
|
* handled by the following three functions.
|
136 |
|
|
*/
|
137 |
|
|
|
138 |
|
|
/**
|
139 |
|
|
* \defgroup uipconffunc uIP configuration functions
|
140 |
|
|
* @{
|
141 |
|
|
*
|
142 |
|
|
* The uIP configuration functions are used for setting run-time
|
143 |
|
|
* parameters in uIP such as IP addresses.
|
144 |
|
|
*/
|
145 |
|
|
|
146 |
|
|
/**
|
147 |
|
|
* Set the IP address of this host.
|
148 |
|
|
*
|
149 |
|
|
* The IP address is represented as a 4-byte array where the first
|
150 |
|
|
* octet of the IP address is put in the first member of the 4-byte
|
151 |
|
|
* array.
|
152 |
|
|
*
|
153 |
|
|
* Example:
|
154 |
|
|
\code
|
155 |
|
|
|
156 |
|
|
uip_ipaddr_t addr;
|
157 |
|
|
|
158 |
|
|
uip_ipaddr(&addr, 192,168,1,2);
|
159 |
|
|
uip_sethostaddr(&addr);
|
160 |
|
|
|
161 |
|
|
\endcode
|
162 |
|
|
* \param addr A pointer to an IP address of type uip_ipaddr_t;
|
163 |
|
|
*
|
164 |
|
|
* \sa uip_ipaddr()
|
165 |
|
|
*
|
166 |
|
|
* \hideinitializer
|
167 |
|
|
*/
|
168 |
|
|
#define uip_sethostaddr( addr ) uip_ipaddr_copy( &uip_hostaddr, (addr) )
|
169 |
|
|
|
170 |
|
|
/**
|
171 |
|
|
* Get the IP address of this host.
|
172 |
|
|
*
|
173 |
|
|
* The IP address is represented as a 4-byte array where the first
|
174 |
|
|
* octet of the IP address is put in the first member of the 4-byte
|
175 |
|
|
* array.
|
176 |
|
|
*
|
177 |
|
|
* Example:
|
178 |
|
|
\code
|
179 |
|
|
uip_ipaddr_t hostaddr;
|
180 |
|
|
|
181 |
|
|
uip_gethostaddr(&hostaddr);
|
182 |
|
|
\endcode
|
183 |
|
|
* \param addr A pointer to a uip_ipaddr_t variable that will be
|
184 |
|
|
* filled in with the currently configured IP address.
|
185 |
|
|
*
|
186 |
|
|
* \hideinitializer
|
187 |
|
|
*/
|
188 |
|
|
#define uip_gethostaddr( addr ) uip_ipaddr_copy( (addr), &uip_hostaddr )
|
189 |
|
|
|
190 |
|
|
/**
|
191 |
|
|
* Set the default router's IP address.
|
192 |
|
|
*
|
193 |
|
|
* \param addr A pointer to a uip_ipaddr_t variable containing the IP
|
194 |
|
|
* address of the default router.
|
195 |
|
|
*
|
196 |
|
|
* \sa uip_ipaddr()
|
197 |
|
|
*
|
198 |
|
|
* \hideinitializer
|
199 |
|
|
*/
|
200 |
|
|
#define uip_setdraddr( addr ) uip_ipaddr_copy( &uip_draddr, (addr) )
|
201 |
|
|
|
202 |
|
|
/**
|
203 |
|
|
* Set the netmask.
|
204 |
|
|
*
|
205 |
|
|
* \param addr A pointer to a uip_ipaddr_t variable containing the IP
|
206 |
|
|
* address of the netmask.
|
207 |
|
|
*
|
208 |
|
|
* \sa uip_ipaddr()
|
209 |
|
|
*
|
210 |
|
|
* \hideinitializer
|
211 |
|
|
*/
|
212 |
|
|
#define uip_setnetmask( addr ) uip_ipaddr_copy( &uip_netmask, (addr) )
|
213 |
|
|
|
214 |
|
|
/**
|
215 |
|
|
* Get the default router's IP address.
|
216 |
|
|
*
|
217 |
|
|
* \param addr A pointer to a uip_ipaddr_t variable that will be
|
218 |
|
|
* filled in with the IP address of the default router.
|
219 |
|
|
*
|
220 |
|
|
* \hideinitializer
|
221 |
|
|
*/
|
222 |
|
|
#define uip_getdraddr( addr ) uip_ipaddr_copy( (addr), &uip_draddr )
|
223 |
|
|
|
224 |
|
|
/**
|
225 |
|
|
* Get the netmask.
|
226 |
|
|
*
|
227 |
|
|
* \param addr A pointer to a uip_ipaddr_t variable that will be
|
228 |
|
|
* filled in with the value of the netmask.
|
229 |
|
|
*
|
230 |
|
|
* \hideinitializer
|
231 |
|
|
*/
|
232 |
|
|
#define uip_getnetmask( addr ) uip_ipaddr_copy( (addr), &uip_netmask )
|
233 |
|
|
|
234 |
|
|
/** @} */
|
235 |
|
|
|
236 |
|
|
/**
|
237 |
|
|
* \defgroup uipinit uIP initialization functions
|
238 |
|
|
* @{
|
239 |
|
|
*
|
240 |
|
|
* The uIP initialization functions are used for booting uIP.
|
241 |
|
|
*/
|
242 |
|
|
|
243 |
|
|
/**
|
244 |
|
|
* uIP initialization function.
|
245 |
|
|
*
|
246 |
|
|
* This function should be called at boot up to initilize the uIP
|
247 |
|
|
* TCP/IP stack.
|
248 |
|
|
*/
|
249 |
|
|
void uip_init( void );
|
250 |
|
|
|
251 |
|
|
/**
|
252 |
|
|
* uIP initialization function.
|
253 |
|
|
*
|
254 |
|
|
* This function may be used at boot time to set the initial ip_id.
|
255 |
|
|
*/
|
256 |
|
|
void uip_setipid( u16_t id );
|
257 |
|
|
|
258 |
|
|
/** @} */
|
259 |
|
|
|
260 |
|
|
/**
|
261 |
|
|
* \defgroup uipdevfunc uIP device driver functions
|
262 |
|
|
* @{
|
263 |
|
|
*
|
264 |
|
|
* These functions are used by a network device driver for interacting
|
265 |
|
|
* with uIP.
|
266 |
|
|
*/
|
267 |
|
|
|
268 |
|
|
/**
|
269 |
|
|
* Process an incoming packet.
|
270 |
|
|
*
|
271 |
|
|
* This function should be called when the device driver has received
|
272 |
|
|
* a packet from the network. The packet from the device driver must
|
273 |
|
|
* be present in the uip_buf buffer, and the length of the packet
|
274 |
|
|
* should be placed in the uip_len variable.
|
275 |
|
|
*
|
276 |
|
|
* When the function returns, there may be an outbound packet placed
|
277 |
|
|
* in the uip_buf packet buffer. If so, the uip_len variable is set to
|
278 |
|
|
* the length of the packet. If no packet is to be sent out, the
|
279 |
|
|
* uip_len variable is set to 0.
|
280 |
|
|
*
|
281 |
|
|
* The usual way of calling the function is presented by the source
|
282 |
|
|
* code below.
|
283 |
|
|
\code
|
284 |
|
|
uip_len = devicedriver_poll();
|
285 |
|
|
if(uip_len > 0) {
|
286 |
|
|
uip_input();
|
287 |
|
|
if(uip_len > 0) {
|
288 |
|
|
devicedriver_send();
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
|
|
\endcode
|
292 |
|
|
*
|
293 |
|
|
* \note If you are writing a uIP device driver that needs ARP
|
294 |
|
|
* (Address Resolution Protocol), e.g., when running uIP over
|
295 |
|
|
* Ethernet, you will need to call the uIP ARP code before calling
|
296 |
|
|
* this function:
|
297 |
|
|
\code
|
298 |
|
|
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
299 |
|
|
uip_len = ethernet_devicedrver_poll();
|
300 |
|
|
if(uip_len > 0) {
|
301 |
|
|
if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
|
302 |
|
|
uip_arp_ipin();
|
303 |
|
|
uip_input();
|
304 |
|
|
if(uip_len > 0) {
|
305 |
|
|
uip_arp_out();
|
306 |
|
|
ethernet_devicedriver_send();
|
307 |
|
|
}
|
308 |
|
|
} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
|
309 |
|
|
uip_arp_arpin();
|
310 |
|
|
if(uip_len > 0) {
|
311 |
|
|
ethernet_devicedriver_send();
|
312 |
|
|
}
|
313 |
|
|
}
|
314 |
|
|
\endcode
|
315 |
|
|
*
|
316 |
|
|
* \hideinitializer
|
317 |
|
|
*/
|
318 |
|
|
#define uip_input() uip_process( UIP_DATA )
|
319 |
|
|
|
320 |
|
|
/**
|
321 |
|
|
* Periodic processing for a connection identified by its number.
|
322 |
|
|
*
|
323 |
|
|
* This function does the necessary periodic processing (timers,
|
324 |
|
|
* polling) for a uIP TCP conneciton, and should be called when the
|
325 |
|
|
* periodic uIP timer goes off. It should be called for every
|
326 |
|
|
* connection, regardless of whether they are open of closed.
|
327 |
|
|
*
|
328 |
|
|
* When the function returns, it may have an outbound packet waiting
|
329 |
|
|
* for service in the uIP packet buffer, and if so the uip_len
|
330 |
|
|
* variable is set to a value larger than zero. The device driver
|
331 |
|
|
* should be called to send out the packet.
|
332 |
|
|
*
|
333 |
|
|
* The usual way of calling the function is through a for() loop like
|
334 |
|
|
* this:
|
335 |
|
|
\code
|
336 |
|
|
for(i = 0; i < UIP_CONNS; ++i) {
|
337 |
|
|
uip_periodic(i);
|
338 |
|
|
if(uip_len > 0) {
|
339 |
|
|
devicedriver_send();
|
340 |
|
|
}
|
341 |
|
|
}
|
342 |
|
|
\endcode
|
343 |
|
|
*
|
344 |
|
|
* \note If you are writing a uIP device driver that needs ARP
|
345 |
|
|
* (Address Resolution Protocol), e.g., when running uIP over
|
346 |
|
|
* Ethernet, you will need to call the uip_arp_out() function before
|
347 |
|
|
* calling the device driver:
|
348 |
|
|
\code
|
349 |
|
|
for(i = 0; i < UIP_CONNS; ++i) {
|
350 |
|
|
uip_periodic(i);
|
351 |
|
|
if(uip_len > 0) {
|
352 |
|
|
uip_arp_out();
|
353 |
|
|
ethernet_devicedriver_send();
|
354 |
|
|
}
|
355 |
|
|
}
|
356 |
|
|
\endcode
|
357 |
|
|
*
|
358 |
|
|
* \param conn The number of the connection which is to be periodically polled.
|
359 |
|
|
*
|
360 |
|
|
* \hideinitializer
|
361 |
|
|
*/
|
362 |
|
|
#ifdef UIP_TCP
|
363 |
|
|
#define uip_periodic( conn ) \
|
364 |
|
|
do \
|
365 |
|
|
{ \
|
366 |
|
|
uip_conn = &uip_conns[conn]; \
|
367 |
|
|
uip_process( UIP_TIMER ); \
|
368 |
|
|
} while( 0 )
|
369 |
|
|
|
370 |
|
|
/**
|
371 |
|
|
*
|
372 |
|
|
*
|
373 |
|
|
*/
|
374 |
|
|
#define uip_conn_active( conn ) ( uip_conns[conn].tcpstateflags != UIP_CLOSED )
|
375 |
|
|
|
376 |
|
|
/**
|
377 |
|
|
* Perform periodic processing for a connection identified by a pointer
|
378 |
|
|
* to its structure.
|
379 |
|
|
*
|
380 |
|
|
* Same as uip_periodic() but takes a pointer to the actual uip_conn
|
381 |
|
|
* struct instead of an integer as its argument. This function can be
|
382 |
|
|
* used to force periodic processing of a specific connection.
|
383 |
|
|
*
|
384 |
|
|
* \param conn A pointer to the uip_conn struct for the connection to
|
385 |
|
|
* be processed.
|
386 |
|
|
*
|
387 |
|
|
* \hideinitializer
|
388 |
|
|
*/
|
389 |
|
|
#define uip_periodic_conn( conn ) \
|
390 |
|
|
do \
|
391 |
|
|
{ \
|
392 |
|
|
uip_conn = conn; \
|
393 |
|
|
uip_process( UIP_TIMER ); \
|
394 |
|
|
} while( 0 )
|
395 |
|
|
|
396 |
|
|
/**
|
397 |
|
|
* Request that a particular connection should be polled.
|
398 |
|
|
*
|
399 |
|
|
* Similar to uip_periodic_conn() but does not perform any timer
|
400 |
|
|
* processing. The application is polled for new data.
|
401 |
|
|
*
|
402 |
|
|
* \param conn A pointer to the uip_conn struct for the connection to
|
403 |
|
|
* be processed.
|
404 |
|
|
*
|
405 |
|
|
* \hideinitializer
|
406 |
|
|
*/
|
407 |
|
|
#define uip_poll_conn( conn ) \
|
408 |
|
|
do \
|
409 |
|
|
{ \
|
410 |
|
|
uip_conn = conn; \
|
411 |
|
|
uip_process( UIP_POLL_REQUEST ); \
|
412 |
|
|
} while( 0 )
|
413 |
|
|
#endif /* UIP_TCP */
|
414 |
|
|
|
415 |
|
|
#ifdef UIP_UDP
|
416 |
|
|
|
417 |
|
|
/**
|
418 |
|
|
* Periodic processing for a UDP connection identified by its number.
|
419 |
|
|
*
|
420 |
|
|
* This function is essentially the same as uip_periodic(), but for
|
421 |
|
|
* UDP connections. It is called in a similar fashion as the
|
422 |
|
|
* uip_periodic() function:
|
423 |
|
|
\code
|
424 |
|
|
for(i = 0; i < UIP_UDP_CONNS; i++) {
|
425 |
|
|
uip_udp_periodic(i);
|
426 |
|
|
if(uip_len > 0) {
|
427 |
|
|
devicedriver_send();
|
428 |
|
|
}
|
429 |
|
|
}
|
430 |
|
|
\endcode
|
431 |
|
|
*
|
432 |
|
|
* \note As for the uip_periodic() function, special care has to be
|
433 |
|
|
* taken when using uIP together with ARP and Ethernet:
|
434 |
|
|
\code
|
435 |
|
|
for(i = 0; i < UIP_UDP_CONNS; i++) {
|
436 |
|
|
uip_udp_periodic(i);
|
437 |
|
|
if(uip_len > 0) {
|
438 |
|
|
uip_arp_out();
|
439 |
|
|
ethernet_devicedriver_send();
|
440 |
|
|
}
|
441 |
|
|
}
|
442 |
|
|
\endcode
|
443 |
|
|
*
|
444 |
|
|
* \param conn The number of the UDP connection to be processed.
|
445 |
|
|
*
|
446 |
|
|
* \hideinitializer
|
447 |
|
|
*/
|
448 |
|
|
#define uip_udp_periodic( conn ) \
|
449 |
|
|
do \
|
450 |
|
|
{ \
|
451 |
|
|
uip_udp_conn = &uip_udp_conns[conn]; \
|
452 |
|
|
uip_process( UIP_UDP_TIMER ); \
|
453 |
|
|
} while( 0 )
|
454 |
|
|
|
455 |
|
|
/**
|
456 |
|
|
* Periodic processing for a UDP connection identified by a pointer to
|
457 |
|
|
* its structure.
|
458 |
|
|
*
|
459 |
|
|
* Same as uip_udp_periodic() but takes a pointer to the actual
|
460 |
|
|
* uip_conn struct instead of an integer as its argument. This
|
461 |
|
|
* function can be used to force periodic processing of a specific
|
462 |
|
|
* connection.
|
463 |
|
|
*
|
464 |
|
|
* \param conn A pointer to the uip_udp_conn struct for the connection
|
465 |
|
|
* to be processed.
|
466 |
|
|
*
|
467 |
|
|
* \hideinitializer
|
468 |
|
|
*/
|
469 |
|
|
#define uip_udp_periodic_conn( conn ) \
|
470 |
|
|
do \
|
471 |
|
|
{ \
|
472 |
|
|
uip_udp_conn = conn; \
|
473 |
|
|
uip_process( UIP_UDP_TIMER ); \
|
474 |
|
|
} while( 0 )
|
475 |
|
|
#endif /* UIP_UDP */
|
476 |
|
|
|
477 |
|
|
/** \brief Abandon the reassembly of the current packet */
|
478 |
|
|
void uip_reass_over( void );
|
479 |
|
|
|
480 |
|
|
/**
|
481 |
|
|
* The uIP packet buffer.
|
482 |
|
|
*
|
483 |
|
|
* The uip_buf array is used to hold incoming and outgoing
|
484 |
|
|
* packets. The device driver should place incoming data into this
|
485 |
|
|
* buffer. When sending data, the device driver should read the link
|
486 |
|
|
* level headers and the TCP/IP headers from this buffer. The size of
|
487 |
|
|
* the link level headers is configured by the UIP_LLH_LEN define.
|
488 |
|
|
*
|
489 |
|
|
* \note The application data need not be placed in this buffer, so
|
490 |
|
|
* the device driver must read it from the place pointed to by the
|
491 |
|
|
* uip_appdata pointer as illustrated by the following example:
|
492 |
|
|
\code
|
493 |
|
|
void
|
494 |
|
|
devicedriver_send(void)
|
495 |
|
|
{
|
496 |
|
|
hwsend(&uip_buf[0], UIP_LLH_LEN);
|
497 |
|
|
if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
|
498 |
|
|
hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
|
499 |
|
|
} else {
|
500 |
|
|
hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
|
501 |
|
|
hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
|
502 |
|
|
}
|
503 |
|
|
}
|
504 |
|
|
\endcode
|
505 |
|
|
*/
|
506 |
|
|
#ifndef UIP_CONF_EXTERNAL_BUFFER
|
507 |
|
|
CCIF extern u8_t uip_buf[UIP_BUFSIZE + 2];
|
508 |
|
|
#else
|
509 |
|
|
CCIF extern unsigned char *uip_buf;
|
510 |
|
|
#endif
|
511 |
|
|
|
512 |
|
|
/** @} */
|
513 |
|
|
|
514 |
|
|
/*---------------------------------------------------------------------------*/
|
515 |
|
|
|
516 |
|
|
/* Functions that are used by the uIP application program. Opening and
|
517 |
|
|
* closing connections, sending and receiving data, etc. is all
|
518 |
|
|
* handled by the functions below.
|
519 |
|
|
*/
|
520 |
|
|
|
521 |
|
|
/**
|
522 |
|
|
* \defgroup uipappfunc uIP application functions
|
523 |
|
|
* @{
|
524 |
|
|
*
|
525 |
|
|
* Functions used by an application running of top of uIP.
|
526 |
|
|
*/
|
527 |
|
|
|
528 |
|
|
/**
|
529 |
|
|
* Start listening to the specified port.
|
530 |
|
|
*
|
531 |
|
|
* \note Since this function expects the port number in network byte
|
532 |
|
|
* order, a conversion using HTONS() or htons() is necessary.
|
533 |
|
|
*
|
534 |
|
|
\code
|
535 |
|
|
uip_listen(HTONS(80));
|
536 |
|
|
\endcode
|
537 |
|
|
*
|
538 |
|
|
* \param port A 16-bit port number in network byte order.
|
539 |
|
|
*/
|
540 |
|
|
void uip_listen( u16_t port );
|
541 |
|
|
|
542 |
|
|
/**
|
543 |
|
|
* Stop listening to the specified port.
|
544 |
|
|
*
|
545 |
|
|
* \note Since this function expects the port number in network byte
|
546 |
|
|
* order, a conversion using HTONS() or htons() is necessary.
|
547 |
|
|
*
|
548 |
|
|
\code
|
549 |
|
|
uip_unlisten(HTONS(80));
|
550 |
|
|
\endcode
|
551 |
|
|
*
|
552 |
|
|
* \param port A 16-bit port number in network byte order.
|
553 |
|
|
*/
|
554 |
|
|
void uip_unlisten( u16_t port );
|
555 |
|
|
|
556 |
|
|
/**
|
557 |
|
|
* Connect to a remote host using TCP.
|
558 |
|
|
*
|
559 |
|
|
* This function is used to start a new connection to the specified
|
560 |
|
|
* port on the specified host. It allocates a new connection identifier,
|
561 |
|
|
* sets the connection to the SYN_SENT state and sets the
|
562 |
|
|
* retransmission timer to 0. This will cause a TCP SYN segment to be
|
563 |
|
|
* sent out the next time this connection is periodically processed,
|
564 |
|
|
* which usually is done within 0.5 seconds after the call to
|
565 |
|
|
* uip_connect().
|
566 |
|
|
*
|
567 |
|
|
* \note This function is available only if support for active open
|
568 |
|
|
* has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
|
569 |
|
|
*
|
570 |
|
|
* \note Since this function requires the port number to be in network
|
571 |
|
|
* byte order, a conversion using HTONS() or htons() is necessary.
|
572 |
|
|
*
|
573 |
|
|
\code
|
574 |
|
|
uip_ipaddr_t ipaddr;
|
575 |
|
|
|
576 |
|
|
uip_ipaddr(&ipaddr, 192,168,1,2);
|
577 |
|
|
uip_connect(&ipaddr, HTONS(80));
|
578 |
|
|
\endcode
|
579 |
|
|
*
|
580 |
|
|
* \param ripaddr The IP address of the remote host.
|
581 |
|
|
*
|
582 |
|
|
* \param port A 16-bit port number in network byte order.
|
583 |
|
|
*
|
584 |
|
|
* \return A pointer to the uIP connection identifier for the new connection,
|
585 |
|
|
* or NULL if no connection could be allocated.
|
586 |
|
|
*
|
587 |
|
|
*/
|
588 |
|
|
struct uip_conn *uip_connect( uip_ipaddr_t *ripaddr, u16_t port );
|
589 |
|
|
|
590 |
|
|
/**
|
591 |
|
|
* \internal
|
592 |
|
|
*
|
593 |
|
|
* Check if a connection has outstanding (i.e., unacknowledged) data.
|
594 |
|
|
*
|
595 |
|
|
* \param conn A pointer to the uip_conn structure for the connection.
|
596 |
|
|
*
|
597 |
|
|
* \hideinitializer
|
598 |
|
|
*/
|
599 |
|
|
#define uip_outstanding( conn ) ( (conn)->len )
|
600 |
|
|
|
601 |
|
|
/**
|
602 |
|
|
* Send data on the current connection.
|
603 |
|
|
*
|
604 |
|
|
* This function is used to send out a single segment of TCP
|
605 |
|
|
* data. Only applications that have been invoked by uIP for event
|
606 |
|
|
* processing can send data.
|
607 |
|
|
*
|
608 |
|
|
* The amount of data that actually is sent out after a call to this
|
609 |
|
|
* function is determined by the maximum amount of data TCP allows. uIP
|
610 |
|
|
* will automatically crop the data so that only the appropriate
|
611 |
|
|
* amount of data is sent. The function uip_mss() can be used to query
|
612 |
|
|
* uIP for the amount of data that actually will be sent.
|
613 |
|
|
*
|
614 |
|
|
* \note This function does not guarantee that the sent data will
|
615 |
|
|
* arrive at the destination. If the data is lost in the network, the
|
616 |
|
|
* application will be invoked with the uip_rexmit() event being
|
617 |
|
|
* set. The application will then have to resend the data using this
|
618 |
|
|
* function.
|
619 |
|
|
*
|
620 |
|
|
* \param data A pointer to the data which is to be sent.
|
621 |
|
|
*
|
622 |
|
|
* \param len The maximum amount of data bytes to be sent.
|
623 |
|
|
*
|
624 |
|
|
* \hideinitializer
|
625 |
|
|
*/
|
626 |
|
|
CCIF void uip_send( const void *data, int len );
|
627 |
|
|
|
628 |
|
|
/**
|
629 |
|
|
* The length of any incoming data that is currently available (if available)
|
630 |
|
|
* in the uip_appdata buffer.
|
631 |
|
|
*
|
632 |
|
|
* The test function uip_data() must first be used to check if there
|
633 |
|
|
* is any data available at all.
|
634 |
|
|
*
|
635 |
|
|
* \hideinitializer
|
636 |
|
|
*/
|
637 |
|
|
|
638 |
|
|
/*void uip_datalen(void);*/
|
639 |
|
|
#define uip_datalen() uip_len
|
640 |
|
|
|
641 |
|
|
/**
|
642 |
|
|
* The length of any out-of-band data (urgent data) that has arrived
|
643 |
|
|
* on the connection.
|
644 |
|
|
*
|
645 |
|
|
* \note The configuration parameter UIP_URGDATA must be set for this
|
646 |
|
|
* function to be enabled.
|
647 |
|
|
*
|
648 |
|
|
* \hideinitializer
|
649 |
|
|
*/
|
650 |
|
|
#define uip_urgdatalen() uip_urglen
|
651 |
|
|
|
652 |
|
|
/**
|
653 |
|
|
* Close the current connection.
|
654 |
|
|
*
|
655 |
|
|
* This function will close the current connection in a nice way.
|
656 |
|
|
*
|
657 |
|
|
* \hideinitializer
|
658 |
|
|
*/
|
659 |
|
|
#define uip_close() ( uip_flags = UIP_CLOSE )
|
660 |
|
|
|
661 |
|
|
/**
|
662 |
|
|
* Abort the current connection.
|
663 |
|
|
*
|
664 |
|
|
* This function will abort (reset) the current connection, and is
|
665 |
|
|
* usually used when an error has occurred that prevents using the
|
666 |
|
|
* uip_close() function.
|
667 |
|
|
*
|
668 |
|
|
* \hideinitializer
|
669 |
|
|
*/
|
670 |
|
|
#define uip_abort() ( uip_flags = UIP_ABORT )
|
671 |
|
|
|
672 |
|
|
/**
|
673 |
|
|
* Tell the sending host to stop sending data.
|
674 |
|
|
*
|
675 |
|
|
* This function will close our receiver's window so that we stop
|
676 |
|
|
* receiving data for the current connection.
|
677 |
|
|
*
|
678 |
|
|
* \hideinitializer
|
679 |
|
|
*/
|
680 |
|
|
#define uip_stop() ( uip_conn->tcpstateflags |= UIP_STOPPED )
|
681 |
|
|
|
682 |
|
|
/**
|
683 |
|
|
* Find out if the current connection has been previously stopped with
|
684 |
|
|
* uip_stop().
|
685 |
|
|
*
|
686 |
|
|
* \hideinitializer
|
687 |
|
|
*/
|
688 |
|
|
#define uip_stopped( conn ) ( (conn)->tcpstateflags & UIP_STOPPED )
|
689 |
|
|
|
690 |
|
|
/**
|
691 |
|
|
* Restart the current connection, if is has previously been stopped
|
692 |
|
|
* with uip_stop().
|
693 |
|
|
*
|
694 |
|
|
* This function will open the receiver's window again so that we
|
695 |
|
|
* start receiving data for the current connection.
|
696 |
|
|
*
|
697 |
|
|
* \hideinitializer
|
698 |
|
|
*/
|
699 |
|
|
#define uip_restart() \
|
700 |
|
|
do \
|
701 |
|
|
{ \
|
702 |
|
|
uip_flags |= UIP_NEWDATA; \
|
703 |
|
|
uip_conn->tcpstateflags &= ~UIP_STOPPED; \
|
704 |
|
|
} while( 0 )
|
705 |
|
|
|
706 |
|
|
/* uIP tests that can be made to determine in what state the current
|
707 |
|
|
connection is, and what the application function should do. */
|
708 |
|
|
|
709 |
|
|
/**
|
710 |
|
|
* Is the current connection a UDP connection?
|
711 |
|
|
*
|
712 |
|
|
* This function checks whether the current connection is a UDP connection.
|
713 |
|
|
*
|
714 |
|
|
* \hideinitializer
|
715 |
|
|
*
|
716 |
|
|
*/
|
717 |
|
|
#define uip_udpconnection() ( uip_conn == NULL )
|
718 |
|
|
|
719 |
|
|
/**
|
720 |
|
|
* Is new incoming data available?
|
721 |
|
|
*
|
722 |
|
|
* Will reduce to non-zero if there is new data for the application
|
723 |
|
|
* present at the uip_appdata pointer. The size of the data is
|
724 |
|
|
* available through the uip_len variable.
|
725 |
|
|
*
|
726 |
|
|
* \hideinitializer
|
727 |
|
|
*/
|
728 |
|
|
#define uip_newdata() ( uip_flags & UIP_NEWDATA )
|
729 |
|
|
|
730 |
|
|
/**
|
731 |
|
|
* Has previously sent data been acknowledged?
|
732 |
|
|
*
|
733 |
|
|
* Will reduce to non-zero if the previously sent data has been
|
734 |
|
|
* acknowledged by the remote host. This means that the application
|
735 |
|
|
* can send new data.
|
736 |
|
|
*
|
737 |
|
|
* \hideinitializer
|
738 |
|
|
*/
|
739 |
|
|
#define uip_acked() ( uip_flags & UIP_ACKDATA )
|
740 |
|
|
|
741 |
|
|
/**
|
742 |
|
|
* Has the connection just been connected?
|
743 |
|
|
*
|
744 |
|
|
* Reduces to non-zero if the current connection has been connected to
|
745 |
|
|
* a remote host. This will happen both if the connection has been
|
746 |
|
|
* actively opened (with uip_connect()) or passively opened (with
|
747 |
|
|
* uip_listen()).
|
748 |
|
|
*
|
749 |
|
|
* \hideinitializer
|
750 |
|
|
*/
|
751 |
|
|
#define uip_connected() ( uip_flags & UIP_CONNECTED )
|
752 |
|
|
|
753 |
|
|
/**
|
754 |
|
|
* Has the connection been closed by the other end?
|
755 |
|
|
*
|
756 |
|
|
* Is non-zero if the connection has been closed by the remote
|
757 |
|
|
* host. The application may then do the necessary clean-ups.
|
758 |
|
|
*
|
759 |
|
|
* \hideinitializer
|
760 |
|
|
*/
|
761 |
|
|
#define uip_closed() ( uip_flags & UIP_CLOSE )
|
762 |
|
|
|
763 |
|
|
/**
|
764 |
|
|
* Has the connection been aborted by the other end?
|
765 |
|
|
*
|
766 |
|
|
* Non-zero if the current connection has been aborted (reset) by the
|
767 |
|
|
* remote host.
|
768 |
|
|
*
|
769 |
|
|
* \hideinitializer
|
770 |
|
|
*/
|
771 |
|
|
#define uip_aborted() ( uip_flags & UIP_ABORT )
|
772 |
|
|
|
773 |
|
|
/**
|
774 |
|
|
* Has the connection timed out?
|
775 |
|
|
*
|
776 |
|
|
* Non-zero if the current connection has been aborted due to too many
|
777 |
|
|
* retransmissions.
|
778 |
|
|
*
|
779 |
|
|
* \hideinitializer
|
780 |
|
|
*/
|
781 |
|
|
#define uip_timedout() ( uip_flags & UIP_TIMEDOUT )
|
782 |
|
|
|
783 |
|
|
/**
|
784 |
|
|
* Do we need to retransmit previously data?
|
785 |
|
|
*
|
786 |
|
|
* Reduces to non-zero if the previously sent data has been lost in
|
787 |
|
|
* the network, and the application should retransmit it. The
|
788 |
|
|
* application should send the exact same data as it did the last
|
789 |
|
|
* time, using the uip_send() function.
|
790 |
|
|
*
|
791 |
|
|
* \hideinitializer
|
792 |
|
|
*/
|
793 |
|
|
#define uip_rexmit() ( uip_flags & UIP_REXMIT )
|
794 |
|
|
|
795 |
|
|
/**
|
796 |
|
|
* Is the connection being polled by uIP?
|
797 |
|
|
*
|
798 |
|
|
* Is non-zero if the reason the application is invoked is that the
|
799 |
|
|
* current connection has been idle for a while and should be
|
800 |
|
|
* polled.
|
801 |
|
|
*
|
802 |
|
|
* The polling event can be used for sending data without having to
|
803 |
|
|
* wait for the remote host to send data.
|
804 |
|
|
*
|
805 |
|
|
* \hideinitializer
|
806 |
|
|
*/
|
807 |
|
|
#define uip_poll() ( uip_flags & UIP_POLL )
|
808 |
|
|
|
809 |
|
|
/**
|
810 |
|
|
* Get the initial maximum segment size (MSS) of the current
|
811 |
|
|
* connection.
|
812 |
|
|
*
|
813 |
|
|
* \hideinitializer
|
814 |
|
|
*/
|
815 |
|
|
#define uip_initialmss() ( uip_conn->initialmss )
|
816 |
|
|
|
817 |
|
|
/**
|
818 |
|
|
* Get the current maximum segment size that can be sent on the current
|
819 |
|
|
* connection.
|
820 |
|
|
*
|
821 |
|
|
* The current maximum segment size that can be sent on the
|
822 |
|
|
* connection is computed from the receiver's window and the MSS of
|
823 |
|
|
* the connection (which also is available by calling
|
824 |
|
|
* uip_initialmss()).
|
825 |
|
|
*
|
826 |
|
|
* \hideinitializer
|
827 |
|
|
*/
|
828 |
|
|
#define uip_mss() ( uip_conn->mss )
|
829 |
|
|
/**
|
830 |
|
|
* Set up a new UDP connection.
|
831 |
|
|
*
|
832 |
|
|
* This function sets up a new UDP connection. The function will
|
833 |
|
|
* automatically allocate an unused local port for the new
|
834 |
|
|
* connection. However, another port can be chosen by using the
|
835 |
|
|
* uip_udp_bind() call, after the uip_udp_new() function has been
|
836 |
|
|
* called.
|
837 |
|
|
*
|
838 |
|
|
* Example:
|
839 |
|
|
\code
|
840 |
|
|
uip_ipaddr_t addr;
|
841 |
|
|
struct uip_udp_conn *c;
|
842 |
|
|
|
843 |
|
|
uip_ipaddr(&addr, 192,168,2,1);
|
844 |
|
|
c = uip_udp_new(&addr, HTONS(12345));
|
845 |
|
|
if(c != NULL) {
|
846 |
|
|
uip_udp_bind(c, HTONS(12344));
|
847 |
|
|
}
|
848 |
|
|
\endcode
|
849 |
|
|
* \param ripaddr The IP address of the remote host.
|
850 |
|
|
*
|
851 |
|
|
* \param rport The remote port number in network byte order.
|
852 |
|
|
*
|
853 |
|
|
* \return The uip_udp_conn structure for the new connection or NULL
|
854 |
|
|
* if no connection could be allocated.
|
855 |
|
|
*/
|
856 |
|
|
struct uip_udp_conn *uip_udp_new( const uip_ipaddr_t *ripaddr, u16_t rport );
|
857 |
|
|
|
858 |
|
|
/**
|
859 |
|
|
* Removed a UDP connection.
|
860 |
|
|
*
|
861 |
|
|
* \param conn A pointer to the uip_udp_conn structure for the connection.
|
862 |
|
|
*
|
863 |
|
|
* \hideinitializer
|
864 |
|
|
*/
|
865 |
|
|
#define uip_udp_remove( conn ) ( conn )->lport = 0
|
866 |
|
|
|
867 |
|
|
/**
|
868 |
|
|
* Bind a UDP connection to a local port.
|
869 |
|
|
*
|
870 |
|
|
* \param conn A pointer to the uip_udp_conn structure for the
|
871 |
|
|
* connection.
|
872 |
|
|
*
|
873 |
|
|
* \param port The local port number, in network byte order.
|
874 |
|
|
*
|
875 |
|
|
* \hideinitializer
|
876 |
|
|
*/
|
877 |
|
|
#define uip_udp_bind( conn, port ) ( conn )->lport = port
|
878 |
|
|
|
879 |
|
|
/**
|
880 |
|
|
* Send a UDP datagram of length len on the current connection.
|
881 |
|
|
*
|
882 |
|
|
* This function can only be called in response to a UDP event (poll
|
883 |
|
|
* or newdata). The data must be present in the uip_buf buffer, at the
|
884 |
|
|
* place pointed to by the uip_appdata pointer.
|
885 |
|
|
*
|
886 |
|
|
* \param len The length of the data in the uip_buf buffer.
|
887 |
|
|
*
|
888 |
|
|
* \hideinitializer
|
889 |
|
|
*/
|
890 |
|
|
#define uip_udp_send( len ) uip_send( ( char * ) uip_appdata, len )
|
891 |
|
|
|
892 |
|
|
/** @} */
|
893 |
|
|
|
894 |
|
|
/* uIP convenience and converting functions. */
|
895 |
|
|
|
896 |
|
|
/**
|
897 |
|
|
* \defgroup uipconvfunc uIP conversion functions
|
898 |
|
|
* @{
|
899 |
|
|
*
|
900 |
|
|
* These functions can be used for converting between different data
|
901 |
|
|
* formats used by uIP.
|
902 |
|
|
*/
|
903 |
|
|
|
904 |
|
|
/**
|
905 |
|
|
* Convert an IP address to four bytes separated by commas.
|
906 |
|
|
*
|
907 |
|
|
* Example:
|
908 |
|
|
\code
|
909 |
|
|
uip_ipaddr_t ipaddr;
|
910 |
|
|
printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
|
911 |
|
|
\endcode
|
912 |
|
|
*
|
913 |
|
|
* \param a A pointer to a uip_ipaddr_t.
|
914 |
|
|
* \hideinitializer
|
915 |
|
|
*/
|
916 |
|
|
#define uip_ipaddr_to_quad( a ) ( a )->u8[0], ( a )->u8[1], ( a )->u8[2], ( a )->u8[3]
|
917 |
|
|
|
918 |
|
|
/**
|
919 |
|
|
* Construct an IP address from four bytes.
|
920 |
|
|
*
|
921 |
|
|
* This function constructs an IP address of the type that uIP handles
|
922 |
|
|
* internally from four bytes. The function is handy for specifying IP
|
923 |
|
|
* addresses to use with e.g. the uip_connect() function.
|
924 |
|
|
*
|
925 |
|
|
* Example:
|
926 |
|
|
\code
|
927 |
|
|
uip_ipaddr_t ipaddr;
|
928 |
|
|
struct uip_conn *c;
|
929 |
|
|
|
930 |
|
|
uip_ipaddr(&ipaddr, 192,168,1,2);
|
931 |
|
|
c = uip_connect(&ipaddr, HTONS(80));
|
932 |
|
|
\endcode
|
933 |
|
|
*
|
934 |
|
|
* \param addr A pointer to a uip_ipaddr_t variable that will be
|
935 |
|
|
* filled in with the IP address.
|
936 |
|
|
*
|
937 |
|
|
* \param addr0 The first octet of the IP address.
|
938 |
|
|
* \param addr1 The second octet of the IP address.
|
939 |
|
|
* \param addr2 The third octet of the IP address.
|
940 |
|
|
* \param addr3 The forth octet of the IP address.
|
941 |
|
|
*
|
942 |
|
|
* \hideinitializer
|
943 |
|
|
*/
|
944 |
|
|
#define uip_ipaddr( addr, addr0, addr1, addr2, addr3 ) \
|
945 |
|
|
do \
|
946 |
|
|
{ \
|
947 |
|
|
( addr )->u8[0] = addr0; \
|
948 |
|
|
( addr )->u8[1] = addr1; \
|
949 |
|
|
( addr )->u8[2] = addr2; \
|
950 |
|
|
( addr )->u8[3] = addr3; \
|
951 |
|
|
} while( 0 )
|
952 |
|
|
|
953 |
|
|
/**
|
954 |
|
|
* Construct an IPv6 address from eight 16-bit words.
|
955 |
|
|
*
|
956 |
|
|
* This function constructs an IPv6 address.
|
957 |
|
|
*
|
958 |
|
|
* \hideinitializer
|
959 |
|
|
*/
|
960 |
|
|
#define uip_ip6addr( addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7 ) \
|
961 |
|
|
do \
|
962 |
|
|
{ \
|
963 |
|
|
( addr )->u16[0] = HTONS( addr0 ); \
|
964 |
|
|
( addr )->u16[1] = HTONS( addr1 ); \
|
965 |
|
|
( addr )->u16[2] = HTONS( addr2 ); \
|
966 |
|
|
( addr )->u16[3] = HTONS( addr3 ); \
|
967 |
|
|
( addr )->u16[4] = HTONS( addr4 ); \
|
968 |
|
|
( addr )->u16[5] = HTONS( addr5 ); \
|
969 |
|
|
( addr )->u16[6] = HTONS( addr6 ); \
|
970 |
|
|
( addr )->u16[7] = HTONS( addr7 ); \
|
971 |
|
|
} while( 0 ) /**
|
972 |
|
|
* Construct an IPv6 address from eight 8-bit words.
|
973 |
|
|
*
|
974 |
|
|
* This function constructs an IPv6 address.
|
975 |
|
|
*
|
976 |
|
|
* \hideinitializer
|
977 |
|
|
*/
|
978 |
|
|
#define uip_ip6addr_u8 ( addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8, addr9, addr10, addr11, addr12, addr13, addr14, \
|
979 |
|
|
addr15 ) do \
|
980 |
|
|
{\
|
981 |
|
|
( addr )->u8[0] = addr0; \
|
982 |
|
|
( addr )->u8[1] = addr1; \
|
983 |
|
|
( addr )->u8[2] = addr2; \
|
984 |
|
|
( addr )->u8[3] = addr3; \
|
985 |
|
|
( addr )->u8[4] = addr4; \
|
986 |
|
|
( addr )->u8[5] = addr5; \
|
987 |
|
|
( addr )->u8[6] = addr6; \
|
988 |
|
|
( addr )->u8[7] = addr7; \
|
989 |
|
|
( addr )->u8[8] = addr8; \
|
990 |
|
|
( addr )->u8[9] = addr9; \
|
991 |
|
|
( addr )->u8[10] = addr10; \
|
992 |
|
|
( addr )->u8[11] = addr11; \
|
993 |
|
|
( addr )->u8[12] = addr12; \
|
994 |
|
|
( addr )->u8[13] = addr13; \
|
995 |
|
|
( addr )->u8[14] = addr14; \
|
996 |
|
|
( addr )->u8[15] = addr15; \
|
997 |
|
|
} while( 0 )
|
998 |
|
|
/**
|
999 |
|
|
* Copy an IP address to another IP address.
|
1000 |
|
|
*
|
1001 |
|
|
* Copies an IP address from one place to another.
|
1002 |
|
|
*
|
1003 |
|
|
* Example:
|
1004 |
|
|
\code
|
1005 |
|
|
uip_ipaddr_t ipaddr1, ipaddr2;
|
1006 |
|
|
|
1007 |
|
|
uip_ipaddr(&ipaddr1, 192,16,1,2);
|
1008 |
|
|
uip_ipaddr_copy(&ipaddr2, &ipaddr1);
|
1009 |
|
|
\endcode
|
1010 |
|
|
*
|
1011 |
|
|
* \param dest The destination for the copy.
|
1012 |
|
|
* \param src The source from where to copy.
|
1013 |
|
|
*
|
1014 |
|
|
* \hideinitializer
|
1015 |
|
|
*/
|
1016 |
|
|
#ifndef uip_ipaddr_copy
|
1017 |
|
|
#define uip_ipaddr_copy( dest, src ) \
|
1018 |
|
|
do \
|
1019 |
|
|
{ \
|
1020 |
|
|
(dest)->u8[0] = (src)->u8[0]; \
|
1021 |
|
|
(dest)->u8[1] = (src)->u8[1]; \
|
1022 |
|
|
(dest)->u8[2] = (src)->u8[2]; \
|
1023 |
|
|
(dest)->u8[3] = (src)->u8[3]; \
|
1024 |
|
|
} while( 0 )
|
1025 |
|
|
#endif
|
1026 |
|
|
|
1027 |
|
|
/**
|
1028 |
|
|
* Compare two IP addresses
|
1029 |
|
|
*
|
1030 |
|
|
* Compares two IP addresses.
|
1031 |
|
|
*
|
1032 |
|
|
* Example:
|
1033 |
|
|
\code
|
1034 |
|
|
uip_ipaddr_t ipaddr1, ipaddr2;
|
1035 |
|
|
|
1036 |
|
|
uip_ipaddr(&ipaddr1, 192,16,1,2);
|
1037 |
|
|
if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
|
1038 |
|
|
printf("They are the same");
|
1039 |
|
|
}
|
1040 |
|
|
\endcode
|
1041 |
|
|
*
|
1042 |
|
|
* \param addr1 The first IP address.
|
1043 |
|
|
* \param addr2 The second IP address.
|
1044 |
|
|
*
|
1045 |
|
|
* \hideinitializer
|
1046 |
|
|
*/
|
1047 |
|
|
#if !UIP_CONF_IPV6
|
1048 |
|
|
#define uip_ipaddr_cmp( addr1, addr2 ) ( (addr1)->u16[0] == (addr2)->u16[0] && (addr1)->u16[1] == (addr2)->u16[1] )
|
1049 |
|
|
#else /* !UIP_CONF_IPV6 */
|
1050 |
|
|
#define uip_ipaddr_cmp( addr1, addr2 ) ( memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0 )
|
1051 |
|
|
#endif /* !UIP_CONF_IPV6 */
|
1052 |
|
|
|
1053 |
|
|
/**
|
1054 |
|
|
* Compare two IP addresses with netmasks
|
1055 |
|
|
*
|
1056 |
|
|
* Compares two IP addresses with netmasks. The masks are used to mask
|
1057 |
|
|
* out the bits that are to be compared.
|
1058 |
|
|
*
|
1059 |
|
|
* Example:
|
1060 |
|
|
\code
|
1061 |
|
|
uip_ipaddr_t ipaddr1, ipaddr2, mask;
|
1062 |
|
|
|
1063 |
|
|
uip_ipaddr(&mask, 255,255,255,0);
|
1064 |
|
|
uip_ipaddr(&ipaddr1, 192,16,1,2);
|
1065 |
|
|
uip_ipaddr(&ipaddr2, 192,16,1,3);
|
1066 |
|
|
if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
|
1067 |
|
|
printf("They are the same");
|
1068 |
|
|
}
|
1069 |
|
|
\endcode
|
1070 |
|
|
*
|
1071 |
|
|
* \param addr1 The first IP address.
|
1072 |
|
|
* \param addr2 The second IP address.
|
1073 |
|
|
* \param mask The netmask.
|
1074 |
|
|
*
|
1075 |
|
|
* \hideinitializer
|
1076 |
|
|
*/
|
1077 |
|
|
#if !UIP_CONF_IPV6
|
1078 |
|
|
#define uip_ipaddr_maskcmp( addr1, addr2, mask ) \
|
1079 |
|
|
( \
|
1080 |
|
|
(((( u16_t * ) addr1)[0] & (( u16_t * ) mask)[0]) == ((( u16_t * ) addr2)[0] & (( u16_t * ) mask)[0])) && \
|
1081 |
|
|
(((( u16_t * ) addr1)[1] & (( u16_t * ) mask)[1]) == ((( u16_t * ) addr2)[1] & (( u16_t * ) mask)[1])) \
|
1082 |
|
|
)
|
1083 |
|
|
#else
|
1084 |
|
|
#define uip_ipaddr_prefixcmp( addr1, addr2, length ) ( memcmp(addr1, addr2, length >> 3) == 0 )
|
1085 |
|
|
#endif
|
1086 |
|
|
|
1087 |
|
|
/**
|
1088 |
|
|
* Check if an address is a broadcast address for a network.
|
1089 |
|
|
*
|
1090 |
|
|
* Checks if an address is the broadcast address for a network. The
|
1091 |
|
|
* network is defined by an IP address that is on the network and the
|
1092 |
|
|
* network's netmask.
|
1093 |
|
|
*
|
1094 |
|
|
* \param addr The IP address.
|
1095 |
|
|
* \param netaddr The network's IP address.
|
1096 |
|
|
* \param netmask The network's netmask.
|
1097 |
|
|
*
|
1098 |
|
|
* \hideinitializer
|
1099 |
|
|
*/
|
1100 |
|
|
|
1101 |
|
|
/*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
|
1102 |
|
|
((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
|
1103 |
|
|
|
1104 |
|
|
/**
|
1105 |
|
|
* Mask out the network part of an IP address.
|
1106 |
|
|
*
|
1107 |
|
|
* Masks out the network part of an IP address, given the address and
|
1108 |
|
|
* the netmask.
|
1109 |
|
|
*
|
1110 |
|
|
* Example:
|
1111 |
|
|
\code
|
1112 |
|
|
uip_ipaddr_t ipaddr1, ipaddr2, netmask;
|
1113 |
|
|
|
1114 |
|
|
uip_ipaddr(&ipaddr1, 192,16,1,2);
|
1115 |
|
|
uip_ipaddr(&netmask, 255,255,255,0);
|
1116 |
|
|
uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
|
1117 |
|
|
\endcode
|
1118 |
|
|
*
|
1119 |
|
|
* In the example above, the variable "ipaddr2" will contain the IP
|
1120 |
|
|
* address 192.168.1.0.
|
1121 |
|
|
*
|
1122 |
|
|
* \param dest Where the result is to be placed.
|
1123 |
|
|
* \param src The IP address.
|
1124 |
|
|
* \param mask The netmask.
|
1125 |
|
|
*
|
1126 |
|
|
* \hideinitializer
|
1127 |
|
|
*/
|
1128 |
|
|
#define uip_ipaddr_mask( dest, src, mask ) \
|
1129 |
|
|
do \
|
1130 |
|
|
{ \
|
1131 |
|
|
( ( u16_t * ) dest )[0] = ( ( u16_t * ) src )[0] & ( ( u16_t * ) mask )[0]; \
|
1132 |
|
|
( ( u16_t * ) dest )[1] = ( ( u16_t * ) src )[1] & ( ( u16_t * ) mask )[1]; \
|
1133 |
|
|
} while( 0 )
|
1134 |
|
|
|
1135 |
|
|
/**
|
1136 |
|
|
* Pick the first octet of an IP address.
|
1137 |
|
|
*
|
1138 |
|
|
* Picks out the first octet of an IP address.
|
1139 |
|
|
*
|
1140 |
|
|
* Example:
|
1141 |
|
|
\code
|
1142 |
|
|
uip_ipaddr_t ipaddr;
|
1143 |
|
|
u8_t octet;
|
1144 |
|
|
|
1145 |
|
|
uip_ipaddr(&ipaddr, 1,2,3,4);
|
1146 |
|
|
octet = uip_ipaddr1(&ipaddr);
|
1147 |
|
|
\endcode
|
1148 |
|
|
*
|
1149 |
|
|
* In the example above, the variable "octet" will contain the value 1.
|
1150 |
|
|
*
|
1151 |
|
|
* \hideinitializer
|
1152 |
|
|
*/
|
1153 |
|
|
#define uip_ipaddr1( addr ) ( (addr)->u8[0] )
|
1154 |
|
|
|
1155 |
|
|
/**
|
1156 |
|
|
* Pick the second octet of an IP address.
|
1157 |
|
|
*
|
1158 |
|
|
* Picks out the second octet of an IP address.
|
1159 |
|
|
*
|
1160 |
|
|
* Example:
|
1161 |
|
|
\code
|
1162 |
|
|
uip_ipaddr_t ipaddr;
|
1163 |
|
|
u8_t octet;
|
1164 |
|
|
|
1165 |
|
|
uip_ipaddr(&ipaddr, 1,2,3,4);
|
1166 |
|
|
octet = uip_ipaddr2(&ipaddr);
|
1167 |
|
|
\endcode
|
1168 |
|
|
*
|
1169 |
|
|
* In the example above, the variable "octet" will contain the value 2.
|
1170 |
|
|
*
|
1171 |
|
|
* \hideinitializer
|
1172 |
|
|
*/
|
1173 |
|
|
#define uip_ipaddr2( addr ) ( (addr)->u8[1] )
|
1174 |
|
|
|
1175 |
|
|
/**
|
1176 |
|
|
* Pick the third octet of an IP address.
|
1177 |
|
|
*
|
1178 |
|
|
* Picks out the third octet of an IP address.
|
1179 |
|
|
*
|
1180 |
|
|
* Example:
|
1181 |
|
|
\code
|
1182 |
|
|
uip_ipaddr_t ipaddr;
|
1183 |
|
|
u8_t octet;
|
1184 |
|
|
|
1185 |
|
|
uip_ipaddr(&ipaddr, 1,2,3,4);
|
1186 |
|
|
octet = uip_ipaddr3(&ipaddr);
|
1187 |
|
|
\endcode
|
1188 |
|
|
*
|
1189 |
|
|
* In the example above, the variable "octet" will contain the value 3.
|
1190 |
|
|
*
|
1191 |
|
|
* \hideinitializer
|
1192 |
|
|
*/
|
1193 |
|
|
#define uip_ipaddr3( addr ) ( (addr)->u8[2] )
|
1194 |
|
|
|
1195 |
|
|
/**
|
1196 |
|
|
* Pick the fourth octet of an IP address.
|
1197 |
|
|
*
|
1198 |
|
|
* Picks out the fourth octet of an IP address.
|
1199 |
|
|
*
|
1200 |
|
|
* Example:
|
1201 |
|
|
\code
|
1202 |
|
|
uip_ipaddr_t ipaddr;
|
1203 |
|
|
u8_t octet;
|
1204 |
|
|
|
1205 |
|
|
uip_ipaddr(&ipaddr, 1,2,3,4);
|
1206 |
|
|
octet = uip_ipaddr4(&ipaddr);
|
1207 |
|
|
\endcode
|
1208 |
|
|
*
|
1209 |
|
|
* In the example above, the variable "octet" will contain the value 4.
|
1210 |
|
|
*
|
1211 |
|
|
* \hideinitializer
|
1212 |
|
|
*/
|
1213 |
|
|
#define uip_ipaddr4( addr ) ( (addr)->u8[3] )
|
1214 |
|
|
/**
|
1215 |
|
|
* Convert 16-bit quantity from host byte order to network byte order.
|
1216 |
|
|
*
|
1217 |
|
|
* This macro is primarily used for converting constants from host
|
1218 |
|
|
* byte order to network byte order. For converting variables to
|
1219 |
|
|
* network byte order, use the htons() function instead.
|
1220 |
|
|
*
|
1221 |
|
|
* \hideinitializer
|
1222 |
|
|
*/
|
1223 |
|
|
#ifndef HTONS
|
1224 |
|
|
#if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
|
1225 |
|
|
#define HTONS( n ) ( n )
|
1226 |
|
|
#define HTONL( n ) ( n )
|
1227 |
|
|
#else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
|
1228 |
|
|
#define HTONS( n ) ( u16_t ) ( (((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8) )
|
1229 |
|
|
#define HTONL( n ) ( ((u32_t) HTONS(n) << 16) | HTONS((u32_t) (n) >> 16) )
|
1230 |
|
|
#endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
|
1231 |
|
|
#else
|
1232 |
|
|
#error "HTONS already defined!"
|
1233 |
|
|
#endif /* HTONS */
|
1234 |
|
|
|
1235 |
|
|
/**
|
1236 |
|
|
* Convert 16-bit quantity from host byte order to network byte order.
|
1237 |
|
|
*
|
1238 |
|
|
* This function is primarily used for converting variables from host
|
1239 |
|
|
* byte order to network byte order. For converting constants to
|
1240 |
|
|
* network byte order, use the HTONS() macro instead.
|
1241 |
|
|
*/
|
1242 |
|
|
#ifndef htons
|
1243 |
|
|
CCIF u16_t htons( u16_t val );
|
1244 |
|
|
#endif /* htons */
|
1245 |
|
|
|
1246 |
|
|
#ifndef ntohs
|
1247 |
|
|
#define ntohs htons
|
1248 |
|
|
#endif
|
1249 |
|
|
|
1250 |
|
|
#ifndef htonl
|
1251 |
|
|
CCIF u32_t htonl( u32_t val );
|
1252 |
|
|
#endif /* htonl */
|
1253 |
|
|
|
1254 |
|
|
#ifndef ntohl
|
1255 |
|
|
#define ntohl htonl
|
1256 |
|
|
#endif
|
1257 |
|
|
|
1258 |
|
|
/** @} */
|
1259 |
|
|
|
1260 |
|
|
/**
|
1261 |
|
|
* Pointer to the application data in the packet buffer.
|
1262 |
|
|
*
|
1263 |
|
|
* This pointer points to the application data when the application is
|
1264 |
|
|
* called. If the application wishes to send data, the application may
|
1265 |
|
|
* use this space to write the data into before calling uip_send().
|
1266 |
|
|
*/
|
1267 |
|
|
CCIF extern void *uip_appdata;
|
1268 |
|
|
|
1269 |
|
|
#if UIP_URGDATA > 0
|
1270 |
|
|
|
1271 |
|
|
/* u8_t *uip_urgdata:
|
1272 |
|
|
*
|
1273 |
|
|
* This pointer points to any urgent data that has been received. Only
|
1274 |
|
|
* present if compiled with support for urgent data (UIP_URGDATA).
|
1275 |
|
|
*/
|
1276 |
|
|
extern void *uip_urgdata;
|
1277 |
|
|
#endif /* UIP_URGDATA > 0 */
|
1278 |
|
|
|
1279 |
|
|
/**
|
1280 |
|
|
* \defgroup uipdrivervars Variables used in uIP device drivers
|
1281 |
|
|
* @{
|
1282 |
|
|
*
|
1283 |
|
|
* uIP has a few global variables that are used in device drivers for
|
1284 |
|
|
* uIP.
|
1285 |
|
|
*/
|
1286 |
|
|
|
1287 |
|
|
/**
|
1288 |
|
|
* The length of the packet in the uip_buf buffer.
|
1289 |
|
|
*
|
1290 |
|
|
* The global variable uip_len holds the length of the packet in the
|
1291 |
|
|
* uip_buf buffer.
|
1292 |
|
|
*
|
1293 |
|
|
* When the network device driver calls the uIP input function,
|
1294 |
|
|
* uip_len should be set to the length of the packet in the uip_buf
|
1295 |
|
|
* buffer.
|
1296 |
|
|
*
|
1297 |
|
|
* When sending packets, the device driver should use the contents of
|
1298 |
|
|
* the uip_len variable to determine the length of the outgoing
|
1299 |
|
|
* packet.
|
1300 |
|
|
*
|
1301 |
|
|
*/
|
1302 |
|
|
CCIF extern u16_t uip_len;
|
1303 |
|
|
|
1304 |
|
|
/**
|
1305 |
|
|
* The length of the extension headers
|
1306 |
|
|
*/
|
1307 |
|
|
extern u8_t uip_ext_len;
|
1308 |
|
|
|
1309 |
|
|
/** @} */
|
1310 |
|
|
#if UIP_URGDATA > 0
|
1311 |
|
|
extern u16_t uip_urglen, uip_surglen;
|
1312 |
|
|
#endif /* UIP_URGDATA > 0 */
|
1313 |
|
|
|
1314 |
|
|
/**
|
1315 |
|
|
* Representation of a uIP TCP connection.
|
1316 |
|
|
*
|
1317 |
|
|
* The uip_conn structure is used for identifying a connection. All
|
1318 |
|
|
* but one field in the structure are to be considered read-only by an
|
1319 |
|
|
* application. The only exception is the appstate field whose purpose
|
1320 |
|
|
* is to let the application store application-specific state (e.g.,
|
1321 |
|
|
* file pointers) for the connection. The type of this field is
|
1322 |
|
|
* configured in the "uipopt.h" header file.
|
1323 |
|
|
*/
|
1324 |
|
|
struct uip_conn
|
1325 |
|
|
{
|
1326 |
|
|
uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
|
1327 |
|
|
|
1328 |
|
|
u16_t lport; /**< The local TCP port, in network byte order. */
|
1329 |
|
|
u16_t rport; /**< The local remote TCP port, in network byte
|
1330 |
|
|
order. */
|
1331 |
|
|
|
1332 |
|
|
u8_t rcv_nxt[4]; /**< The sequence number that we expect to
|
1333 |
|
|
receive next. */
|
1334 |
|
|
u8_t snd_nxt[4]; /**< The sequence number that was last sent by
|
1335 |
|
|
us. */
|
1336 |
|
|
u16_t len; /**< Length of the data that was previously sent. */
|
1337 |
|
|
u16_t mss; /**< Current maximum segment size for the
|
1338 |
|
|
connection. */
|
1339 |
|
|
u16_t initialmss; /**< Initial maximum segment size for the
|
1340 |
|
|
connection. */
|
1341 |
|
|
u8_t sa; /**< Retransmission time-out calculation state
|
1342 |
|
|
variable. */
|
1343 |
|
|
u8_t sv; /**< Retransmission time-out calculation state
|
1344 |
|
|
variable. */
|
1345 |
|
|
u8_t rto; /**< Retransmission time-out. */
|
1346 |
|
|
u8_t tcpstateflags; /**< TCP state and flags. */
|
1347 |
|
|
u8_t timer; /**< The retransmission timer. */
|
1348 |
|
|
u8_t nrtx; /**< The number of retransmissions for the last
|
1349 |
|
|
segment sent. */
|
1350 |
|
|
|
1351 |
|
|
/** The application state. */
|
1352 |
|
|
uip_tcp_appstate_t appstate;
|
1353 |
|
|
};
|
1354 |
|
|
|
1355 |
|
|
/**
|
1356 |
|
|
* Pointer to the current TCP connection.
|
1357 |
|
|
*
|
1358 |
|
|
* The uip_conn pointer can be used to access the current TCP
|
1359 |
|
|
* connection.
|
1360 |
|
|
*/
|
1361 |
|
|
CCIF extern struct uip_conn *uip_conn;
|
1362 |
|
|
#ifdef UIP_TCP
|
1363 |
|
|
|
1364 |
|
|
/* The array containing all uIP connections. */
|
1365 |
|
|
CCIF extern struct uip_conn uip_conns[UIP_CONNS];
|
1366 |
|
|
#endif
|
1367 |
|
|
|
1368 |
|
|
/**
|
1369 |
|
|
* \addtogroup uiparch
|
1370 |
|
|
* @{
|
1371 |
|
|
*/
|
1372 |
|
|
|
1373 |
|
|
/**
|
1374 |
|
|
* 4-byte array used for the 32-bit sequence number calculations.
|
1375 |
|
|
*/
|
1376 |
|
|
extern u8_t uip_acc32[4];
|
1377 |
|
|
|
1378 |
|
|
/** @} */
|
1379 |
|
|
#if UIP_UDP == 1
|
1380 |
|
|
/**
|
1381 |
|
|
* Representation of a uIP UDP connection.
|
1382 |
|
|
*/
|
1383 |
|
|
struct uip_udp_conn
|
1384 |
|
|
{
|
1385 |
|
|
uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
|
1386 |
|
|
u16_t lport; /**< The local port number in network byte order. */
|
1387 |
|
|
u16_t rport; /**< The remote port number in network byte order. */
|
1388 |
|
|
u8_t ttl; /**< Default time-to-live. */
|
1389 |
|
|
|
1390 |
|
|
/** The application state. */
|
1391 |
|
|
uip_udp_appstate_t appstate;
|
1392 |
|
|
};
|
1393 |
|
|
|
1394 |
|
|
/**
|
1395 |
|
|
* The current UDP connection.
|
1396 |
|
|
*/
|
1397 |
|
|
extern struct uip_udp_conn *uip_udp_conn;
|
1398 |
|
|
extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
|
1399 |
|
|
#endif /* UIP_UDP */
|
1400 |
|
|
|
1401 |
|
|
struct uip_router
|
1402 |
|
|
{
|
1403 |
|
|
int ( *activate ) ( void );
|
1404 |
|
|
int ( *deactivate ) ( void );
|
1405 |
|
|
uip_ipaddr_t * ( *lookup ) ( uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop );
|
1406 |
|
|
};
|
1407 |
|
|
|
1408 |
|
|
#ifdef UIP_CONF_ROUTER
|
1409 |
|
|
extern const struct uip_router *uip_router;
|
1410 |
|
|
|
1411 |
|
|
/**
|
1412 |
|
|
* uIP routing driver registration function.
|
1413 |
|
|
*/
|
1414 |
|
|
void uip_router_register( const struct uip_router *router );
|
1415 |
|
|
#endif /*UIP_CONF_ROUTER*/
|
1416 |
|
|
|
1417 |
|
|
#ifdef UIP_CONF_ICMP6
|
1418 |
|
|
struct uip_icmp6_conn
|
1419 |
|
|
{
|
1420 |
|
|
uip_icmp6_appstate_t appstate;
|
1421 |
|
|
};
|
1422 |
|
|
extern struct uip_icmp6_conn uip_icmp6_conns;
|
1423 |
|
|
#endif /*UIP_CONF_ICMP6*/
|
1424 |
|
|
|
1425 |
|
|
/**
|
1426 |
|
|
* The uIP TCP/IP statistics.
|
1427 |
|
|
*
|
1428 |
|
|
* This is the variable in which the uIP TCP/IP statistics are gathered.
|
1429 |
|
|
*/
|
1430 |
|
|
#if UIP_STATISTICS == 1
|
1431 |
|
|
extern struct uip_stats uip_stat;
|
1432 |
|
|
#define UIP_STAT( s ) s
|
1433 |
|
|
#else
|
1434 |
|
|
#define UIP_STAT( s )
|
1435 |
|
|
#endif /* UIP_STATISTICS == 1 */
|
1436 |
|
|
|
1437 |
|
|
/**
|
1438 |
|
|
* The structure holding the TCP/IP statistics that are gathered if
|
1439 |
|
|
* UIP_STATISTICS is set to 1.
|
1440 |
|
|
*
|
1441 |
|
|
*/
|
1442 |
|
|
struct uip_stats
|
1443 |
|
|
{
|
1444 |
|
|
struct
|
1445 |
|
|
{
|
1446 |
|
|
uip_stats_t recv; /**< Number of received packets at the IP
|
1447 |
|
|
layer. */
|
1448 |
|
|
uip_stats_t sent; /**< Number of sent packets at the IP
|
1449 |
|
|
layer. */
|
1450 |
|
|
uip_stats_t forwarded; /**< Number of forwarded packets at the IP
|
1451 |
|
|
layer. */
|
1452 |
|
|
uip_stats_t drop; /**< Number of dropped packets at the IP
|
1453 |
|
|
layer. */
|
1454 |
|
|
uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
|
1455 |
|
|
IP version or header length. */
|
1456 |
|
|
uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
|
1457 |
|
|
IP length, high byte. */
|
1458 |
|
|
uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
|
1459 |
|
|
IP length, low byte. */
|
1460 |
|
|
uip_stats_t fragerr; /**< Number of packets dropped since they
|
1461 |
|
|
were IP fragments. */
|
1462 |
|
|
uip_stats_t chkerr; /**< Number of packets dropped due to IP
|
1463 |
|
|
checksum errors. */
|
1464 |
|
|
uip_stats_t protoerr; /**< Number of packets dropped since they
|
1465 |
|
|
were neither ICMP, UDP nor TCP. */
|
1466 |
|
|
} ip; /**< IP statistics. */
|
1467 |
|
|
struct
|
1468 |
|
|
{
|
1469 |
|
|
uip_stats_t recv; /**< Number of received ICMP packets. */
|
1470 |
|
|
uip_stats_t sent; /**< Number of sent ICMP packets. */
|
1471 |
|
|
uip_stats_t drop; /**< Number of dropped ICMP packets. */
|
1472 |
|
|
uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
|
1473 |
|
|
type. */
|
1474 |
|
|
uip_stats_t chkerr; /**< Number of ICMP packets with a bad
|
1475 |
|
|
checksum. */
|
1476 |
|
|
} icmp; /**< ICMP statistics. */
|
1477 |
|
|
#ifdef UIP_TCP
|
1478 |
|
|
struct
|
1479 |
|
|
{
|
1480 |
|
|
uip_stats_t recv; /**< Number of recived TCP segments. */
|
1481 |
|
|
uip_stats_t sent; /**< Number of sent TCP segments. */
|
1482 |
|
|
uip_stats_t drop; /**< Number of dropped TCP segments. */
|
1483 |
|
|
uip_stats_t chkerr; /**< Number of TCP segments with a bad
|
1484 |
|
|
checksum. */
|
1485 |
|
|
uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
|
1486 |
|
|
number. */
|
1487 |
|
|
uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
|
1488 |
|
|
uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
|
1489 |
|
|
uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
|
1490 |
|
|
connections was avaliable. */
|
1491 |
|
|
uip_stats_t synrst; /**< Number of SYNs for closed ports,
|
1492 |
|
|
triggering a RST. */
|
1493 |
|
|
} tcp; /**< TCP statistics. */
|
1494 |
|
|
#endif
|
1495 |
|
|
#ifdef UIP_UDP
|
1496 |
|
|
struct
|
1497 |
|
|
{
|
1498 |
|
|
uip_stats_t drop; /**< Number of dropped UDP segments. */
|
1499 |
|
|
uip_stats_t recv; /**< Number of recived UDP segments. */
|
1500 |
|
|
uip_stats_t sent; /**< Number of sent UDP segments. */
|
1501 |
|
|
uip_stats_t chkerr; /**< Number of UDP segments with a bad
|
1502 |
|
|
checksum. */
|
1503 |
|
|
} udp; /**< UDP statistics. */
|
1504 |
|
|
#endif /* UIP_UDP */
|
1505 |
|
|
#if UIP_CONF_IPV6 != 0
|
1506 |
|
|
struct
|
1507 |
|
|
{
|
1508 |
|
|
uip_stats_t drop; /**< Number of dropped ND6 packets. */
|
1509 |
|
|
uip_stats_t recv; /**< Number of recived ND6 packets */
|
1510 |
|
|
uip_stats_t sent; /**< Number of sent ND6 packets */
|
1511 |
|
|
} nd6;
|
1512 |
|
|
#endif /*UIP_CONF_IPV6*/
|
1513 |
|
|
};
|
1514 |
|
|
|
1515 |
|
|
/*---------------------------------------------------------------------------*/
|
1516 |
|
|
|
1517 |
|
|
/* All the stuff below this point is internal to uIP and should not be
|
1518 |
|
|
* used directly by an application or by a device driver.
|
1519 |
|
|
*/
|
1520 |
|
|
|
1521 |
|
|
/*---------------------------------------------------------------------------*/
|
1522 |
|
|
|
1523 |
|
|
/* u8_t uip_flags:
|
1524 |
|
|
*
|
1525 |
|
|
* When the application is called, uip_flags will contain the flags
|
1526 |
|
|
* that are defined in this file. Please read below for more
|
1527 |
|
|
* information.
|
1528 |
|
|
*/
|
1529 |
|
|
CCIF extern u8_t uip_flags;
|
1530 |
|
|
|
1531 |
|
|
/* The following flags may be set in the global variable uip_flags
|
1532 |
|
|
before calling the application callback. The UIP_ACKDATA,
|
1533 |
|
|
UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
|
1534 |
|
|
whereas the others are mutually exclusive. Note that these flags
|
1535 |
|
|
should *NOT* be accessed directly, but only through the uIP
|
1536 |
|
|
functions/macros. */
|
1537 |
|
|
#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
|
1538 |
|
|
acked and the application should send
|
1539 |
|
|
out new data instead of retransmitting
|
1540 |
|
|
the last data. */
|
1541 |
|
|
#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
|
1542 |
|
|
us new data. */
|
1543 |
|
|
#define UIP_REXMIT 4 /* Tells the application to retransmit the
|
1544 |
|
|
data that was last sent. */
|
1545 |
|
|
#define UIP_POLL 8 /* Used for polling the application, to
|
1546 |
|
|
check if the application has data that
|
1547 |
|
|
it wants to send. */
|
1548 |
|
|
#define UIP_CLOSE 16 /* The remote host has closed the
|
1549 |
|
|
connection, thus the connection has
|
1550 |
|
|
gone away. Or the application signals
|
1551 |
|
|
that it wants to close the
|
1552 |
|
|
connection. */
|
1553 |
|
|
#define UIP_ABORT 32 /* The remote host has aborted the
|
1554 |
|
|
connection, thus the connection has
|
1555 |
|
|
gone away. Or the application signals
|
1556 |
|
|
that it wants to abort the
|
1557 |
|
|
connection. */
|
1558 |
|
|
#define UIP_CONNECTED 64 /* We have got a connection from a remote
|
1559 |
|
|
host and have set up a new connection
|
1560 |
|
|
for it, or an active connection has
|
1561 |
|
|
been successfully established. */
|
1562 |
|
|
|
1563 |
|
|
#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
|
1564 |
|
|
too many retransmissions. */
|
1565 |
|
|
|
1566 |
|
|
/**
|
1567 |
|
|
* \brief process the options within a hop by hop or destination option header
|
1568 |
|
|
* \retval 0: nothing to send,
|
1569 |
|
|
* \retval 1: drop pkt
|
1570 |
|
|
* \retval 2: ICMP error message to send
|
1571 |
|
|
*/
|
1572 |
|
|
|
1573 |
|
|
/*static u8_t
|
1574 |
|
|
uip_ext_hdr_options_process(); */
|
1575 |
|
|
|
1576 |
|
|
/* uip_process(flag):
|
1577 |
|
|
*
|
1578 |
|
|
* The actual uIP function which does all the work.
|
1579 |
|
|
*/
|
1580 |
|
|
void uip_process( u8_t flag );
|
1581 |
|
|
|
1582 |
|
|
/* The following flags are passed as an argument to the uip_process()
|
1583 |
|
|
function. They are used to distinguish between the two cases where
|
1584 |
|
|
uip_process() is called. It can be called either because we have
|
1585 |
|
|
incoming data that should be processed, or because the periodic
|
1586 |
|
|
timer has fired. These values are never used directly, but only in
|
1587 |
|
|
the macros defined in this file. */
|
1588 |
|
|
#define UIP_DATA 1 /* Tells uIP that there is incoming
|
1589 |
|
|
data in the uip_buf buffer. The
|
1590 |
|
|
length of the data is stored in the
|
1591 |
|
|
global variable uip_len. */
|
1592 |
|
|
#define UIP_TIMER 2 /* Tells uIP that the periodic timer
|
1593 |
|
|
has fired. */
|
1594 |
|
|
#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
|
1595 |
|
|
be polled. */
|
1596 |
|
|
#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
|
1597 |
|
|
should be constructed in the
|
1598 |
|
|
uip_buf buffer. */
|
1599 |
|
|
#ifdef UIP_UDP
|
1600 |
|
|
#define UIP_UDP_TIMER 5
|
1601 |
|
|
#endif /* UIP_UDP */
|
1602 |
|
|
|
1603 |
|
|
/* The TCP states used in the uip_conn->tcpstateflags. */
|
1604 |
|
|
#define UIP_CLOSED 0
|
1605 |
|
|
#define UIP_SYN_RCVD 1
|
1606 |
|
|
#define UIP_SYN_SENT 2
|
1607 |
|
|
#define UIP_ESTABLISHED 3
|
1608 |
|
|
#define UIP_FIN_WAIT_1 4
|
1609 |
|
|
#define UIP_FIN_WAIT_2 5
|
1610 |
|
|
#define UIP_CLOSING 6
|
1611 |
|
|
#define UIP_TIME_WAIT 7
|
1612 |
|
|
#define UIP_LAST_ACK 8
|
1613 |
|
|
#define UIP_TS_MASK 15
|
1614 |
|
|
|
1615 |
|
|
#define UIP_STOPPED 16
|
1616 |
|
|
|
1617 |
|
|
/* The TCP and IP headers. */
|
1618 |
|
|
#include "net/pack_struct_start.h"
|
1619 |
|
|
struct uip_tcpip_hdr
|
1620 |
|
|
{
|
1621 |
|
|
#if UIP_CONF_IPV6 != 0
|
1622 |
|
|
/* IPv6 header. */
|
1623 |
|
|
u8_t vtc, tcflow;
|
1624 |
|
|
u16_t flow;
|
1625 |
|
|
u8_t len[2];
|
1626 |
|
|
u8_t proto, ttl;
|
1627 |
|
|
uip_ip6addr_t srcipaddr, destipaddr;
|
1628 |
|
|
#else /* UIP_CONF_IPV6 */
|
1629 |
|
|
/* IPv4 header. */
|
1630 |
|
|
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
|
1631 |
|
|
u16_t ipchksum;
|
1632 |
|
|
uip_ipaddr_t srcipaddr, destipaddr;
|
1633 |
|
|
#endif /* UIP_CONF_IPV6 */
|
1634 |
|
|
|
1635 |
|
|
/* TCP header. */
|
1636 |
|
|
u16_t srcport, destport;
|
1637 |
|
|
u8_t seqno[4], ackno[4], tcpoffset, flags, wnd[2];
|
1638 |
|
|
u16_t tcpchksum;
|
1639 |
|
|
u8_t urgp[2];
|
1640 |
|
|
u8_t optdata[4];
|
1641 |
|
|
}
|
1642 |
|
|
#include "net/pack_struct_end.h"
|
1643 |
|
|
|
1644 |
|
|
/* The ICMP and IP headers. */
|
1645 |
|
|
#include "net/pack_struct_start.h"
|
1646 |
|
|
struct uip_icmpip_hdr
|
1647 |
|
|
{
|
1648 |
|
|
#if UIP_CONF_IPV6 != 0
|
1649 |
|
|
/* IPv6 header. */
|
1650 |
|
|
u8_t vtc, tcf;
|
1651 |
|
|
u16_t flow;
|
1652 |
|
|
u8_t len[2];
|
1653 |
|
|
u8_t proto, ttl;
|
1654 |
|
|
uip_ip6addr_t srcipaddr, destipaddr;
|
1655 |
|
|
#else /* UIP_CONF_IPV6 */
|
1656 |
|
|
/* IPv4 header. */
|
1657 |
|
|
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
|
1658 |
|
|
u16_t ipchksum;
|
1659 |
|
|
uip_ipaddr_t srcipaddr, destipaddr;
|
1660 |
|
|
#endif /* UIP_CONF_IPV6 */
|
1661 |
|
|
|
1662 |
|
|
/* ICMP header. */
|
1663 |
|
|
u8_t type, icode;
|
1664 |
|
|
u16_t icmpchksum;
|
1665 |
|
|
#if !UIP_CONF_IPV6
|
1666 |
|
|
u16_t id, seqno;
|
1667 |
|
|
u8_t payload[1];
|
1668 |
|
|
#endif /* !UIP_CONF_IPV6 */
|
1669 |
|
|
}
|
1670 |
|
|
|
1671 |
|
|
#include "net/pack_struct_end.h"
|
1672 |
|
|
|
1673 |
|
|
/* The UDP and IP headers. */
|
1674 |
|
|
#include "net/pack_struct_start.h"
|
1675 |
|
|
struct uip_udpip_hdr
|
1676 |
|
|
{
|
1677 |
|
|
#if UIP_CONF_IPV6 != 0
|
1678 |
|
|
/* IPv6 header. */
|
1679 |
|
|
u8_t vtc, tcf;
|
1680 |
|
|
u16_t flow;
|
1681 |
|
|
u8_t len[2];
|
1682 |
|
|
u8_t proto, ttl;
|
1683 |
|
|
uip_ip6addr_t srcipaddr, destipaddr;
|
1684 |
|
|
#else /* UIP_CONF_IPV6 */
|
1685 |
|
|
/* IP header. */
|
1686 |
|
|
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
|
1687 |
|
|
u16_t ipchksum;
|
1688 |
|
|
uip_ipaddr_t srcipaddr, destipaddr;
|
1689 |
|
|
#endif /* UIP_CONF_IPV6 */
|
1690 |
|
|
|
1691 |
|
|
/* UDP header. */
|
1692 |
|
|
u16_t srcport, destport;
|
1693 |
|
|
u16_t udplen;
|
1694 |
|
|
u16_t udpchksum;
|
1695 |
|
|
}
|
1696 |
|
|
|
1697 |
|
|
#include "net/pack_struct_end.h"
|
1698 |
|
|
|
1699 |
|
|
/*
|
1700 |
|
|
* In IPv6 the length of the L3 headers before the transport header is
|
1701 |
|
|
* not fixed, due to the possibility to include extension option headers
|
1702 |
|
|
* after the IP header. hence we split here L3 and L4 headers
|
1703 |
|
|
*/
|
1704 |
|
|
|
1705 |
|
|
/* The IP header */
|
1706 |
|
|
struct uip_ip_hdr
|
1707 |
|
|
{
|
1708 |
|
|
#if UIP_CONF_IPV6 != 0
|
1709 |
|
|
/* IPV6 header */
|
1710 |
|
|
u8_t vtc;
|
1711 |
|
|
u8_t tcflow;
|
1712 |
|
|
u16_t flow;
|
1713 |
|
|
u8_t len[2];
|
1714 |
|
|
u8_t proto, ttl;
|
1715 |
|
|
uip_ip6addr_t srcipaddr, destipaddr;
|
1716 |
|
|
#else /* UIP_CONF_IPV6 */
|
1717 |
|
|
/* IPV4 header */
|
1718 |
|
|
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
|
1719 |
|
|
u16_t ipchksum;
|
1720 |
|
|
uip_ipaddr_t srcipaddr, destipaddr;
|
1721 |
|
|
#endif /* UIP_CONF_IPV6 */
|
1722 |
|
|
};
|
1723 |
|
|
|
1724 |
|
|
/*
|
1725 |
|
|
* IPv6 extension option headers: we are able to process
|
1726 |
|
|
* the 4 extension headers defined in RFC2460 (IPv6):
|
1727 |
|
|
* - Hop by hop option header, destination option header:
|
1728 |
|
|
* These two are not used by any core IPv6 protocol, hence
|
1729 |
|
|
* we just read them and go to the next. They convey options,
|
1730 |
|
|
* the options defined in RFC2460 are Pad1 and PadN, which do
|
1731 |
|
|
* some padding, and that we do not need to read (the length
|
1732 |
|
|
* field in the header is enough)
|
1733 |
|
|
* - Routing header: this one is most notably used by MIPv6,
|
1734 |
|
|
* which we do not implement, hence we just read it and go
|
1735 |
|
|
* to the next
|
1736 |
|
|
* - Fragmentation header: we read this header and are able to
|
1737 |
|
|
* reassemble packets
|
1738 |
|
|
*
|
1739 |
|
|
* We do not offer any means to send packets with extension headers
|
1740 |
|
|
*
|
1741 |
|
|
* We do not implement Authentication and ESP headers, which are
|
1742 |
|
|
* used in IPSec and defined in RFC4302,4303,4305,4385
|
1743 |
|
|
*/
|
1744 |
|
|
|
1745 |
|
|
/* common header part */
|
1746 |
|
|
struct uip_ext_hdr
|
1747 |
|
|
{
|
1748 |
|
|
u8_t next;
|
1749 |
|
|
u8_t len;
|
1750 |
|
|
};
|
1751 |
|
|
|
1752 |
|
|
/* Hop by Hop option header */
|
1753 |
|
|
struct uip_hbho_hdr
|
1754 |
|
|
{
|
1755 |
|
|
u8_t next;
|
1756 |
|
|
u8_t len;
|
1757 |
|
|
};
|
1758 |
|
|
|
1759 |
|
|
/* destination option header */
|
1760 |
|
|
struct uip_desto_hdr
|
1761 |
|
|
{
|
1762 |
|
|
u8_t next;
|
1763 |
|
|
u8_t len;
|
1764 |
|
|
};
|
1765 |
|
|
|
1766 |
|
|
/* We do not define structures for PAD1 and PADN options */
|
1767 |
|
|
|
1768 |
|
|
/*
|
1769 |
|
|
* routing header
|
1770 |
|
|
* the routing header as 4 common bytes, then routing header type
|
1771 |
|
|
* specific data there are several types of routing header. Type 0 was
|
1772 |
|
|
* deprecated as per RFC5095 most notable other type is 2, used in
|
1773 |
|
|
* RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
|
1774 |
|
|
* parse the 4 first bytes
|
1775 |
|
|
*/
|
1776 |
|
|
struct uip_routing_hdr
|
1777 |
|
|
{
|
1778 |
|
|
u8_t next;
|
1779 |
|
|
u8_t len;
|
1780 |
|
|
u8_t routing_type;
|
1781 |
|
|
u8_t seg_left;
|
1782 |
|
|
};
|
1783 |
|
|
|
1784 |
|
|
/* fragmentation header */
|
1785 |
|
|
struct uip_frag_hdr
|
1786 |
|
|
{
|
1787 |
|
|
u8_t next;
|
1788 |
|
|
u8_t res;
|
1789 |
|
|
u16_t offsetresmore;
|
1790 |
|
|
u32_t id;
|
1791 |
|
|
};
|
1792 |
|
|
|
1793 |
|
|
/*
|
1794 |
|
|
* an option within the destination or hop by hop option headers
|
1795 |
|
|
* it contains type an length, which is true for all options but PAD1
|
1796 |
|
|
*/
|
1797 |
|
|
struct uip_ext_hdr_opt
|
1798 |
|
|
{
|
1799 |
|
|
u8_t type;
|
1800 |
|
|
u8_t len;
|
1801 |
|
|
};
|
1802 |
|
|
|
1803 |
|
|
/* PADN option */
|
1804 |
|
|
struct uip_ext_hdr_opt_padn
|
1805 |
|
|
{
|
1806 |
|
|
u8_t opt_type;
|
1807 |
|
|
u8_t opt_len;
|
1808 |
|
|
};
|
1809 |
|
|
|
1810 |
|
|
/* TCP header */
|
1811 |
|
|
struct uip_tcp_hdr
|
1812 |
|
|
{
|
1813 |
|
|
u16_t srcport;
|
1814 |
|
|
u16_t destport;
|
1815 |
|
|
u8_t seqno[4];
|
1816 |
|
|
u8_t ackno[4];
|
1817 |
|
|
u8_t tcpoffset;
|
1818 |
|
|
u8_t flags;
|
1819 |
|
|
u8_t wnd[2];
|
1820 |
|
|
u16_t tcpchksum;
|
1821 |
|
|
u8_t urgp[2];
|
1822 |
|
|
u8_t optdata[4];
|
1823 |
|
|
};
|
1824 |
|
|
|
1825 |
|
|
/* The ICMP headers. */
|
1826 |
|
|
struct uip_icmp_hdr
|
1827 |
|
|
{
|
1828 |
|
|
u8_t type, icode;
|
1829 |
|
|
u16_t icmpchksum;
|
1830 |
|
|
#if !UIP_CONF_IPV6
|
1831 |
|
|
u16_t id, seqno;
|
1832 |
|
|
#endif /* !UIP_CONF_IPV6 */
|
1833 |
|
|
};
|
1834 |
|
|
|
1835 |
|
|
/* The UDP headers. */
|
1836 |
|
|
struct uip_udp_hdr
|
1837 |
|
|
{
|
1838 |
|
|
u16_t srcport;
|
1839 |
|
|
u16_t destport;
|
1840 |
|
|
u16_t udplen;
|
1841 |
|
|
u16_t udpchksum;
|
1842 |
|
|
};
|
1843 |
|
|
|
1844 |
|
|
/**
|
1845 |
|
|
* The buffer size available for user data in the \ref uip_buf buffer.
|
1846 |
|
|
*
|
1847 |
|
|
* This macro holds the available size for user data in the \ref
|
1848 |
|
|
* uip_buf buffer. The macro is intended to be used for checking
|
1849 |
|
|
* bounds of available user data.
|
1850 |
|
|
*
|
1851 |
|
|
* Example:
|
1852 |
|
|
\code
|
1853 |
|
|
snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
|
1854 |
|
|
\endcode
|
1855 |
|
|
*
|
1856 |
|
|
* \hideinitializer
|
1857 |
|
|
*/
|
1858 |
|
|
#define UIP_APPDATA_SIZE ( UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN )
|
1859 |
|
|
#define UIP_APPDATA_PTR ( void * ) &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
|
1860 |
|
|
|
1861 |
|
|
#define UIP_PROTO_ICMP 1
|
1862 |
|
|
#define UIP_PROTO_TCP 6
|
1863 |
|
|
#define UIP_PROTO_UDP 17
|
1864 |
|
|
#define UIP_PROTO_ICMP6 58
|
1865 |
|
|
|
1866 |
|
|
#if UIP_CONF_IPV6 != 0
|
1867 |
|
|
|
1868 |
|
|
/** @{ */
|
1869 |
|
|
|
1870 |
|
|
/** \brief extension headers types */
|
1871 |
|
|
#define UIP_PROTO_HBHO 0
|
1872 |
|
|
#define UIP_PROTO_DESTO 60
|
1873 |
|
|
#define UIP_PROTO_ROUTING 43
|
1874 |
|
|
#define UIP_PROTO_FRAG 44
|
1875 |
|
|
#define UIP_PROTO_NONE 59
|
1876 |
|
|
|
1877 |
|
|
/** @} */
|
1878 |
|
|
|
1879 |
|
|
/** @{ */
|
1880 |
|
|
|
1881 |
|
|
/** \brief Destination and Hop By Hop extension headers option types */
|
1882 |
|
|
#define UIP_EXT_HDR_OPT_PAD1 0
|
1883 |
|
|
#define UIP_EXT_HDR_OPT_PADN 1
|
1884 |
|
|
|
1885 |
|
|
/** @} */
|
1886 |
|
|
|
1887 |
|
|
/** @{ */
|
1888 |
|
|
|
1889 |
|
|
/**
|
1890 |
|
|
* \brief Bitmaps for extension header processing
|
1891 |
|
|
*
|
1892 |
|
|
* When processing extension headers, we should record somehow which one we
|
1893 |
|
|
* see, because you cannot have twice the same header, except for destination
|
1894 |
|
|
* We store all this in one u8_t bitmap one bit for each header expected. The
|
1895 |
|
|
* order in the bitmap is the order recommended in RFC2460
|
1896 |
|
|
*/
|
1897 |
|
|
#define UIP_EXT_HDR_BITMAP_HBHO 0x01
|
1898 |
|
|
#define UIP_EXT_HDR_BITMAP_DESTO1 0x02
|
1899 |
|
|
#define UIP_EXT_HDR_BITMAP_ROUTING 0x04
|
1900 |
|
|
#define UIP_EXT_HDR_BITMAP_FRAG 0x08
|
1901 |
|
|
#define UIP_EXT_HDR_BITMAP_AH 0x10
|
1902 |
|
|
#define UIP_EXT_HDR_BITMAP_ESP 0x20
|
1903 |
|
|
#define UIP_EXT_HDR_BITMAP_DESTO2 0x40
|
1904 |
|
|
|
1905 |
|
|
/** @} */
|
1906 |
|
|
#endif /* UIP_CONF_IPV6 */
|
1907 |
|
|
|
1908 |
|
|
/* Header sizes. */
|
1909 |
|
|
#if UIP_CONF_IPV6 != 0
|
1910 |
|
|
#define UIP_IPH_LEN 40
|
1911 |
|
|
#define UIP_FRAGH_LEN 8
|
1912 |
|
|
#else /* UIP_CONF_IPV6 */
|
1913 |
|
|
#define UIP_IPH_LEN 20 /* Size of IP header */
|
1914 |
|
|
#endif /* UIP_CONF_IPV6 */
|
1915 |
|
|
|
1916 |
|
|
#define UIP_UDPH_LEN 8 /* Size of UDP header */
|
1917 |
|
|
#define UIP_TCPH_LEN 20 /* Size of TCP header */
|
1918 |
|
|
#ifdef UIP_IPH_LEN
|
1919 |
|
|
#define UIP_ICMPH_LEN 4 /* Size of ICMP header */
|
1920 |
|
|
#endif
|
1921 |
|
|
#define UIP_IPUDPH_LEN ( UIP_UDPH_LEN + UIP_IPH_LEN ) /* Size of IP +
|
1922 |
|
|
* UDP
|
1923 |
|
|
* header */
|
1924 |
|
|
#define UIP_IPTCPH_LEN ( UIP_TCPH_LEN + UIP_IPH_LEN ) /* Size of IP +
|
1925 |
|
|
* TCP
|
1926 |
|
|
* header */
|
1927 |
|
|
#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
|
1928 |
|
|
#define UIP_IPICMPH_LEN ( UIP_IPH_LEN + UIP_ICMPH_LEN ) /* size of ICMP
|
1929 |
|
|
+ IP header */
|
1930 |
|
|
#define UIP_LLIPH_LEN ( UIP_LLH_LEN + UIP_IPH_LEN ) /* size of L2
|
1931 |
|
|
+ IP header */
|
1932 |
|
|
#if UIP_CONF_IPV6 != 0
|
1933 |
|
|
|
1934 |
|
|
/**
|
1935 |
|
|
* The sums below are quite used in ND. When used for uip_buf, we
|
1936 |
|
|
* include link layer length when used for uip_len, we do not, hence
|
1937 |
|
|
* we need values with and without LLH_LEN we do not use capital
|
1938 |
|
|
* letters as these values are variable
|
1939 |
|
|
*/
|
1940 |
|
|
#define uip_l2_l3_hdr_len ( UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len )
|
1941 |
|
|
#define uip_l2_l3_icmp_hdr_len ( UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN )
|
1942 |
|
|
#define uip_l3_hdr_len ( UIP_IPH_LEN + uip_ext_len )
|
1943 |
|
|
#define uip_l3_icmp_hdr_len ( UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN )
|
1944 |
|
|
#endif /*UIP_CONF_IPV6*/
|
1945 |
|
|
|
1946 |
|
|
#ifdef UIP_FIXEDADDR
|
1947 |
|
|
CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
|
1948 |
|
|
#else /* UIP_FIXEDADDR */
|
1949 |
|
|
CCIF extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
|
1950 |
|
|
#endif /* UIP_FIXEDADDR */
|
1951 |
|
|
CCIF extern const uip_ipaddr_t uip_broadcast_addr;
|
1952 |
|
|
CCIF extern const uip_ipaddr_t uip_all_zeroes_addr;
|
1953 |
|
|
|
1954 |
|
|
#ifdef UIP_FIXEDETHADDR
|
1955 |
|
|
CCIF extern const uip_lladdr_t uip_lladdr;
|
1956 |
|
|
#else
|
1957 |
|
|
CCIF extern uip_lladdr_t uip_lladdr;
|
1958 |
|
|
#endif
|
1959 |
|
|
#if UIP_CONF_IPV6 != 0
|
1960 |
|
|
|
1961 |
|
|
/**
|
1962 |
|
|
* \brief Is IPv6 address a the unspecified address
|
1963 |
|
|
* a is of type uip_ipaddr_t
|
1964 |
|
|
*/
|
1965 |
|
|
#define uip_is_addr_unspecified( a ) \
|
1966 |
|
|
( \
|
1967 |
|
|
(((a)->u16[0]) == 0) && \
|
1968 |
|
|
(((a)->u16[1]) == 0) && \
|
1969 |
|
|
(((a)->u16[2]) == 0) && \
|
1970 |
|
|
(((a)->u16[3]) == 0) && \
|
1971 |
|
|
(((a)->u16[4]) == 0) && \
|
1972 |
|
|
(((a)->u16[5]) == 0) && \
|
1973 |
|
|
(((a)->u16[6]) == 0) && \
|
1974 |
|
|
(((a)->u16[7]) == 0) \
|
1975 |
|
|
)
|
1976 |
|
|
|
1977 |
|
|
/** \brief Is IPv6 address a the link local all-nodes multicast address */
|
1978 |
|
|
#define uip_is_addr_linklocal_allnodes_mcast( a ) \
|
1979 |
|
|
( \
|
1980 |
|
|
(((a)->u8[0]) == 0xff) && \
|
1981 |
|
|
(((a)->u8[1]) == 0x02) && \
|
1982 |
|
|
(((a)->u16[1]) == 0) && \
|
1983 |
|
|
(((a)->u16[2]) == 0) && \
|
1984 |
|
|
(((a)->u16[3]) == 0) && \
|
1985 |
|
|
(((a)->u16[4]) == 0) && \
|
1986 |
|
|
(((a)->u16[5]) == 0) && \
|
1987 |
|
|
(((a)->u16[6]) == 0) && \
|
1988 |
|
|
(((a)->u8[14]) == 0) && \
|
1989 |
|
|
(((a)->u8[15]) == 0x01) \
|
1990 |
|
|
)
|
1991 |
|
|
|
1992 |
|
|
/** \brief set IP address a to unspecified */
|
1993 |
|
|
#define uip_create_unspecified( a ) uip_ip6addr( a, 0, 0, 0, 0, 0, 0, 0, 0 )
|
1994 |
|
|
|
1995 |
|
|
/** \brief set IP address a to the link local all-nodes multicast address */
|
1996 |
|
|
#define uip_create_linklocal_allnodes_mcast( a ) uip_ip6addr( a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001 )
|
1997 |
|
|
|
1998 |
|
|
/** \brief set IP address a to the link local all-routers multicast address */
|
1999 |
|
|
#define uip_create_linklocal_allrouters_mcast( a ) uip_ip6addr( a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002 )
|
2000 |
|
|
|
2001 |
|
|
/**
|
2002 |
|
|
* \brief is addr (a) a solicited node multicast address, see RFC3513
|
2003 |
|
|
* a is of type uip_ipaddr_t*
|
2004 |
|
|
*/
|
2005 |
|
|
#define uip_is_addr_solicited_node( a ) \
|
2006 |
|
|
( \
|
2007 |
|
|
(((a)->u8[0]) == 0xFF) && \
|
2008 |
|
|
(((a)->u8[1]) == 0x02) && \
|
2009 |
|
|
(((a)->u16[1]) == 0) && \
|
2010 |
|
|
(((a)->u16[2]) == 0) && \
|
2011 |
|
|
(((a)->u16[3]) == 0) && \
|
2012 |
|
|
(((a)->u16[4]) == 0) && \
|
2013 |
|
|
(((a)->u16[5]) == 1) && \
|
2014 |
|
|
(((a)->u8[12]) == 0xFF) \
|
2015 |
|
|
)
|
2016 |
|
|
|
2017 |
|
|
/**
|
2018 |
|
|
* \briefput in b the solicited node address corresponding to address a
|
2019 |
|
|
* both a and b are of type uip_ipaddr_t*
|
2020 |
|
|
* */
|
2021 |
|
|
#define uip_create_solicited_node( a, b ) \
|
2022 |
|
|
( ((b)->u8[0]) = 0xFF ); \
|
2023 |
|
|
( ((b)->u8[1]) = 0x02 ); \
|
2024 |
|
|
( ((b)->u16[1]) = 0 ); \
|
2025 |
|
|
( ((b)->u16[2]) = 0 ); \
|
2026 |
|
|
( ((b)->u16[3]) = 0 ); \
|
2027 |
|
|
( ((b)->u16[4]) = 0 ); \
|
2028 |
|
|
( ((b)->u8[10]) = 0 ); \
|
2029 |
|
|
( ((b)->u8[11]) = 0x01 ); \
|
2030 |
|
|
( ((b)->u8[12]) = 0xFF ); \
|
2031 |
|
|
( ((b)->u8[13]) = ((a)->u8[13]) ); \
|
2032 |
|
|
( ((b)->u16[7]) = ((a)->u16[7]) )
|
2033 |
|
|
|
2034 |
|
|
/**
|
2035 |
|
|
* \brief is addr (a) a link local unicast address, see RFC3513
|
2036 |
|
|
* i.e. is (a) on prefix FE80::/10
|
2037 |
|
|
* a is of type uip_ipaddr_t*
|
2038 |
|
|
*/
|
2039 |
|
|
#define uip_is_addr_link_local( a ) ( (((a)->u8[0]) == 0xFE) && (((a)->u8[1]) == 0x80) )
|
2040 |
|
|
|
2041 |
|
|
/**
|
2042 |
|
|
* \brief was addr (a) forged based on the mac address m
|
2043 |
|
|
* a type is uip_ipaddr_t
|
2044 |
|
|
* m type is uiplladdr_t
|
2045 |
|
|
*/
|
2046 |
|
|
#ifdef UIP_CONF_LL_802154
|
2047 |
|
|
#define uip_is_addr_mac_addr_based( a, m ) \
|
2048 |
|
|
( \
|
2049 |
|
|
(((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \
|
2050 |
|
|
(((a)->u8[9]) == (m)->addr[1]) && \
|
2051 |
|
|
(((a)->u8[10]) == (m)->addr[2]) && \
|
2052 |
|
|
(((a)->u8[11]) == (m)->addr[3]) && \
|
2053 |
|
|
(((a)->u8[12]) == (m)->addr[4]) && \
|
2054 |
|
|
(((a)->u8[13]) == (m)->addr[5]) && \
|
2055 |
|
|
(((a)->u8[14]) == (m)->addr[6]) && \
|
2056 |
|
|
(((a)->u8[15]) == (m)->addr[7]) \
|
2057 |
|
|
)
|
2058 |
|
|
#else
|
2059 |
|
|
#define uip_is_addr_mac_addr_based( a, m ) \
|
2060 |
|
|
( \
|
2061 |
|
|
(((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
|
2062 |
|
|
(((a)->u8[9]) == (m)->addr[1]) && \
|
2063 |
|
|
(((a)->u8[10]) == (m)->addr[2]) && \
|
2064 |
|
|
(((a)->u8[11]) == 0xff) && \
|
2065 |
|
|
(((a)->u8[12]) == 0xfe) && \
|
2066 |
|
|
(((a)->u8[13]) == (m)->addr[3]) && \
|
2067 |
|
|
(((a)->u8[14]) == (m)->addr[4]) && \
|
2068 |
|
|
(((a)->u8[15]) == (m)->addr[5]) \
|
2069 |
|
|
)
|
2070 |
|
|
#endif /*UIP_CONF_LL_802154*/
|
2071 |
|
|
|
2072 |
|
|
/**
|
2073 |
|
|
* \brief is address a multicast address, see RFC 3513
|
2074 |
|
|
* a is of type uip_ipaddr_t*
|
2075 |
|
|
* */
|
2076 |
|
|
#define uip_is_addr_mcast( a ) ( ((a)->u8[0]) == 0xFF )
|
2077 |
|
|
|
2078 |
|
|
/**
|
2079 |
|
|
* \brief is group-id of multicast address a
|
2080 |
|
|
* the all nodes group-id
|
2081 |
|
|
*/
|
2082 |
|
|
#define uip_is_mcast_group_id_all_nodes( a ) \
|
2083 |
|
|
( \
|
2084 |
|
|
(((a)->u16[1]) == 0) && \
|
2085 |
|
|
(((a)->u16[2]) == 0) && \
|
2086 |
|
|
(((a)->u16[3]) == 0) && \
|
2087 |
|
|
(((a)->u16[4]) == 0) && \
|
2088 |
|
|
(((a)->u16[5]) == 0) && \
|
2089 |
|
|
(((a)->u16[6]) == 0) && \
|
2090 |
|
|
(((a)->u8[14]) == 0) && \
|
2091 |
|
|
(((a)->u8[15]) == 1) \
|
2092 |
|
|
)
|
2093 |
|
|
|
2094 |
|
|
/**
|
2095 |
|
|
* \brief is group-id of multicast address a
|
2096 |
|
|
* the all routers group-id
|
2097 |
|
|
*/
|
2098 |
|
|
#define uip_is_mcast_group_id_all_routers( a ) \
|
2099 |
|
|
( \
|
2100 |
|
|
(((a)->u16[1]) == 0) && \
|
2101 |
|
|
(((a)->u16[2]) == 0) && \
|
2102 |
|
|
(((a)->u16[3]) == 0) && \
|
2103 |
|
|
(((a)->u16[4]) == 0) && \
|
2104 |
|
|
(((a)->u16[5]) == 0) && \
|
2105 |
|
|
(((a)->u16[6]) == 0) && \
|
2106 |
|
|
(((a)->u8[14]) == 0) && \
|
2107 |
|
|
(((a)->u8[15]) == 2) \
|
2108 |
|
|
)
|
2109 |
|
|
#endif /*UIP_CONF_IPV6*/
|
2110 |
|
|
|
2111 |
|
|
/**
|
2112 |
|
|
* Calculate the Internet checksum over a buffer.
|
2113 |
|
|
*
|
2114 |
|
|
* The Internet checksum is the one's complement of the one's
|
2115 |
|
|
* complement sum of all 16-bit words in the buffer.
|
2116 |
|
|
*
|
2117 |
|
|
* See RFC1071.
|
2118 |
|
|
*
|
2119 |
|
|
* \param buf A pointer to the buffer over which the checksum is to be
|
2120 |
|
|
* computed.
|
2121 |
|
|
*
|
2122 |
|
|
* \param len The length of the buffer over which the checksum is to
|
2123 |
|
|
* be computed.
|
2124 |
|
|
*
|
2125 |
|
|
* \return The Internet checksum of the buffer.
|
2126 |
|
|
*/
|
2127 |
|
|
u16_t uip_chksum( u16_t *buf, u16_t len );
|
2128 |
|
|
|
2129 |
|
|
/**
|
2130 |
|
|
* Calculate the IP header checksum of the packet header in uip_buf.
|
2131 |
|
|
*
|
2132 |
|
|
* The IP header checksum is the Internet checksum of the 20 bytes of
|
2133 |
|
|
* the IP header.
|
2134 |
|
|
*
|
2135 |
|
|
* \return The IP header checksum of the IP header in the uip_buf
|
2136 |
|
|
* buffer.
|
2137 |
|
|
*/
|
2138 |
|
|
u16_t uip_ipchksum( void );
|
2139 |
|
|
|
2140 |
|
|
/**
|
2141 |
|
|
* Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
|
2142 |
|
|
*
|
2143 |
|
|
* The TCP checksum is the Internet checksum of data contents of the
|
2144 |
|
|
* TCP segment, and a pseudo-header as defined in RFC793.
|
2145 |
|
|
*
|
2146 |
|
|
* \return The TCP checksum of the TCP segment in uip_buf and pointed
|
2147 |
|
|
* to by uip_appdata.
|
2148 |
|
|
*/
|
2149 |
|
|
u16_t uip_tcpchksum( void );
|
2150 |
|
|
|
2151 |
|
|
/**
|
2152 |
|
|
* Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
|
2153 |
|
|
*
|
2154 |
|
|
* The UDP checksum is the Internet checksum of data contents of the
|
2155 |
|
|
* UDP segment, and a pseudo-header as defined in RFC768.
|
2156 |
|
|
*
|
2157 |
|
|
* \return The UDP checksum of the UDP segment in uip_buf and pointed
|
2158 |
|
|
* to by uip_appdata.
|
2159 |
|
|
*/
|
2160 |
|
|
u16_t uip_udpchksum( void );
|
2161 |
|
|
|
2162 |
|
|
/**
|
2163 |
|
|
* Calculate the ICMP checksum of the packet in uip_buf.
|
2164 |
|
|
*
|
2165 |
|
|
* \return The ICMP checksum of the ICMP packet in uip_buf
|
2166 |
|
|
*/
|
2167 |
|
|
u16_t uip_icmp6chksum( void );
|
2168 |
|
|
#endif /* __UIP_H__ */
|
2169 |
|
|
|
2170 |
|
|
/** @} */
|