00001 00002 /** 00003 * \addtogroup uip 00004 * @{ 00005 */ 00006 00007 /** 00008 * \file 00009 * Header file for the uIP TCP/IP stack. 00010 * \author Adam Dunkels <adam@dunkels.com> 00011 * 00012 * The uIP TCP/IP stack header file contains definitions for a number 00013 * of C macros that are used by uIP programs as well as internal uIP 00014 * structures, TCP/IP header structures and function declarations. 00015 * 00016 */ 00017 00018 00019 /* 00020 * Copyright (c) 2001-2003, Adam Dunkels. 00021 * All rights reserved. 00022 * 00023 * Redistribution and use in source and binary forms, with or without 00024 * modification, are permitted provided that the following conditions 00025 * are met: 00026 * 1. Redistributions of source code must retain the above copyright 00027 * notice, this list of conditions and the following disclaimer. 00028 * 2. Redistributions in binary form must reproduce the above copyright 00029 * notice, this list of conditions and the following disclaimer in the 00030 * documentation and/or other materials provided with the distribution. 00031 * 3. The name of the author may not be used to endorse or promote 00032 * products derived from this software without specific prior 00033 * written permission. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00036 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00037 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00038 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00039 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00040 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00041 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00042 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00043 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00044 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00045 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00046 * 00047 * This file is part of the uIP TCP/IP stack. 00048 * 00049 * $Id: uip.h,v 1.13 2005/07/04 07:10:10 adam Exp $ 00050 * 00051 */ 00052 00053 #ifndef __UIP_H__ 00054 #define __UIP_H__ 00055 00056 #include "uipopt.h" 00057 00058 /** 00059 * Repressentation of an IP address. 00060 * 00061 */ 00062 typedef u16_t uip_ipaddr_t[2]; 00063 00064 /*-----------------------------------------------------------------------------------*/ 00065 /* First, the functions that should be called from the 00066 * system. Initialization, the periodic timer and incoming packets are 00067 * handled by the following three functions. 00068 */ 00069 00070 /** 00071 * \defgroup uipconffunc uIP configuration functions 00072 * @{ 00073 * 00074 * The uIP configuration functions are used for setting run-time 00075 * parameters in uIP such as IP addresses. 00076 */ 00077 00078 /** 00079 * Set the IP address of this host. 00080 * 00081 * The IP address is represented as a 4-byte array where the first 00082 * octet of the IP address is put in the first member of the 4-byte 00083 * array. 00084 * 00085 * Example: 00086 \code 00087 00088 uip_ipaddr_t addr; 00089 00090 uip_ipaddr(&addr, 192,168,1,2); 00091 uip_sethostaddr(&addr); 00092 00093 \endcode 00094 * \param addr A pointer to an IP address of type uip_ipaddr_t; 00095 * 00096 * \sa uip_ipaddr() 00097 * 00098 * \hideinitializer 00099 */ 00100 #define uip_sethostaddr(addr) do { uip_hostaddr[0] = ((u16_t *)(addr))[0]; \ 00101 uip_hostaddr[1] = ((u16_t *)(addr))[1]; } while(0) 00102 00103 /** 00104 * Get the IP address of this host. 00105 * 00106 * The IP address is represented as a 4-byte array where the first 00107 * octet of the IP address is put in the first member of the 4-byte 00108 * array. 00109 * 00110 * Example: 00111 \code 00112 uip_ipaddr_t hostaddr; 00113 00114 uip_gethostaddr(&hostaddr); 00115 \endcode 00116 * \param addr A pointer to a uip_ipaddr_t variable that will be 00117 * filled in with the currently configured IP address. 00118 * 00119 * \hideinitializer 00120 */ 00121 #define uip_gethostaddr(addr) do { ((u16_t *)(addr))[0] = uip_hostaddr[0]; \ 00122 ((u16_t *)(addr))[1] = uip_hostaddr[1]; } while(0) 00123 00124 /** 00125 * Set the default router's IP address. 00126 * 00127 * \param addr A pointer to a uip_ipaddr_t variable containing the IP 00128 * address of the default router. 00129 * 00130 * \sa uip_ipaddr() 00131 * 00132 * \hideinitializer 00133 */ 00134 #define uip_setdraddr(addr) do { uip_draddr[0] = ((u16_t *)(addr))[0]; \ 00135 uip_draddr[1] = ((u16_t *)(addr))[1]; } while(0) 00136 00137 /** 00138 * Set the netmask. 00139 * 00140 * \param addr A pointer to a uip_ipaddr_t variable containing the IP 00141 * address of the netmask. 00142 * 00143 * \sa uip_ipaddr() 00144 * 00145 * \hideinitializer 00146 */ 00147 #define uip_setnetmask(addr) do { uip_netmask[0] = ((u16_t *)(addr))[0]; \ 00148 uip_netmask[1] = ((u16_t *)(addr))[1]; } while(0) 00149 00150 00151 /** 00152 * Get the default router's IP address. 00153 * 00154 * \param addr A pointer to a uip_ipaddr_t variable that will be 00155 * filled in with the IP address of the default router. 00156 * 00157 * \hideinitializer 00158 */ 00159 #define uip_getdraddr(addr) do { ((u16_t *)(addr))[0] = uip_draddr[0]; \ 00160 ((u16_t *)(addr))[1] = uip_draddr[1]; } while(0) 00161 00162 /** 00163 * Get the netmask. 00164 * 00165 * \param addr A pointer to a uip_ipaddr_t variable that will be 00166 * filled in with the value of the netmask. 00167 * 00168 * \hideinitializer 00169 */ 00170 #define uip_getnetmask(addr) do { ((u16_t *)(addr))[0] = uip_netmask[0]; \ 00171 ((u16_t *)(addr))[1] = uip_netmask[1]; } while(0) 00172 00173 /** @} */ 00174 00175 /** 00176 * \defgroup uipinit uIP initialization functions 00177 * @{ 00178 * 00179 * The uIP initialization functions are used for booting uIP. 00180 */ 00181 00182 /** 00183 * uIP initialization function. 00184 * 00185 * This function should be called at boot up to initilize the uIP 00186 * TCP/IP stack. 00187 */ 00188 void uip_init(void); 00189 00190 /** @} */ 00191 00192 /** 00193 * \defgroup uipdevfunc uIP device driver functions 00194 * @{ 00195 * 00196 * These functions are used by a network device driver for interacting 00197 * with uIP. 00198 */ 00199 00200 /** 00201 * Process an incoming packet. 00202 * 00203 * This function should be called when the device driver has received 00204 * a packet from the network. The packet from the device driver must 00205 * be present in the uip_buf buffer, and the length of the packet 00206 * should be placed in the uip_len variable. 00207 * 00208 * When the function returns, there may be an outbound packet placed 00209 * in the uip_buf packet buffer. If so, the uip_len variable is set to 00210 * the length of the packet. If no packet is to be sent out, the 00211 * uip_len variable is set to 0. 00212 * 00213 * The usual way of calling the function is presented by the source 00214 * code below. 00215 \code 00216 uip_len = devicedriver_poll(); 00217 if(uip_len > 0) { 00218 uip_input(); 00219 if(uip_len > 0) { 00220 devicedriver_send(); 00221 } 00222 } 00223 \endcode 00224 * 00225 * \note If you are writing a uIP device driver that needs ARP 00226 * (Address Resolution Protocol), e.g., when running uIP over 00227 * Ethernet, you will need to call the uIP ARP code before calling 00228 * this function: 00229 \code 00230 #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) 00231 uip_len = ethernet_devicedrver_poll(); 00232 if(uip_len > 0) { 00233 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { 00234 uip_arp_ipin(); 00235 uip_input(); 00236 if(uip_len > 0) { 00237 uip_arp_out(); 00238 ethernet_devicedriver_send(); 00239 } 00240 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { 00241 uip_arp_arpin(); 00242 if(uip_len > 0) { 00243 ethernet_devicedriver_send(); 00244 } 00245 } 00246 \endcode 00247 * 00248 * \hideinitializer 00249 */ 00250 #define uip_input() uip_process(UIP_DATA) 00251 00252 /** 00253 * Periodic processing for a connection identified by its number. 00254 * 00255 * This function does the necessary periodic processing (timers, 00256 * polling) for a uIP TCP conneciton, and should be called when the 00257 * periodic uIP timer goes off. It should be called for every 00258 * connection, regardless of whether they are open of closed. 00259 * 00260 * When the function returns, it may have an outbound packet waiting 00261 * for service in the uIP packet buffer, and if so the uip_len 00262 * variable is set to a value larger than zero. The device driver 00263 * should be called to send out the packet. 00264 * 00265 * The ususal way of calling the function is through a for() loop like 00266 * this: 00267 \code 00268 for(i = 0; i < UIP_CONNS; ++i) { 00269 uip_periodic(i); 00270 if(uip_len > 0) { 00271 devicedriver_send(); 00272 } 00273 } 00274 \endcode 00275 * 00276 * \note If you are writing a uIP device driver that needs ARP 00277 * (Address Resolution Protocol), e.g., when running uIP over 00278 * Ethernet, you will need to call the uip_arp_out() function before 00279 * calling the device driver: 00280 \code 00281 for(i = 0; i < UIP_CONNS; ++i) { 00282 uip_periodic(i); 00283 if(uip_len > 0) { 00284 uip_arp_out(); 00285 ethernet_devicedriver_send(); 00286 } 00287 } 00288 \endcode 00289 * 00290 * \param conn The number of the connection which is to be periodically polled. 00291 * 00292 * \hideinitializer 00293 */ 00294 #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \ 00295 uip_process(UIP_TIMER); } while (0) 00296 00297 /** 00298 * 00299 * 00300 */ 00301 #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED) 00302 00303 /** 00304 * Perform periodic processing for a connection identified by a pointer 00305 * to its structure. 00306 * 00307 * Same as uip_periodic() but takes a pointer to the actual uip_conn 00308 * struct instead of an integer as its argument. This function can be 00309 * used to force periodic processing of a specific connection. 00310 * 00311 * \param conn A pointer to the uip_conn struct for the connection to 00312 * be processed. 00313 * 00314 * \hideinitializer 00315 */ 00316 #define uip_periodic_conn(conn) do { uip_conn = conn; \ 00317 uip_process(UIP_TIMER); } while (0) 00318 00319 /** 00320 * Reuqest that a particular connection should be polled. 00321 * 00322 * Similar to uip_periodic_conn() but does not perform any timer 00323 * processing. The application is polled for new data. 00324 * 00325 * \param conn A pointer to the uip_conn struct for the connection to 00326 * be processed. 00327 * 00328 * \hideinitializer 00329 */ 00330 #define uip_poll_conn(conn) do { uip_conn = conn; \ 00331 uip_process(UIP_POLL_REQUEST); } while (0) 00332 00333 00334 #if UIP_UDP 00335 /** 00336 * Periodic processing for a UDP connection identified by its number. 00337 * 00338 * This function is essentially the same as uip_periodic(), but for 00339 * UDP connections. It is called in a similar fashion as the 00340 * uip_periodic() function: 00341 \code 00342 for(i = 0; i < UIP_UDP_CONNS; i++) { 00343 uip_udp_periodic(i); 00344 if(uip_len > 0) { 00345 devicedriver_send(); 00346 } 00347 } 00348 \endcode 00349 * 00350 * \note As for the uip_periodic() function, special care has to be 00351 * taken when using uIP together with ARP and Ethernet: 00352 \code 00353 for(i = 0; i < UIP_UDP_CONNS; i++) { 00354 uip_udp_periodic(i); 00355 if(uip_len > 0) { 00356 uip_arp_out(); 00357 ethernet_devicedriver_send(); 00358 } 00359 } 00360 \endcode 00361 * 00362 * \param conn The number of the UDP connection to be processed. 00363 * 00364 * \hideinitializer 00365 */ 00366 #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ 00367 uip_process(UIP_UDP_TIMER); } while (0) 00368 00369 /** 00370 * Periodic processing for a UDP connection identified by a pointer to 00371 * its structure. 00372 * 00373 * Same as uip_udp_periodic() but takes a pointer to the actual 00374 * uip_conn struct instead of an integer as its argument. This 00375 * function can be used to force periodic processing of a specific 00376 * connection. 00377 * 00378 * \param conn A pointer to the uip_udp_conn struct for the connection 00379 * to be processed. 00380 * 00381 * \hideinitializer 00382 */ 00383 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ 00384 uip_process(UIP_UDP_TIMER); } while (0) 00385 00386 00387 #endif /* UIP_UDP */ 00388 00389 /** 00390 * The uIP packet buffer. 00391 * 00392 * The uip_buf array is used to hold incoming and outgoing 00393 * packets. The device driver should place incoming data into this 00394 * buffer. When sending data, the device driver should read the link 00395 * level headers and the TCP/IP headers from this buffer. The size of 00396 * the link level headers is configured by the UIP_LLH_LEN define. 00397 * 00398 * \note The application data need not be placed in this buffer, so 00399 * the device driver must read it from the place pointed to by the 00400 * uip_appdata pointer as illustrated by the following example: 00401 \code 00402 void 00403 devicedriver_send(void) 00404 { 00405 hwsend(&uip_buf[0], UIP_LLH_LEN); 00406 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) { 00407 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN); 00408 } else { 00409 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN); 00410 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN); 00411 } 00412 } 00413 \endcode 00414 */ 00415 extern u8_t uip_buf[UIP_BUFSIZE+2]; 00416 00417 /** @} */ 00418 00419 /*-----------------------------------------------------------------------------------*/ 00420 /* Functions that are used by the uIP application program. Opening and 00421 * closing connections, sending and receiving data, etc. is all 00422 * handled by the functions below. 00423 */ 00424 /** 00425 * \defgroup uipappfunc uIP application functions 00426 * @{ 00427 * 00428 * Functions used by an application running of top of uIP. 00429 */ 00430 00431 /** 00432 * Start listening to the specified port. 00433 * 00434 * \note Since this function expects the port number in network byte 00435 * order, a conversion using HTONS() or htons() is necessary. 00436 * 00437 \code 00438 uip_listen(HTONS(80)); 00439 \endcode 00440 * 00441 * \param port A 16-bit port number in network byte order. 00442 */ 00443 void uip_listen(u16_t port); 00444 00445 /** 00446 * Stop listening to the specified port. 00447 * 00448 * \note Since this function expects the port number in network byte 00449 * order, a conversion using HTONS() or htons() is necessary. 00450 * 00451 \code 00452 uip_unlisten(HTONS(80)); 00453 \endcode 00454 * 00455 * \param port A 16-bit port number in network byte order. 00456 */ 00457 void uip_unlisten(u16_t port); 00458 00459 /** 00460 * Connect to a remote host using TCP. 00461 * 00462 * This function is used to start a new connection to the specified 00463 * port on the specied host. It allocates a new connection identifier, 00464 * sets the connection to the SYN_SENT state and sets the 00465 * retransmission timer to 0. This will cause a TCP SYN segment to be 00466 * sent out the next time this connection is periodically processed, 00467 * which usually is done within 0.5 seconds after the call to 00468 * uip_connect(). 00469 * 00470 * \note This function is avaliable only if support for active open 00471 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. 00472 * 00473 * \note Since this function requires the port number to be in network 00474 * byte order, a conversion using HTONS() or htons() is necessary. 00475 * 00476 \code 00477 uip_ipaddr_t ipaddr; 00478 00479 uip_ipaddr(&ipaddr, 192,168,1,2); 00480 uip_connect(&ipaddr, HTONS(80)); 00481 \endcode 00482 * 00483 * \param ripaddr The IP address of the remote hot. 00484 * 00485 * \param port A 16-bit port number in network byte order. 00486 * 00487 * \return A pointer to the uIP connection identifier for the new connection, 00488 * or NULL if no connection could be allocated. 00489 * 00490 */ 00491 struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port); 00492 00493 00494 00495 /** 00496 * \internal 00497 * 00498 * Check if a connection has outstanding (i.e., unacknowledged) data. 00499 * 00500 * \param conn A pointer to the uip_conn structure for the connection. 00501 * 00502 * \hideinitializer 00503 */ 00504 #define uip_outstanding(conn) ((conn)->len) 00505 00506 /** 00507 * Send data on the current connection. 00508 * 00509 * This function is used to send out a single segment of TCP 00510 * data. Only applications that have been invoked by uIP for event 00511 * processing can send data. 00512 * 00513 * The amount of data that actually is sent out after a call to this 00514 * funcion is determined by the maximum amount of data TCP allows. uIP 00515 * will automatically crop the data so that only the appropriate 00516 * amount of data is sent. The function uip_mss() can be used to query 00517 * uIP for the amount of data that actually will be sent. 00518 * 00519 * \note This function does not guarantee that the sent data will 00520 * arrive at the destination. If the data is lost in the network, the 00521 * application will be invoked with the uip_rexmit() event being 00522 * set. The application will then have to resend the data using this 00523 * function. 00524 * 00525 * \param data A pointer to the data which is to be sent. 00526 * 00527 * \param len The maximum amount of data bytes to be sent. 00528 * 00529 * \hideinitializer 00530 */ 00531 void uip_send(const char *data, int len); 00532 /*#define uip_send(data, len) do { uip_sappdata = (void *)(data); uip_slen = (len);} while(0) */ 00533 00534 /** 00535 * The length of any incoming data that is currently avaliable (if avaliable) 00536 * in the uip_appdata buffer. 00537 * 00538 * The test function uip_data() must first be used to check if there 00539 * is any data available at all. 00540 * 00541 * \hideinitializer 00542 */ 00543 #define uip_datalen() uip_len 00544 00545 /** 00546 * The length of any out-of-band data (urgent data) that has arrived 00547 * on the connection. 00548 * 00549 * \note The configuration parameter UIP_URGDATA must be set for this 00550 * function to be enabled. 00551 * 00552 * \hideinitializer 00553 */ 00554 #define uip_urgdatalen() uip_urglen 00555 00556 /** 00557 * Close the current connection. 00558 * 00559 * This function will close the current connection in a nice way. 00560 * 00561 * \hideinitializer 00562 */ 00563 #define uip_close() (uip_flags = UIP_CLOSE) 00564 00565 /** 00566 * Abort the current connection. 00567 * 00568 * This function will abort (reset) the current connection, and is 00569 * usually used when an error has occured that prevents using the 00570 * uip_close() function. 00571 * 00572 * \hideinitializer 00573 */ 00574 #define uip_abort() (uip_flags = UIP_ABORT) 00575 00576 /** 00577 * Tell the sending host to stop sending data. 00578 * 00579 * This function will close our receiver's window so that we stop 00580 * receiving data for the current connection. 00581 * 00582 * \hideinitializer 00583 */ 00584 #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) 00585 00586 /** 00587 * Find out if the current connection has been previously stopped with 00588 * uip_stop(). 00589 * 00590 * \hideinitializer 00591 */ 00592 #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) 00593 00594 /** 00595 * Restart the current connection, if is has previously been stopped 00596 * with uip_stop(). 00597 * 00598 * This function will open the receiver's window again so that we 00599 * start receiving data for the current connection. 00600 * 00601 * \hideinitializer 00602 */ 00603 #define uip_restart() do { uip_flags |= UIP_NEWDATA; \ 00604 uip_conn->tcpstateflags &= ~UIP_STOPPED; \ 00605 } while(0) 00606 00607 00608 /* uIP tests that can be made to determine in what state the current 00609 connection is, and what the application function should do. */ 00610 00611 /** 00612 * Is the current connection a UDP connection? 00613 * 00614 * This function checks whether the current connection is a UDP connection. 00615 * 00616 * \hideinitializer 00617 * 00618 */ 00619 #define uip_udpconnection() (uip_conn == NULL) 00620 00621 /** 00622 * Is new incoming data available? 00623 * 00624 * Will reduce to non-zero if there is new data for the application 00625 * present at the uip_appdata pointer. The size of the data is 00626 * avaliable through the uip_len variable. 00627 * 00628 * \hideinitializer 00629 */ 00630 #define uip_newdata() (uip_flags & UIP_NEWDATA) 00631 00632 /** 00633 * Has previously sent data been acknowledged? 00634 * 00635 * Will reduce to non-zero if the previously sent data has been 00636 * acknowledged by the remote host. This means that the application 00637 * can send new data. 00638 * 00639 * \hideinitializer 00640 */ 00641 #define uip_acked() (uip_flags & UIP_ACKDATA) 00642 00643 /** 00644 * Has the connection just been connected? 00645 * 00646 * Reduces to non-zero if the current connection has been connected to 00647 * a remote host. This will happen both if the connection has been 00648 * actively opened (with uip_connect()) or passively opened (with 00649 * uip_listen()). 00650 * 00651 * \hideinitializer 00652 */ 00653 #define uip_connected() (uip_flags & UIP_CONNECTED) 00654 00655 /** 00656 * Has the connection been closed by the other end? 00657 * 00658 * Is non-zero if the connection has been closed by the remote 00659 * host. The application may then do the necessary clean-ups. 00660 * 00661 * \hideinitializer 00662 */ 00663 #define uip_closed() (uip_flags & UIP_CLOSE) 00664 00665 /** 00666 * Has the connection been aborted by the other end? 00667 * 00668 * Non-zero if the current connection has been aborted (reset) by the 00669 * remote host. 00670 * 00671 * \hideinitializer 00672 */ 00673 #define uip_aborted() (uip_flags & UIP_ABORT) 00674 00675 /** 00676 * Has the connection timed out? 00677 * 00678 * Non-zero if the current connection has been aborted due to too many 00679 * retransmissions. 00680 * 00681 * \hideinitializer 00682 */ 00683 #define uip_timedout() (uip_flags & UIP_TIMEDOUT) 00684 00685 /** 00686 * Do we need to retransmit previously data? 00687 * 00688 * Reduces to non-zero if the previously sent data has been lost in 00689 * the network, and the application should retransmit it. The 00690 * application should send the exact same data as it did the last 00691 * time, using the uip_send() function. 00692 * 00693 * \hideinitializer 00694 */ 00695 #define uip_rexmit() (uip_flags & UIP_REXMIT) 00696 00697 /** 00698 * Is the connection being polled by uIP? 00699 * 00700 * Is non-zero if the reason the application is invoked is that the 00701 * current connection has been idle for a while and should be 00702 * polled. 00703 * 00704 * The polling event can be used for sending data without having to 00705 * wait for the remote host to send data. 00706 * 00707 * \hideinitializer 00708 */ 00709 #define uip_poll() (uip_flags & UIP_POLL) 00710 00711 /** 00712 * Get the initial maxium segment size (MSS) of the current 00713 * connection. 00714 * 00715 * \hideinitializer 00716 */ 00717 #define uip_initialmss() (uip_conn->initialmss) 00718 00719 /** 00720 * Get the current maxium segment size that can be sent on the current 00721 * connection. 00722 * 00723 * The current maxiumum segment size that can be sent on the 00724 * connection is computed from the receiver's window and the MSS of 00725 * the connection (which also is available by calling 00726 * uip_initialmss()). 00727 * 00728 * \hideinitializer 00729 */ 00730 #define uip_mss() (uip_conn->mss) 00731 00732 /** 00733 * Set up a new UDP connection. 00734 * 00735 * This function sets up a new UDP connection. The function will 00736 * automatically allocate an unused local port for the new 00737 * connection. However, another port can be chosen by using the 00738 * uip_udp_bind() call, after the uip_udp_new() function has been 00739 * called. 00740 * 00741 * Example: 00742 \code 00743 uip_ipaddr_t addr; 00744 struct uip_udp_conn *c; 00745 00746 uip_ipaddr(&addr, 192,168,2,1); 00747 c = uip_udp_new(&addr, HTONS(12345)); 00748 if(c != NULL) { 00749 uip_udp_bind(c, HTONS(12344)); 00750 } 00751 \endcode 00752 * \param ripaddr The IP address of the remote host. 00753 * 00754 * \param rport The remote port number in network byte order. 00755 * 00756 * \return The uip_udp_conn structure for the new connection or NULL 00757 * if no connection could be allocated. 00758 */ 00759 struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport); 00760 00761 /** 00762 * Removed a UDP connection. 00763 * 00764 * \param conn A pointer to the uip_udp_conn structure for the connection. 00765 * 00766 * \hideinitializer 00767 */ 00768 #define uip_udp_remove(conn) (conn)->lport = 0 00769 00770 /** 00771 * Bind a UDP connection to a local port. 00772 * 00773 * \param conn A pointer to the uip_udp_conn structure for the 00774 * connection. 00775 * 00776 * \param port The local port number, in network byte order. 00777 * 00778 * \hideinitializer 00779 */ 00780 #define uip_udp_bind(conn, port) (conn)->lport = port 00781 00782 /** 00783 * Send a UDP datagram of length len on the current connection. 00784 * 00785 * This function can only be called in response to a UDP event (poll 00786 * or newdata). The data must be present in the uip_buf buffer, at the 00787 * place pointed to by the uip_appdata pointer. 00788 * 00789 * \param len The length of the data in the uip_buf buffer. 00790 * 00791 * \hideinitializer 00792 */ 00793 #define uip_udp_send(len) uip_send((char *)uip_appdata, len) 00794 /*#define uip_udp_send(len) uip_slen = (len)*/ 00795 00796 /** 00797 * Construct an UDP datagram in the uip_buf buffer. 00798 * 00799 * This function constructs an UDP datagram in the uip_buf 00800 * buffer. This function should NOT be called from an uIP application 00801 * callback, but only from outside of uIP. In general, the function 00802 * uip_udp_send() should be used instead. 00803 * 00804 * \note Do not use this function unless you know what you are doing 00805 * 00806 * The data that is to be sent must be present in the uip_buf buffer 00807 * before this function is called. The data should be placed at the 00808 * offset UIP_LLH_LEN + UIP_IPUDPH_LEN. 00809 * 00810 * Typical usage of this function is to first call this function to 00811 * construct a UDP datagram in the uip_buf buffer, and then calling 00812 * the network device driver to send the data over the network. 00813 * 00814 * Example: 00815 \code 00816 struct uip_udp_conn *conn; 00817 00818 memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], "hello", 5); 00819 uip_udp_send_conn(5, conn); 00820 devicedriver_send(); 00821 \endcode 00822 * 00823 * \param len The length of the datagram to be sent. 00824 * \param conn A pointer to the UDP connection on which the datagram 00825 * to be sent. 00826 * 00827 * \hideinitializer 00828 */ 00829 #define uip_udp_send_conn(len, conn) \ 00830 do { \ 00831 uip_slen = (len); \ 00832 uip_udp_conn = (conn); \ 00833 uip_process(UIP_UDP_SEND_CONN); \ 00834 } while(0) 00835 00836 /** @} */ 00837 00838 /* uIP convenience and converting functions. */ 00839 00840 /** 00841 * \defgroup uipconvfunc uIP conversion functions 00842 * @{ 00843 * 00844 * These functions can be used for converting between different data 00845 * formats used by uIP. 00846 */ 00847 00848 /** 00849 * Construct an IP address from four bytes. 00850 * 00851 * This function constructs an IP address of the type that uIP handles 00852 * internally from four bytes. The function is handy for specifying IP 00853 * addresses to use with e.g. the uip_connect() function. 00854 * 00855 * Example: 00856 \code 00857 uip_ipaddr_t ipaddr; 00858 struct uip_conn *c; 00859 00860 uip_ipaddr(&ipaddr, 192,168,1,2); 00861 c = uip_connect(&ipaddr, HTONS(80)); 00862 \endcode 00863 * 00864 * \param addr A pointer to a uip_ipaddr_t variable that will be 00865 * filled in with the IP address. 00866 * 00867 * \param addr0 The first octet of the IP address. 00868 * \param addr1 The second octet of the IP address. 00869 * \param addr2 The third octet of the IP address. 00870 * \param addr3 The forth octet of the IP address. 00871 * 00872 * \hideinitializer 00873 */ 00874 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ 00875 ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ 00876 ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ 00877 } while(0) 00878 00879 /** 00880 * Copy an IP address to another IP address. 00881 * 00882 * Copies an IP address from one place to another. 00883 * 00884 * Example: 00885 \code 00886 uip_ipaddr_t ipaddr1, ipaddr2; 00887 00888 uip_ipaddr(&ipaddr1, 192,16,1,2); 00889 uip_ipaddr_copy(&ipaddr2, &ipaddr1); 00890 \endcode 00891 * 00892 * \param dest The destination for the copy. 00893 * \param src The source from where to copy. 00894 * 00895 * \hideinitializer 00896 */ 00897 #define uip_ipaddr_copy(dest, src) do { \ 00898 ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \ 00899 ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \ 00900 } while(0) 00901 /** 00902 * Compare two IP addresses 00903 * 00904 * Compares two IP addresses. 00905 * 00906 * Example: 00907 \code 00908 uip_ipaddr_t ipaddr1, ipaddr2; 00909 00910 uip_ipaddr(&ipaddr1, 192,16,1,2); 00911 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) { 00912 printf("They are the same"); 00913 } 00914 \endcode 00915 * 00916 * \param addr1 The first IP address. 00917 * \param addr2 The second IP address. 00918 * 00919 * \hideinitializer 00920 */ 00921 #define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \ 00922 ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1]) 00923 00924 /** 00925 * Compare two IP addresses with netmasks 00926 * 00927 * Compares two IP addresses with netmasks. The masks are used to mask 00928 * out the bits that are to be compared. 00929 * 00930 * Example: 00931 \code 00932 uip_ipaddr_t ipaddr1, ipaddr2, mask; 00933 00934 uip_ipaddr(&mask, 255,255,255,0); 00935 uip_ipaddr(&ipaddr1, 192,16,1,2); 00936 uip_ipaddr(&ipaddr2, 192,16,1,3); 00937 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) { 00938 printf("They are the same"); 00939 } 00940 \endcode 00941 * 00942 * \param addr1 The first IP address. 00943 * \param addr2 The second IP address. 00944 * \param mask The netmask. 00945 * 00946 * \hideinitializer 00947 */ 00948 #define uip_ipaddr_maskcmp(addr1, addr2, mask) \ 00949 (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \ 00950 (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \ 00951 ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \ 00952 (((u16_t *)addr2)[1] & ((u16_t *)mask)[1]))) 00953 00954 00955 /** 00956 * Mask out the network part of an IP address. 00957 * 00958 * Masks out the network part of an IP address, given the address and 00959 * the netmask. 00960 * 00961 * Example: 00962 \code 00963 uip_ipaddr_t ipaddr1, ipaddr2, netmask; 00964 00965 uip_ipaddr(&ipaddr1, 192,16,1,2); 00966 uip_ipaddr(&netmask, 255,255,255,0); 00967 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask); 00968 \endcode 00969 * 00970 * In the example above, the variable "ipaddr2" will contain the IP 00971 * address 192.168.1.0. 00972 * 00973 * \param dest Where the result is to be placed. 00974 * \param src The IP address. 00975 * \param mask The netmask. 00976 * 00977 * \hideinitializer 00978 */ 00979 #define uip_ipaddr_mask(dest, src, mask) do { \ 00980 ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \ 00981 ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \ 00982 } while(0) 00983 00984 /** 00985 * Pick the first octet of an IP address. 00986 * 00987 * Picks out the first octet of an IP address. 00988 * 00989 * Example: 00990 \code 00991 uip_ipaddr_t ipaddr; 00992 u8_t octet; 00993 00994 uip_ipaddr(&ipaddr, 1,2,3,4); 00995 octet = uip_ipaddr1(&ipaddr); 00996 \endcode 00997 * 00998 * In the example above, the variable "octet" will contain the value 1. 00999 * 01000 * \hideinitializer 01001 */ 01002 #define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8) 01003 01004 /** 01005 * Pick the second octet of an IP address. 01006 * 01007 * Picks out the second octet of an IP address. 01008 * 01009 * Example: 01010 \code 01011 uip_ipaddr_t ipaddr; 01012 u8_t octet; 01013 01014 uip_ipaddr(&ipaddr, 1,2,3,4); 01015 octet = uip_ipaddr2(&ipaddr); 01016 \endcode 01017 * 01018 * In the example above, the variable "octet" will contain the value 2. 01019 * 01020 * \hideinitializer 01021 */ 01022 #define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff) 01023 01024 /** 01025 * Pick the third octet of an IP address. 01026 * 01027 * Picks out the third octet of an IP address. 01028 * 01029 * Example: 01030 \code 01031 uip_ipaddr_t ipaddr; 01032 u8_t octet; 01033 01034 uip_ipaddr(&ipaddr, 1,2,3,4); 01035 octet = uip_ipaddr3(&ipaddr); 01036 \endcode 01037 * 01038 * In the example above, the variable "octet" will contain the value 3. 01039 * 01040 * \hideinitializer 01041 */ 01042 #define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8) 01043 01044 /** 01045 * Pick the fourth octet of an IP address. 01046 * 01047 * Picks out the fourth octet of an IP address. 01048 * 01049 * Example: 01050 \code 01051 uip_ipaddr_t ipaddr; 01052 u8_t octet; 01053 01054 uip_ipaddr(&ipaddr, 1,2,3,4); 01055 octet = uip_ipaddr4(&ipaddr); 01056 \endcode 01057 * 01058 * In the example above, the variable "octet" will contain the value 4. 01059 * 01060 * \hideinitializer 01061 */ 01062 #define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff) 01063 01064 /** 01065 * Convert 16-bit quantity from host byte order to network byte order. 01066 * 01067 * This macro is primarily used for converting constants from host 01068 * byte order to network byte order. For converting variables to 01069 * network byte order, use the htons() function instead. 01070 * 01071 * \hideinitializer 01072 */ 01073 #ifndef HTONS 01074 # if UIP_BYTE_ORDER == UIP_BIG_ENDIAN 01075 # define HTONS(n) (n) 01076 # else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ 01077 # define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8)) 01078 # endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ 01079 #endif /* HTONS */ 01080 01081 /** 01082 * Convert 16-bit quantity from host byte order to network byte order. 01083 * 01084 * This function is primarily used for converting variables from host 01085 * byte order to network byte order. For converting constants to 01086 * network byte order, use the HTONS() macro instead. 01087 */ 01088 #ifndef htons 01089 u16_t htons(u16_t val); 01090 #endif /* htons */ 01091 01092 /** @} */ 01093 01094 /** 01095 * Pointer to the application data in the packet buffer. 01096 * 01097 * This pointer points to the application data when the application is 01098 * called. If the application wishes to send data, the application may 01099 * use this space to write the data into before calling uip_send(). 01100 */ 01101 extern u8_t *uip_appdata; 01102 extern u8_t *uip_sappdata; 01103 01104 #if UIP_URGDATA > 0 01105 /* u8_t *uip_urgdata: 01106 * 01107 * This pointer points to any urgent data that has been received. Only 01108 * present if compiled with support for urgent data (UIP_URGDATA). 01109 */ 01110 extern u8_t *uip_urgdata; 01111 #endif /* UIP_URGDATA > 0 */ 01112 01113 01114 /* u[8|16]_t uip_len: 01115 * 01116 * When the application is called, uip_len contains the length of any 01117 * new data that has been received from the remote host. The 01118 * application should set this variable to the size of any data that 01119 * the application wishes to send. When the network device driver 01120 * output function is called, uip_len should contain the length of the 01121 * outgoing packet. 01122 */ 01123 extern u16_t uip_len, uip_slen; 01124 01125 #if UIP_URGDATA > 0 01126 extern u8_t uip_urglen, uip_surglen; 01127 #endif /* UIP_URGDATA > 0 */ 01128 01129 01130 /** 01131 * Representation of a uIP TCP connection. 01132 * 01133 * The uip_conn structure is used for identifying a connection. All 01134 * but one field in the structure are to be considered read-only by an 01135 * application. The only exception is the appstate field whos purpose 01136 * is to let the application store application-specific state (e.g., 01137 * file pointers) for the connection. The size of this field is 01138 * configured in the "uipopt.h" header file. 01139 */ 01140 struct uip_conn { 01141 uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */ 01142 01143 u16_t lport; /**< The local TCP port, in network byte order. */ 01144 u16_t rport; /**< The local remote TCP port, in network byte 01145 order. */ 01146 01147 u8_t rcv_nxt[4]; /**< The sequence number that we expect to 01148 receive next. */ 01149 u8_t snd_nxt[4]; /**< The sequence number that was last sent by 01150 us. */ 01151 u16_t len; /**< Length of the data that was previously sent. */ 01152 u16_t mss; /**< Current maximum segment size for the 01153 connection. */ 01154 u16_t initialmss; /**< Initial maximum segment size for the 01155 connection. */ 01156 u8_t sa; /**< Retransmission time-out calculation state 01157 variable. */ 01158 u8_t sv; /**< Retransmission time-out calculation state 01159 variable. */ 01160 u8_t rto; /**< Retransmission time-out. */ 01161 u8_t tcpstateflags; /**< TCP state and flags. */ 01162 u8_t timer; /**< The retransmission timer. */ 01163 u8_t nrtx; /**< The number of retransmissions for the last 01164 segment sent. */ 01165 01166 /** The application state. */ 01167 u8_t appstate[UIP_APPSTATE_SIZE]; 01168 }; 01169 01170 01171 /* Pointer to the current connection. */ 01172 extern struct uip_conn *uip_conn; 01173 /* The array containing all uIP connections. */ 01174 extern struct uip_conn uip_conns[UIP_CONNS]; 01175 /** 01176 * \addtogroup uiparch 01177 * @{ 01178 */ 01179 01180 /** 01181 * 4-byte array used for the 32-bit sequence number calculations. 01182 */ 01183 extern u8_t uip_acc32[4]; 01184 01185 /** @} */ 01186 01187 01188 #if UIP_UDP 01189 /** 01190 * Representation of a uIP UDP connection. 01191 */ 01192 struct uip_udp_conn { 01193 uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */ 01194 u16_t lport; /**< The local port number in network byte order. */ 01195 u16_t rport; /**< The remote port number in network byte order. */ 01196 01197 /** The application state. */ 01198 u8_t appstate[UIP_APPSTATE_SIZE]; 01199 }; 01200 01201 extern struct uip_udp_conn *uip_udp_conn; 01202 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; 01203 #endif /* UIP_UDP */ 01204 01205 /** 01206 * The structure holding the TCP/IP statistics that are gathered if 01207 * UIP_STATISTICS is set to 1. 01208 * 01209 */ 01210 struct uip_stats { 01211 struct { 01212 uip_stats_t drop; /**< Number of dropped packets at the IP 01213 layer. */ 01214 uip_stats_t recv; /**< Number of received packets at the IP 01215 layer. */ 01216 uip_stats_t sent; /**< Number of sent packets at the IP 01217 layer. */ 01218 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong 01219 IP version or header length. */ 01220 uip_stats_t hblenerr; /**< Number of packets dropped due to wrong 01221 IP length, high byte. */ 01222 uip_stats_t lblenerr; /**< Number of packets dropped due to wrong 01223 IP length, low byte. */ 01224 uip_stats_t fragerr; /**< Number of packets dropped since they 01225 were IP fragments. */ 01226 uip_stats_t chkerr; /**< Number of packets dropped due to IP 01227 checksum errors. */ 01228 uip_stats_t protoerr; /**< Number of packets dropped since they 01229 were neither ICMP, UDP nor TCP. */ 01230 } ip; /**< IP statistics. */ 01231 struct { 01232 uip_stats_t drop; /**< Number of dropped ICMP packets. */ 01233 uip_stats_t recv; /**< Number of received ICMP packets. */ 01234 uip_stats_t sent; /**< Number of sent ICMP packets. */ 01235 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong 01236 type. */ 01237 } icmp; /**< ICMP statistics. */ 01238 struct { 01239 uip_stats_t drop; /**< Number of dropped TCP segments. */ 01240 uip_stats_t recv; /**< Number of recived TCP segments. */ 01241 uip_stats_t sent; /**< Number of sent TCP segments. */ 01242 uip_stats_t chkerr; /**< Number of TCP segments with a bad 01243 checksum. */ 01244 uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK 01245 number. */ 01246 uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */ 01247 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ 01248 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few 01249 connections was avaliable. */ 01250 uip_stats_t synrst; /**< Number of SYNs for closed ports, 01251 triggering a RST. */ 01252 } tcp; /**< TCP statistics. */ 01253 }; 01254 01255 /** 01256 * The uIP TCP/IP statistics. 01257 * 01258 * This is the variable in which the uIP TCP/IP statistics are gathered. 01259 */ 01260 extern struct uip_stats uip_stat; 01261 01262 01263 /*-----------------------------------------------------------------------------------*/ 01264 /* All the stuff below this point is internal to uIP and should not be 01265 * used directly by an application or by a device driver. 01266 */ 01267 /*-----------------------------------------------------------------------------------*/ 01268 /* u8_t uip_flags: 01269 * 01270 * When the application is called, uip_flags will contain the flags 01271 * that are defined in this file. Please read below for more 01272 * infomation. 01273 */ 01274 extern u8_t uip_flags; 01275 01276 /* The following flags may be set in the global variable uip_flags 01277 before calling the application callback. The UIP_ACKDATA and 01278 UIP_NEWDATA flags may both be set at the same time, whereas the 01279 others are mutualy exclusive. Note that these flags should *NOT* be 01280 accessed directly, but through the uIP functions/macros. */ 01281 01282 #define UIP_ACKDATA 1 /* Signifies that the outstanding data was 01283 acked and the application should send 01284 out new data instead of retransmitting 01285 the last data. */ 01286 #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent 01287 us new data. */ 01288 #define UIP_REXMIT 4 /* Tells the application to retransmit the 01289 data that was last sent. */ 01290 #define UIP_POLL 8 /* Used for polling the application, to 01291 check if the application has data that 01292 it wants to send. */ 01293 #define UIP_CLOSE 16 /* The remote host has closed the 01294 connection, thus the connection has 01295 gone away. Or the application signals 01296 that it wants to close the 01297 connection. */ 01298 #define UIP_ABORT 32 /* The remote host has aborted the 01299 connection, thus the connection has 01300 gone away. Or the application signals 01301 that it wants to abort the 01302 connection. */ 01303 #define UIP_CONNECTED 64 /* We have got a connection from a remote 01304 host and have set up a new connection 01305 for it, or an active connection has 01306 been successfully established. */ 01307 01308 #define UIP_TIMEDOUT 128 /* The connection has been aborted due to 01309 too many retransmissions. */ 01310 01311 01312 /* uip_process(flag): 01313 * 01314 * The actual uIP function which does all the work. 01315 */ 01316 void uip_process(u8_t flag); 01317 01318 /* The following flags are passed as an argument to the uip_process() 01319 function. They are used to distinguish between the two cases where 01320 uip_process() is called. It can be called either because we have 01321 incoming data that should be processed, or because the periodic 01322 timer has fired. These values are never used directly, but only in 01323 the macrose defined in this file. */ 01324 01325 #define UIP_DATA 1 /* Tells uIP that there is incoming 01326 data in the uip_buf buffer. The 01327 length of the data is stored in the 01328 global variable uip_len. */ 01329 #define UIP_TIMER 2 /* Tells uIP that the periodic timer 01330 has fired. */ 01331 #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should 01332 be polled. */ 01333 #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram 01334 should be constructed in the 01335 uip_buf buffer. */ 01336 #if UIP_UDP 01337 #define UIP_UDP_TIMER 5 01338 #endif /* UIP_UDP */ 01339 01340 /* The TCP states used in the uip_conn->tcpstateflags. */ 01341 #define UIP_CLOSED 0 01342 #define UIP_SYN_RCVD 1 01343 #define UIP_SYN_SENT 2 01344 #define UIP_ESTABLISHED 3 01345 #define UIP_FIN_WAIT_1 4 01346 #define UIP_FIN_WAIT_2 5 01347 #define UIP_CLOSING 6 01348 #define UIP_TIME_WAIT 7 01349 #define UIP_LAST_ACK 8 01350 #define UIP_TS_MASK 15 01351 01352 #define UIP_STOPPED 16 01353 01354 #define UIP_TCPIP_HLEN 40 01355 01356 /** 01357 * The buffer size available for user data in the \ref uip_buf buffer. 01358 * 01359 * This macro holds the available size for user data in the \ref 01360 * uip_buf buffer. The macro is intended to be used for checking 01361 * bounds of available user data. 01362 * 01363 * Example: 01364 \code 01365 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i); 01366 \endcode 01367 * 01368 * \hideinitializer 01369 */ 01370 #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) 01371 01372 /* The TCP and IP headers. */ 01373 struct uip_tcpip_hdr { 01374 /* IP header. */ 01375 u8_t vhl, 01376 tos, 01377 len[2], 01378 ipid[2], 01379 ipoffset[2], 01380 ttl, 01381 proto; 01382 u16_t ipchksum; 01383 u16_t srcipaddr[2], 01384 destipaddr[2]; 01385 01386 /* TCP header. */ 01387 u16_t srcport, 01388 destport; 01389 u8_t seqno[4], 01390 ackno[4], 01391 tcpoffset, 01392 flags, 01393 wnd[2]; 01394 u16_t tcpchksum; 01395 u8_t urgp[2]; 01396 u8_t optdata[4]; 01397 }; 01398 01399 /* The ICMP and IP headers. */ 01400 struct uip_icmpip_hdr { 01401 /* IP header. */ 01402 u8_t vhl, 01403 tos, 01404 len[2], 01405 ipid[2], 01406 ipoffset[2], 01407 ttl, 01408 proto; 01409 u16_t ipchksum; 01410 u16_t srcipaddr[2], 01411 destipaddr[2]; 01412 /* ICMP (echo) header. */ 01413 u8_t type, icode; 01414 u16_t icmpchksum; 01415 u16_t id, seqno; 01416 }; 01417 01418 01419 /* The UDP and IP headers. */ 01420 struct uip_udpip_hdr { 01421 /* IP header. */ 01422 u8_t vhl, 01423 tos, 01424 len[2], 01425 ipid[2], 01426 ipoffset[2], 01427 ttl, 01428 proto; 01429 u16_t ipchksum; 01430 u16_t srcipaddr[2], 01431 destipaddr[2]; 01432 01433 /* UDP header. */ 01434 u16_t srcport, 01435 destport; 01436 u16_t udplen; 01437 u16_t udpchksum; 01438 }; 01439 01440 #define UIP_PROTO_ICMP 1 01441 #define UIP_PROTO_TCP 6 01442 #define UIP_PROTO_UDP 17 01443 01444 /* Header sizes. */ 01445 #define UIP_IPH_LEN 20 /* Size of IP header */ 01446 #define UIP_UDPH_LEN 8 /* Size of UDP header */ 01447 #define UIP_TCPH_LEN 20 /* Size of TCP header */ 01448 #define UIP_IPUDPH_LEN 28 /* Size of IP + UDP header */ 01449 #define UIP_IPTCPH_LEN 40 /* Size of IP + TCP header */ 01450 01451 01452 01453 #if UIP_FIXEDADDR 01454 extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; 01455 #else /* UIP_FIXEDADDR */ 01456 extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; 01457 #endif /* UIP_FIXEDADDR */ 01458 01459 01460 01461 /** 01462 * Representation of a 48-bit Ethernet address. 01463 */ 01464 struct uip_eth_addr { 01465 u8_t addr[6]; 01466 }; 01467 01468 /** 01469 * Calculate the Internet checksum over a buffer. 01470 * 01471 * The Internet checksum is the one's complement of the one's 01472 * complement sum of all 16-bit words in the buffer. 01473 * 01474 * See RFC1071. 01475 * 01476 * \param buf A pointer to the buffer over which the checksum is to be 01477 * computed. 01478 * 01479 * \param len The length of the buffer over which the checksum is to 01480 * be computed. 01481 * 01482 * \return The Internet checksum of the buffer. 01483 */ 01484 u16_t uip_chksum(u16_t *buf, u16_t len); 01485 01486 /** 01487 * Calculate the IP header checksum of the packet header in uip_buf. 01488 * 01489 * The IP header checksum is the Internet checksum of the 20 bytes of 01490 * the IP header. 01491 * 01492 * \return The IP header checksum of the IP header in the uip_buf 01493 * buffer. 01494 */ 01495 u16_t uip_ipchksum(void); 01496 01497 /** 01498 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata. 01499 * 01500 * The TCP checksum is the Internet checksum of data contents of the 01501 * TCP segment, and a pseudo-header as defined in RFC793. 01502 * 01503 * \return The TCP checksum of the TCP segment in uip_buf and pointed 01504 * to by uip_appdata. 01505 */ 01506 u16_t uip_tcpchksum(void); 01507 01508 u16_t uip_udpchksum(void); 01509 01510 01511 #endif /* __UIP_H__ */ 01512 01513 01514 /** @} */
1.3.6