adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 1 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 2 | * \addtogroup uip |
| 3 | * @{ |
| 4 | */ |
| 5 | |
| 6 | /** |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 7 | * \file |
| 8 | * Header file for the uIP TCP/IP stack. |
| 9 | * \author Adam Dunkels <adam@dunkels.com> |
| 10 | * |
| 11 | * The uIP TCP/IP stack header file contains definitions for a number |
| 12 | * of C macros that are used by uIP programs as well as internal uIP |
| 13 | * structures, TCP/IP header structures and function declarations. |
| 14 | * |
| 15 | */ |
| 16 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 17 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 18 | /* |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 19 | * Copyright (c) 2001-2003, Adam Dunkels. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 20 | * All rights reserved. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the above copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 30 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 31 | * products derived from this software without specific prior |
| 32 | * written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 35 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 36 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 37 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 38 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 39 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 40 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 41 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 42 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 43 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 44 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | * This file is part of the uIP TCP/IP stack. |
| 47 | * |
oliverschmidt | 06b40b4 | 2006-05-17 15:25:15 +0000 | [diff] [blame] | 48 | * $Id: uip.h,v 1.20 2006/05/17 15:25:15 oliverschmidt Exp $ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 49 | * |
| 50 | */ |
| 51 | |
| 52 | #ifndef __UIP_H__ |
| 53 | #define __UIP_H__ |
| 54 | |
| 55 | #include "uipopt.h" |
| 56 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 57 | /*-----------------------------------------------------------------------------------*/ |
| 58 | /* First, the functions that should be called from the |
| 59 | * system. Initialization, the periodic timer and incoming packets are |
| 60 | * handled by the following three functions. |
| 61 | */ |
| 62 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 63 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 64 | * \defgroup uipconffunc uIP configuration functions |
| 65 | * @{ |
| 66 | * |
| 67 | * The uIP configuration functions are used for setting run-time |
| 68 | * parameters in uIP such as IP addresses. |
| 69 | */ |
| 70 | |
| 71 | /** |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 72 | * Set the IP address of this host. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 73 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 74 | * The IP address is represented as a 4-byte array where the first |
| 75 | * octet of the IP address is put in the first member of the 4-byte |
| 76 | * array. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 77 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 78 | * \param addr A pointer to a 4-byte representation of the IP address. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 79 | * |
| 80 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 81 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 82 | #define uip_sethostaddr(addr) do { uip_hostaddr[0] = ((u16_t *)(addr))[0]; \ |
| 83 | uip_hostaddr[1] = ((u16_t *)(addr))[1]; } while(0) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 84 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 85 | /** |
| 86 | * Get the IP address of this host. |
adamdunkels | 66c6af6 | 2003-04-16 18:28:16 +0000 | [diff] [blame] | 87 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 88 | * The IP address is represented as a 4-byte array where the first |
| 89 | * octet of the IP address is put in the first member of the 4-byte |
| 90 | * array. |
| 91 | * |
| 92 | * \param addr A pointer to a 4-byte array that will be filled in with |
| 93 | * the currently configured IP address. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 94 | * |
| 95 | * \hideinitializer |
adamdunkels | 66c6af6 | 2003-04-16 18:28:16 +0000 | [diff] [blame] | 96 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 97 | #define uip_gethostaddr(addr) do { ((u16_t *)(addr))[0] = uip_hostaddr[0]; \ |
| 98 | ((u16_t *)(addr))[1] = uip_hostaddr[1]; } while(0) |
| 99 | |
| 100 | /** |
| 101 | * Set the default router's IP address. |
| 102 | * |
| 103 | * \param addr A pointer to a 4-byte array containing the IP address |
| 104 | * of the default router. |
| 105 | * |
| 106 | * \hideinitializer |
| 107 | */ |
| 108 | #define uip_setdraddr(addr) do { uip_draddr[0] = ((u16_t *)(addr))[0]; \ |
| 109 | uip_draddr[1] = ((u16_t *)(addr))[1]; } while(0) |
| 110 | |
| 111 | /** |
| 112 | * Set the netmask. |
| 113 | * |
| 114 | * \param addr A pointer to a 4-byte array containing the IP address |
| 115 | * of the netmask. |
| 116 | * |
| 117 | * \hideinitializer |
| 118 | */ |
| 119 | #define uip_setnetmask(addr) do { uip_netmask[0] = ((u16_t *)(addr))[0]; \ |
| 120 | uip_netmask[1] = ((u16_t *)(addr))[1]; } while(0) |
| 121 | |
| 122 | |
| 123 | /** |
| 124 | * Get the default router's IP address. |
| 125 | * |
| 126 | * \param addr A pointer to a 4-byte array that will be filled in with |
| 127 | * the IP address of the default router. |
| 128 | * |
| 129 | * \hideinitializer |
| 130 | */ |
| 131 | #define uip_getdraddr(addr) do { ((u16_t *)(addr))[0] = uip_draddr[0]; \ |
| 132 | ((u16_t *)(addr))[1] = uip_draddr[1]; } while(0) |
| 133 | |
| 134 | /** |
| 135 | * Get the netmask. |
| 136 | * |
| 137 | * \param addr A pointer to a 4-byte array that will be filled in with |
| 138 | * the value of the netmask. |
| 139 | * |
| 140 | * \hideinitializer |
| 141 | */ |
| 142 | #define uip_getnetmask(addr) do { ((u16_t *)(addr))[0] = uip_netmask[0]; \ |
| 143 | ((u16_t *)(addr))[1] = uip_netmask[1]; } while(0) |
adamdunkels | 66c6af6 | 2003-04-16 18:28:16 +0000 | [diff] [blame] | 144 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 145 | /** @} */ |
| 146 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 147 | /** |
| 148 | * \defgroup uipinit uIP initialization functions |
| 149 | * @{ |
| 150 | * |
| 151 | * The uIP initialization functions are used for booting uIP. |
| 152 | */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * uIP initialization function. |
| 156 | * |
| 157 | * This function should be called at boot up to initilize the uIP |
| 158 | * TCP/IP stack. |
| 159 | */ |
| 160 | void uip_init(void); |
| 161 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 162 | /** @} */ |
| 163 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 164 | /** |
| 165 | * \defgroup uipdevfunc uIP device driver functions |
| 166 | * @{ |
| 167 | * |
| 168 | * These functions are used by a network device driver for interacting |
| 169 | * with uIP. |
| 170 | */ |
| 171 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 172 | /** |
| 173 | * Process an incoming packet. |
| 174 | * |
| 175 | * This function should be called when the device driver has received |
| 176 | * a packet from the network. The packet from the device driver must |
| 177 | * be present in the uip_buf buffer, and the length of the packet |
| 178 | * should be placed in the uip_len variable. |
| 179 | * |
| 180 | * When the function returns, there may be an outbound packet placed |
| 181 | * in the uip_buf packet buffer. If so, the uip_len variable is set to |
| 182 | * the length of the packet. If no packet is to be sent out, the |
| 183 | * uip_len variable is set to 0. |
| 184 | * |
| 185 | * The usual way of calling the function is presented by the source |
| 186 | * code below. |
| 187 | \code |
| 188 | uip_len = devicedriver_poll(); |
| 189 | if(uip_len > 0) { |
| 190 | uip_input(); |
| 191 | if(uip_len > 0) { |
| 192 | devicedriver_send(); |
| 193 | } |
| 194 | } |
| 195 | \endcode |
| 196 | * |
| 197 | * \note If you are writing a uIP device driver that needs ARP |
| 198 | * (Address Resolution Protocol), e.g., when running uIP over |
| 199 | * Ethernet, you will need to call the uIP ARP code before calling |
| 200 | * this function: |
| 201 | \code |
| 202 | #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) |
| 203 | uip_len = ethernet_devicedrver_poll(); |
| 204 | if(uip_len > 0) { |
| 205 | if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { |
| 206 | uip_arp_ipin(); |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 207 | uip_input(); |
| 208 | if(uip_len > 0) { |
| 209 | uip_arp_out(); |
| 210 | ethernet_devicedriver_send(); |
| 211 | } |
| 212 | } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { |
| 213 | uip_arp_arpin(); |
| 214 | if(uip_len > 0) { |
| 215 | ethernet_devicedriver_send(); |
| 216 | } |
| 217 | } |
| 218 | \endcode |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 219 | * |
| 220 | * \hideinitializer |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 221 | */ |
| 222 | #define uip_input() uip_process(UIP_DATA) |
| 223 | |
| 224 | /** |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 225 | * Periodic processing for a connection identified by its number. |
| 226 | * |
| 227 | * This function does the necessary periodic processing (timers, |
| 228 | * polling) for a uIP TCP conneciton, and should be called when the |
| 229 | * periodic uIP timer goes off. It should be called for every |
| 230 | * connection, regardless of whether they are open of closed. |
| 231 | * |
| 232 | * When the function returns, it may have an outbound packet waiting |
| 233 | * for service in the uIP packet buffer, and if so the uip_len |
| 234 | * variable is set to a value larger than zero. The device driver |
| 235 | * should be called to send out the packet. |
| 236 | * |
| 237 | * The ususal way of calling the function is through a for() loop like |
| 238 | * this: |
| 239 | \code |
| 240 | for(i = 0; i < UIP_CONNS; ++i) { |
| 241 | uip_periodic(i); |
| 242 | if(uip_len > 0) { |
| 243 | devicedriver_send(); |
| 244 | } |
| 245 | } |
| 246 | \endcode |
| 247 | * |
| 248 | * \note If you are writing a uIP device driver that needs ARP |
| 249 | * (Address Resolution Protocol), e.g., when running uIP over |
| 250 | * Ethernet, you will need to call the uip_arp_out() function before |
| 251 | * calling the device driver: |
| 252 | \code |
| 253 | for(i = 0; i < UIP_CONNS; ++i) { |
| 254 | uip_periodic(i); |
| 255 | if(uip_len > 0) { |
| 256 | uip_arp_out(); |
| 257 | ethernet_devicedriver_send(); |
| 258 | } |
| 259 | } |
| 260 | \endcode |
| 261 | * |
| 262 | * \param conn The number of the connection which is to be periodically polled. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 263 | * |
| 264 | * \hideinitializer |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 265 | */ |
| 266 | #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \ |
| 267 | uip_process(UIP_TIMER); } while (0) |
| 268 | |
| 269 | /** |
adamdunkels | 36d49be | 2005-02-27 09:52:43 +0000 | [diff] [blame] | 270 | * Perform periodic processing for a connection identified by a pointer |
adamdunkels | 3335cd9 | 2005-02-27 09:44:33 +0000 | [diff] [blame] | 271 | * to its structure. |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 272 | * |
| 273 | * Same as uip_periodic() but takes a pointer to the actual uip_conn |
| 274 | * struct instead of an integer as its argument. This function can be |
| 275 | * used to force periodic processing of a specific connection. |
| 276 | * |
| 277 | * \param conn A pointer to the uip_conn struct for the connection to |
| 278 | * be processed. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 279 | * |
| 280 | * \hideinitializer |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 281 | */ |
| 282 | #define uip_periodic_conn(conn) do { uip_conn = conn; \ |
| 283 | uip_process(UIP_TIMER); } while (0) |
| 284 | |
adamdunkels | 3335cd9 | 2005-02-27 09:44:33 +0000 | [diff] [blame] | 285 | /** |
| 286 | * Reuqest that a particular connection should be polled. |
| 287 | * |
| 288 | * Similar to uip_periodic_conn() but does not perform any timer |
| 289 | * processing. The application is polled for new data. |
| 290 | * |
| 291 | * \param conn A pointer to the uip_conn struct for the connection to |
| 292 | * be processed. |
| 293 | * |
| 294 | * \hideinitializer |
| 295 | */ |
| 296 | #define uip_poll_conn(conn) do { uip_conn = conn; \ |
| 297 | uip_process(UIP_POLL_REQUEST); } while (0) |
| 298 | |
| 299 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 300 | #if UIP_UDP |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 301 | /** |
| 302 | * Periodic processing for a UDP connection identified by its number. |
| 303 | * |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 304 | * This function is essentially the same as uip_periodic(), but for |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 305 | * UDP connections. It is called in a similar fashion as the |
| 306 | * uip_periodic() function: |
| 307 | \code |
| 308 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
| 309 | uip_udp_periodic(i); |
| 310 | if(uip_len > 0) { |
| 311 | devicedriver_send(); |
| 312 | } |
| 313 | } |
| 314 | \endcode |
| 315 | * |
| 316 | * \note As for the uip_periodic() function, special care has to be |
| 317 | * taken when using uIP together with ARP and Ethernet: |
| 318 | \code |
| 319 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
| 320 | uip_udp_periodic(i); |
| 321 | if(uip_len > 0) { |
| 322 | uip_arp_out(); |
| 323 | ethernet_devicedriver_send(); |
| 324 | } |
| 325 | } |
| 326 | \endcode |
| 327 | * |
| 328 | * \param conn The number of the UDP connection to be processed. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 329 | * |
| 330 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 331 | */ |
| 332 | #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ |
| 333 | uip_process(UIP_UDP_TIMER); } while (0) |
adamdunkels | eb91d5f | 2003-08-20 20:58:08 +0000 | [diff] [blame] | 334 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 335 | /** |
| 336 | * Periodic processing for a UDP connection identified by a pointer to |
| 337 | * its structure. |
| 338 | * |
| 339 | * Same as uip_udp_periodic() but takes a pointer to the actual |
| 340 | * uip_conn struct instead of an integer as its argument. This |
| 341 | * function can be used to force periodic processing of a specific |
| 342 | * connection. |
| 343 | * |
| 344 | * \param conn A pointer to the uip_udp_conn struct for the connection |
| 345 | * to be processed. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 346 | * |
| 347 | * \hideinitializer |
adamdunkels | eb91d5f | 2003-08-20 20:58:08 +0000 | [diff] [blame] | 348 | */ |
| 349 | #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ |
| 350 | uip_process(UIP_UDP_TIMER); } while (0) |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 351 | |
| 352 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 353 | #endif /* UIP_UDP */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 354 | |
| 355 | /** |
| 356 | * The uIP packet buffer. |
| 357 | * |
| 358 | * The uip_buf array is used to hold incoming and outgoing |
| 359 | * packets. The device driver should place incoming data into this |
| 360 | * buffer. When sending data, the device driver should read the link |
| 361 | * level headers and the TCP/IP headers from this buffer. The size of |
| 362 | * the link level headers is configured by the UIP_LLH_LEN define. |
| 363 | * |
| 364 | * \note The application data need not be placed in this buffer, so |
| 365 | * the device driver must read it from the place pointed to by the |
| 366 | * uip_appdata pointer as illustrated by the following example: |
| 367 | \code |
| 368 | void |
| 369 | devicedriver_send(void) |
| 370 | { |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 371 | hwsend(&uip_buf[0], UIP_LLH_LEN); |
oliverschmidt | 3742087 | 2005-02-23 22:38:43 +0000 | [diff] [blame] | 372 | if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) { |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 373 | hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN); |
| 374 | } else { |
oliverschmidt | 3742087 | 2005-02-23 22:38:43 +0000 | [diff] [blame] | 375 | hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN); |
| 376 | hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN); |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 377 | } |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 378 | } |
| 379 | \endcode |
| 380 | */ |
| 381 | extern u8_t uip_buf[UIP_BUFSIZE+2]; |
| 382 | |
| 383 | /** @} */ |
| 384 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 385 | /*-----------------------------------------------------------------------------------*/ |
| 386 | /* Functions that are used by the uIP application program. Opening and |
| 387 | * closing connections, sending and receiving data, etc. is all |
| 388 | * handled by the functions below. |
| 389 | */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 390 | /** |
| 391 | * \defgroup uipappfunc uIP application functions |
| 392 | * @{ |
| 393 | * |
| 394 | * Functions used by an application running of top of uIP. |
| 395 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 396 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 397 | /** |
| 398 | * Start listening to the specified port. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 399 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 400 | * \note Since this function expects the port number in network byte |
| 401 | * order, a conversion using HTONS() or htons() is necessary. |
| 402 | * |
| 403 | \code |
| 404 | uip_listen(HTONS(80)); |
| 405 | \endcode |
| 406 | * |
| 407 | * \param port A 16-bit port number in network byte order. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 408 | */ |
| 409 | void uip_listen(u16_t port); |
| 410 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 411 | /** |
| 412 | * Stop listening to the specified port. |
adamdunkels | cd8c3a2 | 2003-08-13 22:52:48 +0000 | [diff] [blame] | 413 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 414 | * \note Since this function expects the port number in network byte |
| 415 | * order, a conversion using HTONS() or htons() is necessary. |
| 416 | * |
| 417 | \code |
| 418 | uip_unlisten(HTONS(80)); |
| 419 | \endcode |
| 420 | * |
| 421 | * \param port A 16-bit port number in network byte order. |
adamdunkels | cd8c3a2 | 2003-08-13 22:52:48 +0000 | [diff] [blame] | 422 | */ |
| 423 | void uip_unlisten(u16_t port); |
| 424 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 425 | /** |
| 426 | * Connect to a remote host using TCP. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 427 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 428 | * This function is used to start a new connection to the specified |
| 429 | * port on the specied host. It allocates a new connection identifier, |
| 430 | * sets the connection to the SYN_SENT state and sets the |
| 431 | * retransmission timer to 0. This will cause a TCP SYN segment to be |
| 432 | * sent out the next time this connection is periodically processed, |
| 433 | * which usually is done within 0.5 seconds after the call to |
| 434 | * uip_connect(). |
| 435 | * |
| 436 | * \note This function is avaliable only if support for active open |
| 437 | * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. |
| 438 | * |
| 439 | * \note Since this function requires the port number to be in network |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 440 | * byte order, a conversion using HTONS() or htons() is necessary. |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 441 | * |
| 442 | \code |
| 443 | u16_t ipaddr[2]; |
| 444 | |
| 445 | uip_ipaddr(ipaddr, 192,168,1,2); |
| 446 | uip_connect(ipaddr, HTONS(80)); |
| 447 | \endcode |
| 448 | * |
| 449 | * \param ripaddr A pointer to a 4-byte array representing the IP |
| 450 | * address of the remote hot. |
| 451 | * |
| 452 | * \param port A 16-bit port number in network byte order. |
| 453 | * |
| 454 | * \return A pointer to the uIP connection identifier for the new connection, |
| 455 | * or NULL if no connection could be allocated. |
| 456 | * |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 457 | */ |
| 458 | struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port); |
| 459 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 460 | |
| 461 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 462 | /** |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 463 | * \internal |
| 464 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 465 | * Check if a connection has outstanding (i.e., unacknowledged) data. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 466 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 467 | * \param conn A pointer to the uip_conn structure for the connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 468 | * |
| 469 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 470 | */ |
| 471 | #define uip_outstanding(conn) ((conn)->len) |
| 472 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 473 | /** |
| 474 | * Send data on the current connection. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 475 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 476 | * This function is used to send out a single segment of TCP |
| 477 | * data. Only applications that have been invoked by uIP for event |
| 478 | * processing can send data. |
| 479 | * |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 480 | * The amount of data that actually is sent out after a call to this |
| 481 | * funcion is determined by the maximum amount of data TCP allows. uIP |
| 482 | * will automatically crop the data so that only the appropriate |
| 483 | * amount of data is sent. The function uip_mss() can be used to query |
| 484 | * uIP for the amount of data that actually will be sent. |
| 485 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 486 | * \note This function does not guarantee that the sent data will |
| 487 | * arrive at the destination. If the data is lost in the network, the |
| 488 | * application will be invoked with the uip_rexmit() event being |
| 489 | * set. The application will then have to resend the data using this |
| 490 | * function. |
| 491 | * |
| 492 | * \param data A pointer to the data which is to be sent. |
| 493 | * |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 494 | * \param len The maximum amount of data bytes to be sent. |
| 495 | * |
| 496 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 497 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 498 | #define uip_send(data, len) do { uip_sappdata = (void *)(data); uip_slen = (len);} while(0) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 499 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 500 | /** |
| 501 | * The length of any incoming data that is currently avaliable (if avaliable) |
| 502 | * in the uip_appdata buffer. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 503 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 504 | * The test function uip_data() must first be used to check if there |
| 505 | * is any data available at all. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 506 | * |
| 507 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 508 | */ |
| 509 | #define uip_datalen() uip_len |
| 510 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 511 | /** |
| 512 | * The length of any out-of-band data (urgent data) that has arrived |
| 513 | * on the connection. |
| 514 | * |
| 515 | * \note The configuration parameter UIP_URGDATA must be set for this |
| 516 | * function to be enabled. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 517 | * |
| 518 | * \hideinitializer |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 519 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 520 | #define uip_urgdatalen() uip_urglen |
| 521 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 522 | /** |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 523 | * Close the current connection. |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 524 | * |
| 525 | * This function will close the current connection in a nice way. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 526 | * |
| 527 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 528 | */ |
| 529 | #define uip_close() (uip_flags = UIP_CLOSE) |
| 530 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 531 | /** |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 532 | * Abort the current connection. |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 533 | * |
| 534 | * This function will abort (reset) the current connection, and is |
| 535 | * usually used when an error has occured that prevents using the |
| 536 | * uip_close() function. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 537 | * |
| 538 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 539 | */ |
| 540 | #define uip_abort() (uip_flags = UIP_ABORT) |
| 541 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 542 | /** |
| 543 | * Tell the sending host to stop sending data. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 544 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 545 | * This function will close our receiver's window so that we stop |
| 546 | * receiving data for the current connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 547 | * |
| 548 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 549 | */ |
| 550 | #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) |
| 551 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 552 | /** |
| 553 | * Find out if the current connection has been previously stopped with |
| 554 | * uip_stop(). |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 555 | * |
| 556 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 557 | */ |
| 558 | #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) |
| 559 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 560 | /** |
| 561 | * Restart the current connection, if is has previously been stopped |
| 562 | * with uip_stop(). |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 563 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 564 | * This function will open the receiver's window again so that we |
| 565 | * start receiving data for the current connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 566 | * |
| 567 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 568 | */ |
| 569 | #define uip_restart() do { uip_flags |= UIP_NEWDATA; \ |
| 570 | uip_conn->tcpstateflags &= ~UIP_STOPPED; \ |
| 571 | } while(0) |
| 572 | |
| 573 | |
| 574 | /* uIP tests that can be made to determine in what state the current |
| 575 | connection is, and what the application function should do. */ |
| 576 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 577 | /** |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 578 | * Is the current connection a UDP connection? |
| 579 | * |
| 580 | * This function checks whether the current connection is a UDP connection. |
| 581 | * |
| 582 | * \hideinitializer |
| 583 | * |
| 584 | */ |
| 585 | #define uip_udpconnection() (uip_conn == NULL) |
| 586 | |
| 587 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 588 | * Is new incoming data available? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 589 | * |
| 590 | * Will reduce to non-zero if there is new data for the application |
| 591 | * present at the uip_appdata pointer. The size of the data is |
| 592 | * avaliable through the uip_len variable. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 593 | * |
| 594 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 595 | */ |
| 596 | #define uip_newdata() (uip_flags & UIP_NEWDATA) |
| 597 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 598 | /** |
| 599 | * Has previously sent data been acknowledged? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 600 | * |
| 601 | * Will reduce to non-zero if the previously sent data has been |
| 602 | * acknowledged by the remote host. This means that the application |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 603 | * can send new data. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 604 | * |
| 605 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 606 | */ |
| 607 | #define uip_acked() (uip_flags & UIP_ACKDATA) |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 608 | |
| 609 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 610 | * Has the connection just been connected? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 611 | * |
| 612 | * Reduces to non-zero if the current connection has been connected to |
| 613 | * a remote host. This will happen both if the connection has been |
| 614 | * actively opened (with uip_connect()) or passively opened (with |
| 615 | * uip_listen()). |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 616 | * |
| 617 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 618 | */ |
| 619 | #define uip_connected() (uip_flags & UIP_CONNECTED) |
| 620 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 621 | /** |
| 622 | * Has the connection been closed by the other end? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 623 | * |
| 624 | * Is non-zero if the connection has been closed by the remote |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 625 | * host. The application may then do the necessary clean-ups. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 626 | * |
| 627 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 628 | */ |
| 629 | #define uip_closed() (uip_flags & UIP_CLOSE) |
| 630 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 631 | /** |
| 632 | * Has the connection been aborted by the other end? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 633 | * |
| 634 | * Non-zero if the current connection has been aborted (reset) by the |
| 635 | * remote host. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 636 | * |
| 637 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 638 | */ |
| 639 | #define uip_aborted() (uip_flags & UIP_ABORT) |
| 640 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 641 | /** |
| 642 | * Has the connection timed out? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 643 | * |
| 644 | * Non-zero if the current connection has been aborted due to too many |
| 645 | * retransmissions. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 646 | * |
| 647 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 648 | */ |
adamdunkels | 399a078 | 2004-02-16 20:52:07 +0000 | [diff] [blame] | 649 | #define uip_timedout() (uip_flags & UIP_TIMEDOUT) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 650 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 651 | /** |
| 652 | * Do we need to retransmit previously data? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 653 | * |
| 654 | * Reduces to non-zero if the previously sent data has been lost in |
| 655 | * the network, and the application should retransmit it. The |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 656 | * application should send the exact same data as it did the last |
| 657 | * time, using the uip_send() function. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 658 | * |
| 659 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 660 | */ |
| 661 | #define uip_rexmit() (uip_flags & UIP_REXMIT) |
| 662 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 663 | /** |
| 664 | * Is the connection being polled by uIP? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 665 | * |
| 666 | * Is non-zero if the reason the application is invoked is that the |
| 667 | * current connection has been idle for a while and should be |
| 668 | * polled. |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 669 | * |
| 670 | * The polling event can be used for sending data without having to |
| 671 | * wait for the remote host to send data. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 672 | * |
| 673 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 674 | */ |
| 675 | #define uip_poll() (uip_flags & UIP_POLL) |
| 676 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 677 | /** |
| 678 | * Get the initial maxium segment size (MSS) of the current |
| 679 | * connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 680 | * |
| 681 | * \hideinitializer |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 682 | */ |
| 683 | #define uip_initialmss() (uip_conn->initialmss) |
| 684 | |
| 685 | /** |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 686 | * Get the current maxium segment size that can be sent on the current |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 687 | * connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 688 | * |
| 689 | * The current maxiumum segment size that can be sent on the |
| 690 | * connection is computed from the receiver's window and the MSS of |
| 691 | * the connection (which also is available by calling |
| 692 | * uip_initialmss()). |
| 693 | * |
| 694 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 695 | */ |
| 696 | #define uip_mss() (uip_conn->mss) |
| 697 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 698 | /** |
| 699 | * Set up a new UDP connection. |
| 700 | * |
| 701 | * \param ripaddr A pointer to a 4-byte structure representing the IP |
| 702 | * address of the remote host. |
| 703 | * |
| 704 | * \param rport The remote port number in network byte order. |
| 705 | * |
| 706 | * \return The uip_udp_conn structure for the new connection or NULL |
| 707 | * if no connection could be allocated. |
| 708 | */ |
| 709 | struct uip_udp_conn *uip_udp_new(u16_t *ripaddr, u16_t rport); |
| 710 | |
| 711 | /** |
| 712 | * Removed a UDP connection. |
| 713 | * |
| 714 | * \param conn A pointer to the uip_udp_conn structure for the connection. |
| 715 | * |
| 716 | * \hideinitializer |
| 717 | */ |
| 718 | #define uip_udp_remove(conn) (conn)->lport = 0 |
| 719 | |
| 720 | /** |
adamdunkels | 37f0b8d | 2004-07-04 17:00:50 +0000 | [diff] [blame] | 721 | * Bind a UDP connection to a local port. |
| 722 | * |
| 723 | * \param conn A pointer to the uip_udp_conn structure for the |
| 724 | * connection. |
| 725 | * |
| 726 | * \param port The local port number, in network byte order. |
| 727 | * |
| 728 | * \hideinitializer |
| 729 | */ |
| 730 | #define uip_udp_bind(conn, port) (conn)->lport = port |
| 731 | |
| 732 | /** |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 733 | * Send a UDP datagram of length len on the current connection. |
| 734 | * |
| 735 | * This function can only be called in response to a UDP event (poll |
| 736 | * or newdata). The data must be present in the uip_buf buffer, at the |
| 737 | * place pointed to by the uip_appdata pointer. |
| 738 | * |
| 739 | * \param len The length of the data in the uip_buf buffer. |
| 740 | * |
| 741 | * \hideinitializer |
| 742 | */ |
| 743 | #define uip_udp_send(len) uip_slen = (len) |
| 744 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 745 | /** @} */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 746 | |
| 747 | /* uIP convenience and converting functions. */ |
| 748 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 749 | /** |
| 750 | * \defgroup uipconvfunc uIP conversion functions |
| 751 | * @{ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 752 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 753 | * These functions can be used for converting between different data |
| 754 | * formats used by uIP. |
| 755 | */ |
| 756 | |
| 757 | /** |
| 758 | * Pack an IP address into a 4-byte array which is used by uIP to |
| 759 | * represent IP addresses. |
| 760 | * |
| 761 | * Example: |
| 762 | \code |
| 763 | u16_t ipaddr[2]; |
| 764 | |
| 765 | uip_ipaddr(&ipaddr, 192,168,1,2); |
| 766 | \endcode |
| 767 | * |
| 768 | * \param addr A pointer to a 4-byte array that will be filled in with |
| 769 | * the IP addres. |
| 770 | * \param addr0 The first octet of the IP address. |
| 771 | * \param addr1 The second octet of the IP address. |
| 772 | * \param addr2 The third octet of the IP address. |
| 773 | * \param addr3 The forth octet of the IP address. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 774 | * |
| 775 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 776 | */ |
| 777 | #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 778 | ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ |
| 779 | ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 780 | } while(0) |
| 781 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 782 | /** |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 783 | * Copy an IP address to another IP address. |
| 784 | * |
| 785 | * Copies an IP address from one place to another. |
| 786 | * |
| 787 | * Example: |
| 788 | \code |
| 789 | u16_t ipaddr1[2], ipaddr2[2]; |
| 790 | |
| 791 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 792 | uip_ipaddr_copy(ipaddr2, ipaddr1); |
| 793 | \endcode |
| 794 | * |
| 795 | * \param dest The destination for the copy. |
| 796 | * \param src The source from where to copy. |
| 797 | * |
| 798 | * \hideinitializer |
| 799 | */ |
| 800 | #define uip_ipaddr_copy(dest, src) do { \ |
| 801 | ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \ |
| 802 | ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \ |
| 803 | } while(0) |
| 804 | /** |
| 805 | * Compare two IP addresses |
| 806 | * |
| 807 | * Compares two IP addresses. |
| 808 | * |
| 809 | * Example: |
| 810 | \code |
| 811 | u16_t ipaddr1[2], ipaddr2[2]; |
| 812 | |
| 813 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 814 | if(uip_ipaddr_cmp(ipaddr2, ipaddr1)) { |
| 815 | printf("They are the same"); |
| 816 | } |
| 817 | \endcode |
| 818 | * |
| 819 | * \param addr1 The first IP address. |
| 820 | * \param addr2 The second IP address. |
| 821 | * |
| 822 | * \hideinitializer |
| 823 | */ |
| 824 | #define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \ |
| 825 | ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1]) |
| 826 | |
| 827 | /** |
| 828 | * Compare two IP addresses with netmasks |
| 829 | * |
| 830 | * Compares two IP addresses with netmasks. The masks are used to mask |
| 831 | * out the bits that are to be compared. |
| 832 | * |
| 833 | * Example: |
| 834 | \code |
| 835 | u16_t ipaddr1[2], ipaddr2[2], mask[2]; |
| 836 | |
| 837 | uip_ipaddr(mask, 255,255,255,0); |
| 838 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 839 | uip_ipaddr(ipaddr2, 192,16,1,3); |
| 840 | if(uip_ipaddr_maskcmp(ipaddr1, ipaddr2, mask)) { |
| 841 | printf("They are the same"); |
| 842 | } |
| 843 | \endcode |
| 844 | * |
| 845 | * \param addr1 The first IP address. |
| 846 | * \param addr2 The second IP address. |
| 847 | * \param mask The netmask. |
| 848 | * |
| 849 | * \hideinitializer |
| 850 | */ |
| 851 | #define uip_ipaddr_maskcmp(addr1, addr2, mask) \ |
| 852 | (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \ |
| 853 | (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \ |
| 854 | ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \ |
| 855 | (((u16_t *)addr2)[1] & ((u16_t *)mask)[1]))) |
| 856 | |
| 857 | |
| 858 | /** |
| 859 | * Mask out the network part of an IP address. |
| 860 | * |
| 861 | * Masks out the network part of an IP address, given the address and |
| 862 | * the netmask. |
| 863 | * |
| 864 | * Example: |
| 865 | \code |
| 866 | u16_t ipaddr1[2], ipaddr2[2], netmask[2]; |
| 867 | |
| 868 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 869 | uip_ipaddr(netmask, 255,255,255,0); |
| 870 | uip_ipaddr_mask(ipaddr2, ipaddr1, netmask); |
| 871 | \endcode |
| 872 | * |
| 873 | * In the example above, the variable "ipaddr2" will contain the IP |
| 874 | * address 192.168.1.0. |
| 875 | * |
| 876 | * \param dest Where the result is to be placed. |
| 877 | * \param src The IP address. |
| 878 | * \param mask The netmask. |
| 879 | * |
| 880 | * \hideinitializer |
| 881 | */ |
| 882 | #define uip_ipaddr_mask(dest, src, mask) do { \ |
| 883 | ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \ |
| 884 | ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \ |
| 885 | } while(0) |
| 886 | |
| 887 | /** |
| 888 | * Pick the first octet of an IP address. |
| 889 | * |
| 890 | * Picks out the first octet of an IP address. |
| 891 | * |
| 892 | * Example: |
| 893 | \code |
| 894 | u16_t ipaddr[2]; |
| 895 | u8_t octet; |
| 896 | |
| 897 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 898 | octet = uip_ipaddr1(ipaddr); |
| 899 | \endcode |
| 900 | * |
| 901 | * In the example above, the variable "octet" will contain the value 1. |
| 902 | * |
| 903 | * \hideinitializer |
| 904 | */ |
| 905 | #define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8) |
| 906 | |
| 907 | /** |
| 908 | * Pick the second octet of an IP address. |
| 909 | * |
| 910 | * Picks out the second octet of an IP address. |
| 911 | * |
| 912 | * Example: |
| 913 | \code |
| 914 | u16_t ipaddr[2]; |
| 915 | u8_t octet; |
| 916 | |
| 917 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 918 | octet = uip_ipaddr2(ipaddr); |
| 919 | \endcode |
| 920 | * |
| 921 | * In the example above, the variable "octet" will contain the value 2. |
| 922 | * |
| 923 | * \hideinitializer |
| 924 | */ |
| 925 | #define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff) |
| 926 | |
| 927 | /** |
| 928 | * Pick the third octet of an IP address. |
| 929 | * |
| 930 | * Picks out the third octet of an IP address. |
| 931 | * |
| 932 | * Example: |
| 933 | \code |
| 934 | u16_t ipaddr[2]; |
| 935 | u8_t octet; |
| 936 | |
| 937 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 938 | octet = uip_ipaddr3(ipaddr); |
| 939 | \endcode |
| 940 | * |
| 941 | * In the example above, the variable "octet" will contain the value 3. |
| 942 | * |
| 943 | * \hideinitializer |
| 944 | */ |
| 945 | #define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8) |
| 946 | |
| 947 | /** |
| 948 | * Pick the fourth octet of an IP address. |
| 949 | * |
| 950 | * Picks out the fourth octet of an IP address. |
| 951 | * |
| 952 | * Example: |
| 953 | \code |
| 954 | u16_t ipaddr[2]; |
| 955 | u8_t octet; |
| 956 | |
| 957 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 958 | octet = uip_ipaddr4(ipaddr); |
| 959 | \endcode |
| 960 | * |
| 961 | * In the example above, the variable "octet" will contain the value 4. |
| 962 | * |
| 963 | * \hideinitializer |
| 964 | */ |
| 965 | #define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff) |
| 966 | |
| 967 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 968 | * Convert 16-bit quantity from host byte order to network byte order. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 969 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 970 | * This macro is primarily used for converting constants from host |
| 971 | * byte order to network byte order. For converting variables to |
| 972 | * network byte order, use the htons() function instead. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 973 | * |
| 974 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 975 | */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 976 | #ifndef HTONS |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 977 | # if BYTE_ORDER == BIG_ENDIAN |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 978 | # define HTONS(n) (n) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 979 | # else /* BYTE_ORDER == BIG_ENDIAN */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 980 | # define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8)) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 981 | # endif /* BYTE_ORDER == BIG_ENDIAN */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 982 | #endif /* HTONS */ |
| 983 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 984 | /** |
| 985 | * Convert 16-bit quantity from host byte order to network byte order. |
| 986 | * |
| 987 | * This function is primarily used for converting variables from host |
| 988 | * byte order to network byte order. For converting constants to |
| 989 | * network byte order, use the HTONS() macro instead. |
| 990 | */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 991 | u16_t htons(u16_t val); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 992 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 993 | /** @} */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 994 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 995 | /** |
| 996 | * Pointer to the application data in the packet buffer. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 997 | * |
| 998 | * This pointer points to the application data when the application is |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 999 | * called. If the application wishes to send data, the application may |
| 1000 | * use this space to write the data into before calling uip_send(). |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1001 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1002 | extern u8_t *uip_appdata; |
| 1003 | extern u8_t *uip_sappdata; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1004 | |
| 1005 | #if UIP_URGDATA > 0 |
| 1006 | /* u8_t *uip_urgdata: |
| 1007 | * |
| 1008 | * This pointer points to any urgent data that has been received. Only |
| 1009 | * present if compiled with support for urgent data (UIP_URGDATA). |
| 1010 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1011 | extern u8_t *uip_urgdata; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1012 | #endif /* UIP_URGDATA > 0 */ |
| 1013 | |
| 1014 | |
| 1015 | /* u[8|16]_t uip_len: |
| 1016 | * |
| 1017 | * When the application is called, uip_len contains the length of any |
| 1018 | * new data that has been received from the remote host. The |
| 1019 | * application should set this variable to the size of any data that |
| 1020 | * the application wishes to send. When the network device driver |
| 1021 | * output function is called, uip_len should contain the length of the |
| 1022 | * outgoing packet. |
| 1023 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1024 | extern u16_t uip_len, uip_slen; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1025 | |
| 1026 | #if UIP_URGDATA > 0 |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1027 | extern u8_t uip_urglen, uip_surglen; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1028 | #endif /* UIP_URGDATA > 0 */ |
| 1029 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1030 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1031 | /** |
| 1032 | * Representation of a uIP TCP connection. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1033 | * |
| 1034 | * The uip_conn structure is used for identifying a connection. All |
| 1035 | * but one field in the structure are to be considered read-only by an |
| 1036 | * application. The only exception is the appstate field whos purpose |
| 1037 | * is to let the application store application-specific state (e.g., |
| 1038 | * file pointers) for the connection. The size of this field is |
| 1039 | * configured in the "uipopt.h" header file. |
| 1040 | */ |
| 1041 | struct uip_conn { |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1042 | u16_t ripaddr[2]; /**< The IP address of the remote host. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1043 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1044 | u16_t lport; /**< The local TCP port, in network byte order. */ |
| 1045 | u16_t rport; /**< The local remote TCP port, in network byte |
| 1046 | order. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1047 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1048 | u8_t rcv_nxt[4]; /**< The sequence number that we expect to |
| 1049 | receive next. */ |
| 1050 | u8_t snd_nxt[4]; /**< The sequence number that was last sent by |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1051 | us. */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1052 | u16_t len; /**< Length of the data that was previously sent. */ |
| 1053 | u16_t mss; /**< Current maximum segment size for the |
| 1054 | connection. */ |
| 1055 | u16_t initialmss; /**< Initial maximum segment size for the |
| 1056 | connection. */ |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1057 | u8_t sa; /**< Retransmission time-out calculation state |
| 1058 | variable. */ |
| 1059 | u8_t sv; /**< Retransmission time-out calculation state |
| 1060 | variable. */ |
| 1061 | u8_t rto; /**< Retransmission time-out. */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1062 | u8_t tcpstateflags; /**< TCP state and flags. */ |
| 1063 | u8_t timer; /**< The retransmission timer. */ |
| 1064 | u8_t nrtx; /**< The number of retransmissions for the last |
| 1065 | segment sent. */ |
| 1066 | |
| 1067 | /** The application state. */ |
| 1068 | u8_t appstate[UIP_APPSTATE_SIZE]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1069 | }; |
| 1070 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1071 | |
| 1072 | /* Pointer to the current connection. */ |
| 1073 | extern struct uip_conn *uip_conn; |
| 1074 | /* The array containing all uIP connections. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1075 | extern struct uip_conn uip_conns[UIP_CONNS]; |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1076 | /** |
| 1077 | * \addtogroup uiparch |
| 1078 | * @{ |
| 1079 | */ |
| 1080 | |
| 1081 | /** |
| 1082 | * 4-byte array used for the 32-bit sequence number calculations. |
| 1083 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1084 | extern u8_t uip_acc32[4]; |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1085 | |
| 1086 | /** @} */ |
| 1087 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1088 | |
| 1089 | #if UIP_UDP |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 1090 | /** |
| 1091 | * Representation of a uIP UDP connection. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1092 | */ |
| 1093 | struct uip_udp_conn { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1094 | u16_t ripaddr[2]; /**< The IP address of the remote peer. */ |
| 1095 | u16_t lport; /**< The local port number in network byte order. */ |
| 1096 | u16_t rport; /**< The remote port number in network byte order. */ |
adamdunkels | 399a078 | 2004-02-16 20:52:07 +0000 | [diff] [blame] | 1097 | |
| 1098 | /** The application state. */ |
| 1099 | u8_t appstate[UIP_APPSTATE_SIZE]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1100 | }; |
| 1101 | |
| 1102 | extern struct uip_udp_conn *uip_udp_conn; |
| 1103 | extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; |
| 1104 | #endif /* UIP_UDP */ |
| 1105 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1106 | /** |
| 1107 | * The structure holding the TCP/IP statistics that are gathered if |
| 1108 | * UIP_STATISTICS is set to 1. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1109 | * |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1110 | */ |
| 1111 | struct uip_stats { |
| 1112 | struct { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1113 | uip_stats_t drop; /**< Number of dropped packets at the IP |
| 1114 | layer. */ |
| 1115 | uip_stats_t recv; /**< Number of received packets at the IP |
| 1116 | layer. */ |
| 1117 | uip_stats_t sent; /**< Number of sent packets at the IP |
| 1118 | layer. */ |
| 1119 | uip_stats_t vhlerr; /**< Number of packets dropped due to wrong |
| 1120 | IP version or header length. */ |
| 1121 | uip_stats_t hblenerr; /**< Number of packets dropped due to wrong |
| 1122 | IP length, high byte. */ |
| 1123 | uip_stats_t lblenerr; /**< Number of packets dropped due to wrong |
| 1124 | IP length, low byte. */ |
| 1125 | uip_stats_t fragerr; /**< Number of packets dropped since they |
| 1126 | were IP fragments. */ |
| 1127 | uip_stats_t chkerr; /**< Number of packets dropped due to IP |
| 1128 | checksum errors. */ |
| 1129 | uip_stats_t protoerr; /**< Number of packets dropped since they |
| 1130 | were neither ICMP, UDP nor TCP. */ |
| 1131 | } ip; /**< IP statistics. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1132 | struct { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1133 | uip_stats_t drop; /**< Number of dropped ICMP packets. */ |
| 1134 | uip_stats_t recv; /**< Number of received ICMP packets. */ |
| 1135 | uip_stats_t sent; /**< Number of sent ICMP packets. */ |
| 1136 | uip_stats_t typeerr; /**< Number of ICMP packets with a wrong |
| 1137 | type. */ |
| 1138 | } icmp; /**< ICMP statistics. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1139 | struct { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1140 | uip_stats_t drop; /**< Number of dropped TCP segments. */ |
| 1141 | uip_stats_t recv; /**< Number of recived TCP segments. */ |
| 1142 | uip_stats_t sent; /**< Number of sent TCP segments. */ |
| 1143 | uip_stats_t chkerr; /**< Number of TCP segments with a bad |
| 1144 | checksum. */ |
| 1145 | uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK |
| 1146 | number. */ |
| 1147 | uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */ |
| 1148 | uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ |
| 1149 | uip_stats_t syndrop; /**< Number of dropped SYNs due to too few |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1150 | connections was avaliable. */ |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1151 | uip_stats_t synrst; /**< Number of SYNs for closed ports, |
| 1152 | triggering a RST. */ |
| 1153 | } tcp; /**< TCP statistics. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1154 | }; |
| 1155 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1156 | /** |
| 1157 | * The uIP TCP/IP statistics. |
| 1158 | * |
| 1159 | * This is the variable in which the uIP TCP/IP statistics are gathered. |
| 1160 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1161 | extern struct uip_stats uip_stat; |
| 1162 | |
| 1163 | |
| 1164 | /*-----------------------------------------------------------------------------------*/ |
| 1165 | /* All the stuff below this point is internal to uIP and should not be |
| 1166 | * used directly by an application or by a device driver. |
| 1167 | */ |
| 1168 | /*-----------------------------------------------------------------------------------*/ |
| 1169 | /* u8_t uip_flags: |
| 1170 | * |
| 1171 | * When the application is called, uip_flags will contain the flags |
| 1172 | * that are defined in this file. Please read below for more |
| 1173 | * infomation. |
| 1174 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1175 | extern u8_t uip_flags; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1176 | |
| 1177 | /* The following flags may be set in the global variable uip_flags |
| 1178 | before calling the application callback. The UIP_ACKDATA and |
| 1179 | UIP_NEWDATA flags may both be set at the same time, whereas the |
| 1180 | others are mutualy exclusive. Note that these flags should *NOT* be |
| 1181 | accessed directly, but through the uIP functions/macros. */ |
| 1182 | |
| 1183 | #define UIP_ACKDATA 1 /* Signifies that the outstanding data was |
| 1184 | acked and the application should send |
| 1185 | out new data instead of retransmitting |
| 1186 | the last data. */ |
| 1187 | #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent |
| 1188 | us new data. */ |
| 1189 | #define UIP_REXMIT 4 /* Tells the application to retransmit the |
| 1190 | data that was last sent. */ |
| 1191 | #define UIP_POLL 8 /* Used for polling the application, to |
| 1192 | check if the application has data that |
| 1193 | it wants to send. */ |
| 1194 | #define UIP_CLOSE 16 /* The remote host has closed the |
| 1195 | connection, thus the connection has |
| 1196 | gone away. Or the application signals |
| 1197 | that it wants to close the |
| 1198 | connection. */ |
| 1199 | #define UIP_ABORT 32 /* The remote host has aborted the |
| 1200 | connection, thus the connection has |
| 1201 | gone away. Or the application signals |
| 1202 | that it wants to abort the |
| 1203 | connection. */ |
| 1204 | #define UIP_CONNECTED 64 /* We have got a connection from a remote |
| 1205 | host and have set up a new connection |
| 1206 | for it, or an active connection has |
| 1207 | been successfully established. */ |
| 1208 | |
| 1209 | #define UIP_TIMEDOUT 128 /* The connection has been aborted due to |
| 1210 | too many retransmissions. */ |
| 1211 | |
| 1212 | |
| 1213 | /* uip_process(flag): |
| 1214 | * |
| 1215 | * The actual uIP function which does all the work. |
| 1216 | */ |
| 1217 | void uip_process(u8_t flag); |
| 1218 | |
| 1219 | /* The following flags are passed as an argument to the uip_process() |
| 1220 | function. They are used to distinguish between the two cases where |
| 1221 | uip_process() is called. It can be called either because we have |
| 1222 | incoming data that should be processed, or because the periodic |
adamdunkels | 3335cd9 | 2005-02-27 09:44:33 +0000 | [diff] [blame] | 1223 | timer has fired. These values are never used directly, but only in |
| 1224 | the macrose defined in this file. */ |
| 1225 | |
| 1226 | #define UIP_DATA 1 /* Tells uIP that there is incoming |
| 1227 | data in the uip_buf buffer. The |
| 1228 | length of the data is stored in the |
| 1229 | global variable uip_len. */ |
| 1230 | #define UIP_TIMER 2 /* Tells uIP that the periodic timer |
| 1231 | has fired. */ |
| 1232 | #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should |
| 1233 | be polled. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1234 | #if UIP_UDP |
adamdunkels | 3335cd9 | 2005-02-27 09:44:33 +0000 | [diff] [blame] | 1235 | #define UIP_UDP_TIMER 4 |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1236 | #endif /* UIP_UDP */ |
| 1237 | |
| 1238 | /* The TCP states used in the uip_conn->tcpstateflags. */ |
| 1239 | #define CLOSED 0 |
| 1240 | #define SYN_RCVD 1 |
| 1241 | #define SYN_SENT 2 |
| 1242 | #define ESTABLISHED 3 |
| 1243 | #define FIN_WAIT_1 4 |
| 1244 | #define FIN_WAIT_2 5 |
| 1245 | #define CLOSING 6 |
| 1246 | #define TIME_WAIT 7 |
| 1247 | #define LAST_ACK 8 |
| 1248 | #define TS_MASK 15 |
| 1249 | |
| 1250 | #define UIP_STOPPED 16 |
| 1251 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1252 | #define UIP_TCPIP_HLEN 40 |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1253 | |
adamdunkels | 0dd56df | 2005-03-09 10:21:04 +0000 | [diff] [blame] | 1254 | /** |
| 1255 | * The buffer size available for user data in the \ref uip_buf buffer. |
| 1256 | * |
| 1257 | * This macro holds the available size for user data in the \ref |
| 1258 | * uip_buf buffer. The macro is intended to be used for checking |
| 1259 | * bounds of available user data. |
| 1260 | * |
| 1261 | * Example: |
| 1262 | \code |
| 1263 | snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i); |
| 1264 | \endcode |
| 1265 | * |
| 1266 | * \hideinitializer |
| 1267 | */ |
| 1268 | #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) |
| 1269 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1270 | /* The TCP and IP headers. */ |
| 1271 | typedef struct { |
| 1272 | /* IP header. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1273 | u8_t vhl, |
| 1274 | tos, |
| 1275 | len[2], |
| 1276 | ipid[2], |
| 1277 | ipoffset[2], |
| 1278 | ttl, |
| 1279 | proto; |
| 1280 | u16_t ipchksum; |
| 1281 | u16_t srcipaddr[2], |
| 1282 | destipaddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1283 | |
| 1284 | /* TCP header. */ |
| 1285 | u16_t srcport, |
| 1286 | destport; |
| 1287 | u8_t seqno[4], |
| 1288 | ackno[4], |
| 1289 | tcpoffset, |
| 1290 | flags, |
| 1291 | wnd[2]; |
| 1292 | u16_t tcpchksum; |
| 1293 | u8_t urgp[2]; |
| 1294 | u8_t optdata[4]; |
| 1295 | } uip_tcpip_hdr; |
| 1296 | |
| 1297 | /* The ICMP and IP headers. */ |
| 1298 | typedef struct { |
| 1299 | /* IP header. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1300 | u8_t vhl, |
| 1301 | tos, |
| 1302 | len[2], |
| 1303 | ipid[2], |
| 1304 | ipoffset[2], |
| 1305 | ttl, |
| 1306 | proto; |
| 1307 | u16_t ipchksum; |
| 1308 | u16_t srcipaddr[2], |
| 1309 | destipaddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1310 | /* ICMP (echo) header. */ |
| 1311 | u8_t type, icode; |
| 1312 | u16_t icmpchksum; |
| 1313 | u16_t id, seqno; |
| 1314 | } uip_icmpip_hdr; |
| 1315 | |
| 1316 | |
| 1317 | /* The UDP and IP headers. */ |
| 1318 | typedef struct { |
| 1319 | /* IP header. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1320 | u8_t vhl, |
| 1321 | tos, |
| 1322 | len[2], |
| 1323 | ipid[2], |
| 1324 | ipoffset[2], |
| 1325 | ttl, |
| 1326 | proto; |
| 1327 | u16_t ipchksum; |
| 1328 | u16_t srcipaddr[2], |
| 1329 | destipaddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1330 | |
| 1331 | /* UDP header. */ |
| 1332 | u16_t srcport, |
| 1333 | destport; |
| 1334 | u16_t udplen; |
| 1335 | u16_t udpchksum; |
| 1336 | } uip_udpip_hdr; |
| 1337 | |
| 1338 | #define UIP_PROTO_ICMP 1 |
| 1339 | #define UIP_PROTO_TCP 6 |
| 1340 | #define UIP_PROTO_UDP 17 |
| 1341 | |
adamdunkels | 72a8303 | 2005-02-22 22:32:40 +0000 | [diff] [blame] | 1342 | /* Header sizes. */ |
| 1343 | #define UIP_IPH_LEN 20 /* Size of IP header */ |
| 1344 | #define UIP_UDPH_LEN 8 /* Size of UDP header */ |
| 1345 | #define UIP_TCPH_LEN 20 /* Size of TCP header */ |
| 1346 | #define UIP_IPUDPH_LEN 28 /* Size of IP + UDP header */ |
| 1347 | #define UIP_IPTCPH_LEN 40 /* Size of IP + TCP header */ |
| 1348 | |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1349 | |
| 1350 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1351 | #if UIP_FIXEDADDR |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1352 | extern const u16_t uip_hostaddr[2], uip_netmask[2], uip_draddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1353 | #else /* UIP_FIXEDADDR */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1354 | extern u16_t uip_hostaddr[2], uip_netmask[2], uip_draddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1355 | #endif /* UIP_FIXEDADDR */ |
| 1356 | |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1357 | |
| 1358 | |
adamdunkels | b380a3e | 2004-09-17 20:59:23 +0000 | [diff] [blame] | 1359 | /** |
| 1360 | * Representation of a 48-bit Ethernet address. |
| 1361 | */ |
| 1362 | struct uip_eth_addr { |
| 1363 | u8_t addr[6]; |
| 1364 | }; |
| 1365 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1366 | #endif /* __UIP_H__ */ |
| 1367 | |
| 1368 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1369 | /** @} */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1370 | |