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 | * |
adamdunkels | 72a8303 | 2005-02-22 22:32:40 +0000 | [diff] [blame^] | 48 | * $Id: uip.h,v 1.15 2005/02/22 22:32:40 adamdunkels 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 | /** |
| 270 | * Periodic processing for a connection identified by a pointer to its structure. |
| 271 | * |
| 272 | * Same as uip_periodic() but takes a pointer to the actual uip_conn |
| 273 | * struct instead of an integer as its argument. This function can be |
| 274 | * used to force periodic processing of a specific connection. |
| 275 | * |
| 276 | * \param conn A pointer to the uip_conn struct for the connection to |
| 277 | * be processed. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 278 | * |
| 279 | * \hideinitializer |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 280 | */ |
| 281 | #define uip_periodic_conn(conn) do { uip_conn = conn; \ |
| 282 | uip_process(UIP_TIMER); } while (0) |
| 283 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 284 | #if UIP_UDP |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 285 | /** |
| 286 | * Periodic processing for a UDP connection identified by its number. |
| 287 | * |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 288 | * This function is essentially the same as uip_periodic(), but for |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 289 | * UDP connections. It is called in a similar fashion as the |
| 290 | * uip_periodic() function: |
| 291 | \code |
| 292 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
| 293 | uip_udp_periodic(i); |
| 294 | if(uip_len > 0) { |
| 295 | devicedriver_send(); |
| 296 | } |
| 297 | } |
| 298 | \endcode |
| 299 | * |
| 300 | * \note As for the uip_periodic() function, special care has to be |
| 301 | * taken when using uIP together with ARP and Ethernet: |
| 302 | \code |
| 303 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
| 304 | uip_udp_periodic(i); |
| 305 | if(uip_len > 0) { |
| 306 | uip_arp_out(); |
| 307 | ethernet_devicedriver_send(); |
| 308 | } |
| 309 | } |
| 310 | \endcode |
| 311 | * |
| 312 | * \param conn The number of the UDP connection to be processed. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 313 | * |
| 314 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 315 | */ |
| 316 | #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ |
| 317 | uip_process(UIP_UDP_TIMER); } while (0) |
adamdunkels | eb91d5f | 2003-08-20 20:58:08 +0000 | [diff] [blame] | 318 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 319 | /** |
| 320 | * Periodic processing for a UDP connection identified by a pointer to |
| 321 | * its structure. |
| 322 | * |
| 323 | * Same as uip_udp_periodic() but takes a pointer to the actual |
| 324 | * uip_conn struct instead of an integer as its argument. This |
| 325 | * function can be used to force periodic processing of a specific |
| 326 | * connection. |
| 327 | * |
| 328 | * \param conn A pointer to the uip_udp_conn struct for the connection |
| 329 | * to be processed. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 330 | * |
| 331 | * \hideinitializer |
adamdunkels | eb91d5f | 2003-08-20 20:58:08 +0000 | [diff] [blame] | 332 | */ |
| 333 | #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ |
| 334 | uip_process(UIP_UDP_TIMER); } while (0) |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 335 | |
| 336 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 337 | #endif /* UIP_UDP */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 338 | |
| 339 | /** |
| 340 | * The uIP packet buffer. |
| 341 | * |
| 342 | * The uip_buf array is used to hold incoming and outgoing |
| 343 | * packets. The device driver should place incoming data into this |
| 344 | * buffer. When sending data, the device driver should read the link |
| 345 | * level headers and the TCP/IP headers from this buffer. The size of |
| 346 | * the link level headers is configured by the UIP_LLH_LEN define. |
| 347 | * |
| 348 | * \note The application data need not be placed in this buffer, so |
| 349 | * the device driver must read it from the place pointed to by the |
| 350 | * uip_appdata pointer as illustrated by the following example: |
| 351 | \code |
| 352 | void |
| 353 | devicedriver_send(void) |
| 354 | { |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 355 | hwsend(&uip_buf[0], UIP_LLH_LEN); |
| 356 | if(uip_len <= UIP_LLH_LEN + 40) { |
| 357 | hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN); |
| 358 | } else { |
| 359 | hwsend(&uip_buf[UIP_LLH_LEN], 40); |
| 360 | hwsend(uip_appdata, uip_len - 40 - UIP_LLH_LEN); |
| 361 | } |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 362 | } |
| 363 | \endcode |
| 364 | */ |
| 365 | extern u8_t uip_buf[UIP_BUFSIZE+2]; |
| 366 | |
| 367 | /** @} */ |
| 368 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 369 | /*-----------------------------------------------------------------------------------*/ |
| 370 | /* Functions that are used by the uIP application program. Opening and |
| 371 | * closing connections, sending and receiving data, etc. is all |
| 372 | * handled by the functions below. |
| 373 | */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 374 | /** |
| 375 | * \defgroup uipappfunc uIP application functions |
| 376 | * @{ |
| 377 | * |
| 378 | * Functions used by an application running of top of uIP. |
| 379 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 380 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 381 | /** |
| 382 | * Start listening to the specified port. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 383 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 384 | * \note Since this function expects the port number in network byte |
| 385 | * order, a conversion using HTONS() or htons() is necessary. |
| 386 | * |
| 387 | \code |
| 388 | uip_listen(HTONS(80)); |
| 389 | \endcode |
| 390 | * |
| 391 | * \param port A 16-bit port number in network byte order. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 392 | */ |
| 393 | void uip_listen(u16_t port); |
| 394 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 395 | /** |
| 396 | * Stop listening to the specified port. |
adamdunkels | cd8c3a2 | 2003-08-13 22:52:48 +0000 | [diff] [blame] | 397 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 398 | * \note Since this function expects the port number in network byte |
| 399 | * order, a conversion using HTONS() or htons() is necessary. |
| 400 | * |
| 401 | \code |
| 402 | uip_unlisten(HTONS(80)); |
| 403 | \endcode |
| 404 | * |
| 405 | * \param port A 16-bit port number in network byte order. |
adamdunkels | cd8c3a2 | 2003-08-13 22:52:48 +0000 | [diff] [blame] | 406 | */ |
| 407 | void uip_unlisten(u16_t port); |
| 408 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 409 | /** |
| 410 | * Connect to a remote host using TCP. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 411 | * |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 412 | * This function is used to start a new connection to the specified |
| 413 | * port on the specied host. It allocates a new connection identifier, |
| 414 | * sets the connection to the SYN_SENT state and sets the |
| 415 | * retransmission timer to 0. This will cause a TCP SYN segment to be |
| 416 | * sent out the next time this connection is periodically processed, |
| 417 | * which usually is done within 0.5 seconds after the call to |
| 418 | * uip_connect(). |
| 419 | * |
| 420 | * \note This function is avaliable only if support for active open |
| 421 | * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. |
| 422 | * |
| 423 | * \note Since this function requires the port number to be in network |
adamdunkels | 7461bcb | 2005-02-07 07:00:54 +0000 | [diff] [blame] | 424 | * byte order, a conversion using HTONS() or htons() is necessary. |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 425 | * |
| 426 | \code |
| 427 | u16_t ipaddr[2]; |
| 428 | |
| 429 | uip_ipaddr(ipaddr, 192,168,1,2); |
| 430 | uip_connect(ipaddr, HTONS(80)); |
| 431 | \endcode |
| 432 | * |
| 433 | * \param ripaddr A pointer to a 4-byte array representing the IP |
| 434 | * address of the remote hot. |
| 435 | * |
| 436 | * \param port A 16-bit port number in network byte order. |
| 437 | * |
| 438 | * \return A pointer to the uIP connection identifier for the new connection, |
| 439 | * or NULL if no connection could be allocated. |
| 440 | * |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 441 | */ |
| 442 | struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port); |
| 443 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 444 | |
| 445 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 446 | /** |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 447 | * \internal |
| 448 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 449 | * Check if a connection has outstanding (i.e., unacknowledged) data. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 450 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 451 | * \param conn A pointer to the uip_conn structure for the connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 452 | * |
| 453 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 454 | */ |
| 455 | #define uip_outstanding(conn) ((conn)->len) |
| 456 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 457 | /** |
| 458 | * Send data on the current connection. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 459 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 460 | * This function is used to send out a single segment of TCP |
| 461 | * data. Only applications that have been invoked by uIP for event |
| 462 | * processing can send data. |
| 463 | * |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 464 | * The amount of data that actually is sent out after a call to this |
| 465 | * funcion is determined by the maximum amount of data TCP allows. uIP |
| 466 | * will automatically crop the data so that only the appropriate |
| 467 | * amount of data is sent. The function uip_mss() can be used to query |
| 468 | * uIP for the amount of data that actually will be sent. |
| 469 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 470 | * \note This function does not guarantee that the sent data will |
| 471 | * arrive at the destination. If the data is lost in the network, the |
| 472 | * application will be invoked with the uip_rexmit() event being |
| 473 | * set. The application will then have to resend the data using this |
| 474 | * function. |
| 475 | * |
| 476 | * \param data A pointer to the data which is to be sent. |
| 477 | * |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 478 | * \param len The maximum amount of data bytes to be sent. |
| 479 | * |
| 480 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 481 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 482 | #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] | 483 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 484 | /** |
| 485 | * The length of any incoming data that is currently avaliable (if avaliable) |
| 486 | * in the uip_appdata buffer. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 487 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 488 | * The test function uip_data() must first be used to check if there |
| 489 | * is any data available at all. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 490 | * |
| 491 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 492 | */ |
| 493 | #define uip_datalen() uip_len |
| 494 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 495 | /** |
| 496 | * The length of any out-of-band data (urgent data) that has arrived |
| 497 | * on the connection. |
| 498 | * |
| 499 | * \note The configuration parameter UIP_URGDATA must be set for this |
| 500 | * function to be enabled. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 501 | * |
| 502 | * \hideinitializer |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 503 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 504 | #define uip_urgdatalen() uip_urglen |
| 505 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 506 | /** |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 507 | * Close the current connection. |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 508 | * |
| 509 | * This function will close the current connection in a nice way. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 510 | * |
| 511 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 512 | */ |
| 513 | #define uip_close() (uip_flags = UIP_CLOSE) |
| 514 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 515 | /** |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 516 | * Abort the current connection. |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 517 | * |
| 518 | * This function will abort (reset) the current connection, and is |
| 519 | * usually used when an error has occured that prevents using the |
| 520 | * uip_close() function. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 521 | * |
| 522 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 523 | */ |
| 524 | #define uip_abort() (uip_flags = UIP_ABORT) |
| 525 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 526 | /** |
| 527 | * Tell the sending host to stop sending data. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 528 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 529 | * This function will close our receiver's window so that we stop |
| 530 | * receiving data for the current connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 531 | * |
| 532 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 533 | */ |
| 534 | #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) |
| 535 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 536 | /** |
| 537 | * Find out if the current connection has been previously stopped with |
| 538 | * uip_stop(). |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 539 | * |
| 540 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 541 | */ |
| 542 | #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) |
| 543 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 544 | /** |
| 545 | * Restart the current connection, if is has previously been stopped |
| 546 | * with uip_stop(). |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 547 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 548 | * This function will open the receiver's window again so that we |
| 549 | * start receiving data for the current connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 550 | * |
| 551 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 552 | */ |
| 553 | #define uip_restart() do { uip_flags |= UIP_NEWDATA; \ |
| 554 | uip_conn->tcpstateflags &= ~UIP_STOPPED; \ |
| 555 | } while(0) |
| 556 | |
| 557 | |
| 558 | /* uIP tests that can be made to determine in what state the current |
| 559 | connection is, and what the application function should do. */ |
| 560 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 561 | /** |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 562 | * Is the current connection a UDP connection? |
| 563 | * |
| 564 | * This function checks whether the current connection is a UDP connection. |
| 565 | * |
| 566 | * \hideinitializer |
| 567 | * |
| 568 | */ |
| 569 | #define uip_udpconnection() (uip_conn == NULL) |
| 570 | |
| 571 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 572 | * Is new incoming data available? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 573 | * |
| 574 | * Will reduce to non-zero if there is new data for the application |
| 575 | * present at the uip_appdata pointer. The size of the data is |
| 576 | * avaliable through the uip_len variable. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 577 | * |
| 578 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 579 | */ |
| 580 | #define uip_newdata() (uip_flags & UIP_NEWDATA) |
| 581 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 582 | /** |
| 583 | * Has previously sent data been acknowledged? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 584 | * |
| 585 | * Will reduce to non-zero if the previously sent data has been |
| 586 | * acknowledged by the remote host. This means that the application |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 587 | * can send new data. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 588 | * |
| 589 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 590 | */ |
| 591 | #define uip_acked() (uip_flags & UIP_ACKDATA) |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 592 | |
| 593 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 594 | * Has the connection just been connected? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 595 | * |
| 596 | * Reduces to non-zero if the current connection has been connected to |
| 597 | * a remote host. This will happen both if the connection has been |
| 598 | * actively opened (with uip_connect()) or passively opened (with |
| 599 | * uip_listen()). |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 600 | * |
| 601 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 602 | */ |
| 603 | #define uip_connected() (uip_flags & UIP_CONNECTED) |
| 604 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 605 | /** |
| 606 | * Has the connection been closed by the other end? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 607 | * |
| 608 | * Is non-zero if the connection has been closed by the remote |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 609 | * host. The application may then do the necessary clean-ups. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 610 | * |
| 611 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 612 | */ |
| 613 | #define uip_closed() (uip_flags & UIP_CLOSE) |
| 614 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 615 | /** |
| 616 | * Has the connection been aborted by the other end? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 617 | * |
| 618 | * Non-zero if the current connection has been aborted (reset) by the |
| 619 | * remote host. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 620 | * |
| 621 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 622 | */ |
| 623 | #define uip_aborted() (uip_flags & UIP_ABORT) |
| 624 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 625 | /** |
| 626 | * Has the connection timed out? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 627 | * |
| 628 | * Non-zero if the current connection has been aborted due to too many |
| 629 | * retransmissions. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 630 | * |
| 631 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 632 | */ |
adamdunkels | 399a078 | 2004-02-16 20:52:07 +0000 | [diff] [blame] | 633 | #define uip_timedout() (uip_flags & UIP_TIMEDOUT) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 634 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 635 | /** |
| 636 | * Do we need to retransmit previously data? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 637 | * |
| 638 | * Reduces to non-zero if the previously sent data has been lost in |
| 639 | * the network, and the application should retransmit it. The |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 640 | * application should send the exact same data as it did the last |
| 641 | * time, using the uip_send() function. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 642 | * |
| 643 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 644 | */ |
| 645 | #define uip_rexmit() (uip_flags & UIP_REXMIT) |
| 646 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 647 | /** |
| 648 | * Is the connection being polled by uIP? |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 649 | * |
| 650 | * Is non-zero if the reason the application is invoked is that the |
| 651 | * current connection has been idle for a while and should be |
| 652 | * polled. |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 653 | * |
| 654 | * The polling event can be used for sending data without having to |
| 655 | * wait for the remote host to send data. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 656 | * |
| 657 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 658 | */ |
| 659 | #define uip_poll() (uip_flags & UIP_POLL) |
| 660 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 661 | /** |
| 662 | * Get the initial maxium segment size (MSS) of the current |
| 663 | * connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 664 | * |
| 665 | * \hideinitializer |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 666 | */ |
| 667 | #define uip_initialmss() (uip_conn->initialmss) |
| 668 | |
| 669 | /** |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 670 | * Get the current maxium segment size that can be sent on the current |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 671 | * connection. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 672 | * |
| 673 | * The current maxiumum segment size that can be sent on the |
| 674 | * connection is computed from the receiver's window and the MSS of |
| 675 | * the connection (which also is available by calling |
| 676 | * uip_initialmss()). |
| 677 | * |
| 678 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 679 | */ |
| 680 | #define uip_mss() (uip_conn->mss) |
| 681 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 682 | /** |
| 683 | * Set up a new UDP connection. |
| 684 | * |
| 685 | * \param ripaddr A pointer to a 4-byte structure representing the IP |
| 686 | * address of the remote host. |
| 687 | * |
| 688 | * \param rport The remote port number in network byte order. |
| 689 | * |
| 690 | * \return The uip_udp_conn structure for the new connection or NULL |
| 691 | * if no connection could be allocated. |
| 692 | */ |
| 693 | struct uip_udp_conn *uip_udp_new(u16_t *ripaddr, u16_t rport); |
| 694 | |
| 695 | /** |
| 696 | * Removed a UDP connection. |
| 697 | * |
| 698 | * \param conn A pointer to the uip_udp_conn structure for the connection. |
| 699 | * |
| 700 | * \hideinitializer |
| 701 | */ |
| 702 | #define uip_udp_remove(conn) (conn)->lport = 0 |
| 703 | |
| 704 | /** |
adamdunkels | 37f0b8d | 2004-07-04 17:00:50 +0000 | [diff] [blame] | 705 | * Bind a UDP connection to a local port. |
| 706 | * |
| 707 | * \param conn A pointer to the uip_udp_conn structure for the |
| 708 | * connection. |
| 709 | * |
| 710 | * \param port The local port number, in network byte order. |
| 711 | * |
| 712 | * \hideinitializer |
| 713 | */ |
| 714 | #define uip_udp_bind(conn, port) (conn)->lport = port |
| 715 | |
| 716 | /** |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 717 | * Send a UDP datagram of length len on the current connection. |
| 718 | * |
| 719 | * This function can only be called in response to a UDP event (poll |
| 720 | * or newdata). The data must be present in the uip_buf buffer, at the |
| 721 | * place pointed to by the uip_appdata pointer. |
| 722 | * |
| 723 | * \param len The length of the data in the uip_buf buffer. |
| 724 | * |
| 725 | * \hideinitializer |
| 726 | */ |
| 727 | #define uip_udp_send(len) uip_slen = (len) |
| 728 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 729 | /** @} */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 730 | |
| 731 | /* uIP convenience and converting functions. */ |
| 732 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 733 | /** |
| 734 | * \defgroup uipconvfunc uIP conversion functions |
| 735 | * @{ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 736 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 737 | * These functions can be used for converting between different data |
| 738 | * formats used by uIP. |
| 739 | */ |
| 740 | |
| 741 | /** |
| 742 | * Pack an IP address into a 4-byte array which is used by uIP to |
| 743 | * represent IP addresses. |
| 744 | * |
| 745 | * Example: |
| 746 | \code |
| 747 | u16_t ipaddr[2]; |
| 748 | |
| 749 | uip_ipaddr(&ipaddr, 192,168,1,2); |
| 750 | \endcode |
| 751 | * |
| 752 | * \param addr A pointer to a 4-byte array that will be filled in with |
| 753 | * the IP addres. |
| 754 | * \param addr0 The first octet of the IP address. |
| 755 | * \param addr1 The second octet of the IP address. |
| 756 | * \param addr2 The third octet of the IP address. |
| 757 | * \param addr3 The forth octet of the IP address. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 758 | * |
| 759 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 760 | */ |
| 761 | #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 762 | ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ |
| 763 | ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 764 | } while(0) |
| 765 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 766 | /** |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 767 | * Copy an IP address to another IP address. |
| 768 | * |
| 769 | * Copies an IP address from one place to another. |
| 770 | * |
| 771 | * Example: |
| 772 | \code |
| 773 | u16_t ipaddr1[2], ipaddr2[2]; |
| 774 | |
| 775 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 776 | uip_ipaddr_copy(ipaddr2, ipaddr1); |
| 777 | \endcode |
| 778 | * |
| 779 | * \param dest The destination for the copy. |
| 780 | * \param src The source from where to copy. |
| 781 | * |
| 782 | * \hideinitializer |
| 783 | */ |
| 784 | #define uip_ipaddr_copy(dest, src) do { \ |
| 785 | ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \ |
| 786 | ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \ |
| 787 | } while(0) |
| 788 | /** |
| 789 | * Compare two IP addresses |
| 790 | * |
| 791 | * Compares two IP addresses. |
| 792 | * |
| 793 | * Example: |
| 794 | \code |
| 795 | u16_t ipaddr1[2], ipaddr2[2]; |
| 796 | |
| 797 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 798 | if(uip_ipaddr_cmp(ipaddr2, ipaddr1)) { |
| 799 | printf("They are the same"); |
| 800 | } |
| 801 | \endcode |
| 802 | * |
| 803 | * \param addr1 The first IP address. |
| 804 | * \param addr2 The second IP address. |
| 805 | * |
| 806 | * \hideinitializer |
| 807 | */ |
| 808 | #define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \ |
| 809 | ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1]) |
| 810 | |
| 811 | /** |
| 812 | * Compare two IP addresses with netmasks |
| 813 | * |
| 814 | * Compares two IP addresses with netmasks. The masks are used to mask |
| 815 | * out the bits that are to be compared. |
| 816 | * |
| 817 | * Example: |
| 818 | \code |
| 819 | u16_t ipaddr1[2], ipaddr2[2], mask[2]; |
| 820 | |
| 821 | uip_ipaddr(mask, 255,255,255,0); |
| 822 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 823 | uip_ipaddr(ipaddr2, 192,16,1,3); |
| 824 | if(uip_ipaddr_maskcmp(ipaddr1, ipaddr2, mask)) { |
| 825 | printf("They are the same"); |
| 826 | } |
| 827 | \endcode |
| 828 | * |
| 829 | * \param addr1 The first IP address. |
| 830 | * \param addr2 The second IP address. |
| 831 | * \param mask The netmask. |
| 832 | * |
| 833 | * \hideinitializer |
| 834 | */ |
| 835 | #define uip_ipaddr_maskcmp(addr1, addr2, mask) \ |
| 836 | (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \ |
| 837 | (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \ |
| 838 | ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \ |
| 839 | (((u16_t *)addr2)[1] & ((u16_t *)mask)[1]))) |
| 840 | |
| 841 | |
| 842 | /** |
| 843 | * Mask out the network part of an IP address. |
| 844 | * |
| 845 | * Masks out the network part of an IP address, given the address and |
| 846 | * the netmask. |
| 847 | * |
| 848 | * Example: |
| 849 | \code |
| 850 | u16_t ipaddr1[2], ipaddr2[2], netmask[2]; |
| 851 | |
| 852 | uip_ipaddr(ipaddr1, 192,16,1,2); |
| 853 | uip_ipaddr(netmask, 255,255,255,0); |
| 854 | uip_ipaddr_mask(ipaddr2, ipaddr1, netmask); |
| 855 | \endcode |
| 856 | * |
| 857 | * In the example above, the variable "ipaddr2" will contain the IP |
| 858 | * address 192.168.1.0. |
| 859 | * |
| 860 | * \param dest Where the result is to be placed. |
| 861 | * \param src The IP address. |
| 862 | * \param mask The netmask. |
| 863 | * |
| 864 | * \hideinitializer |
| 865 | */ |
| 866 | #define uip_ipaddr_mask(dest, src, mask) do { \ |
| 867 | ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \ |
| 868 | ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \ |
| 869 | } while(0) |
| 870 | |
| 871 | /** |
| 872 | * Pick the first octet of an IP address. |
| 873 | * |
| 874 | * Picks out the first octet of an IP address. |
| 875 | * |
| 876 | * Example: |
| 877 | \code |
| 878 | u16_t ipaddr[2]; |
| 879 | u8_t octet; |
| 880 | |
| 881 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 882 | octet = uip_ipaddr1(ipaddr); |
| 883 | \endcode |
| 884 | * |
| 885 | * In the example above, the variable "octet" will contain the value 1. |
| 886 | * |
| 887 | * \hideinitializer |
| 888 | */ |
| 889 | #define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8) |
| 890 | |
| 891 | /** |
| 892 | * Pick the second octet of an IP address. |
| 893 | * |
| 894 | * Picks out the second octet of an IP address. |
| 895 | * |
| 896 | * Example: |
| 897 | \code |
| 898 | u16_t ipaddr[2]; |
| 899 | u8_t octet; |
| 900 | |
| 901 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 902 | octet = uip_ipaddr2(ipaddr); |
| 903 | \endcode |
| 904 | * |
| 905 | * In the example above, the variable "octet" will contain the value 2. |
| 906 | * |
| 907 | * \hideinitializer |
| 908 | */ |
| 909 | #define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff) |
| 910 | |
| 911 | /** |
| 912 | * Pick the third octet of an IP address. |
| 913 | * |
| 914 | * Picks out the third octet of an IP address. |
| 915 | * |
| 916 | * Example: |
| 917 | \code |
| 918 | u16_t ipaddr[2]; |
| 919 | u8_t octet; |
| 920 | |
| 921 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 922 | octet = uip_ipaddr3(ipaddr); |
| 923 | \endcode |
| 924 | * |
| 925 | * In the example above, the variable "octet" will contain the value 3. |
| 926 | * |
| 927 | * \hideinitializer |
| 928 | */ |
| 929 | #define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8) |
| 930 | |
| 931 | /** |
| 932 | * Pick the fourth octet of an IP address. |
| 933 | * |
| 934 | * Picks out the fourth octet of an IP address. |
| 935 | * |
| 936 | * Example: |
| 937 | \code |
| 938 | u16_t ipaddr[2]; |
| 939 | u8_t octet; |
| 940 | |
| 941 | uip_ipaddr(ipaddr, 1,2,3,4); |
| 942 | octet = uip_ipaddr4(ipaddr); |
| 943 | \endcode |
| 944 | * |
| 945 | * In the example above, the variable "octet" will contain the value 4. |
| 946 | * |
| 947 | * \hideinitializer |
| 948 | */ |
| 949 | #define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff) |
| 950 | |
| 951 | /** |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 952 | * Convert 16-bit quantity from host byte order to network byte order. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 953 | * |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 954 | * This macro is primarily used for converting constants from host |
| 955 | * byte order to network byte order. For converting variables to |
| 956 | * network byte order, use the htons() function instead. |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 957 | * |
| 958 | * \hideinitializer |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 959 | */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 960 | #ifndef HTONS |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 961 | # if BYTE_ORDER == BIG_ENDIAN |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 962 | # define HTONS(n) (n) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 963 | # else /* BYTE_ORDER == BIG_ENDIAN */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 964 | # define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8)) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 965 | # endif /* BYTE_ORDER == BIG_ENDIAN */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 966 | #endif /* HTONS */ |
| 967 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 968 | /** |
| 969 | * Convert 16-bit quantity from host byte order to network byte order. |
| 970 | * |
| 971 | * This function is primarily used for converting variables from host |
| 972 | * byte order to network byte order. For converting constants to |
| 973 | * network byte order, use the HTONS() macro instead. |
| 974 | */ |
adamdunkels | 47ec7fa | 2003-03-28 12:11:17 +0000 | [diff] [blame] | 975 | #ifndef htons |
| 976 | u16_t htons(u16_t val); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 977 | #endif /* htons */ |
| 978 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 979 | /** @} */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 980 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 981 | /** |
| 982 | * Pointer to the application data in the packet buffer. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 983 | * |
| 984 | * This pointer points to the application data when the application is |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 985 | * called. If the application wishes to send data, the application may |
| 986 | * use this space to write the data into before calling uip_send(). |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 987 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 988 | extern u8_t *uip_appdata; |
| 989 | extern u8_t *uip_sappdata; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 990 | |
| 991 | #if UIP_URGDATA > 0 |
| 992 | /* u8_t *uip_urgdata: |
| 993 | * |
| 994 | * This pointer points to any urgent data that has been received. Only |
| 995 | * present if compiled with support for urgent data (UIP_URGDATA). |
| 996 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 997 | extern u8_t *uip_urgdata; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 998 | #endif /* UIP_URGDATA > 0 */ |
| 999 | |
| 1000 | |
| 1001 | /* u[8|16]_t uip_len: |
| 1002 | * |
| 1003 | * When the application is called, uip_len contains the length of any |
| 1004 | * new data that has been received from the remote host. The |
| 1005 | * application should set this variable to the size of any data that |
| 1006 | * the application wishes to send. When the network device driver |
| 1007 | * output function is called, uip_len should contain the length of the |
| 1008 | * outgoing packet. |
| 1009 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1010 | extern u16_t uip_len, uip_slen; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1011 | |
| 1012 | #if UIP_URGDATA > 0 |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1013 | extern u8_t uip_urglen, uip_surglen; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1014 | #endif /* UIP_URGDATA > 0 */ |
| 1015 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1016 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1017 | /** |
| 1018 | * Representation of a uIP TCP connection. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1019 | * |
| 1020 | * The uip_conn structure is used for identifying a connection. All |
| 1021 | * but one field in the structure are to be considered read-only by an |
| 1022 | * application. The only exception is the appstate field whos purpose |
| 1023 | * is to let the application store application-specific state (e.g., |
| 1024 | * file pointers) for the connection. The size of this field is |
| 1025 | * configured in the "uipopt.h" header file. |
| 1026 | */ |
| 1027 | struct uip_conn { |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1028 | u16_t ripaddr[2]; /**< The IP address of the remote host. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1029 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1030 | u16_t lport; /**< The local TCP port, in network byte order. */ |
| 1031 | u16_t rport; /**< The local remote TCP port, in network byte |
| 1032 | order. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1033 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1034 | u8_t rcv_nxt[4]; /**< The sequence number that we expect to |
| 1035 | receive next. */ |
| 1036 | u8_t snd_nxt[4]; /**< The sequence number that was last sent by |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1037 | us. */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1038 | u16_t len; /**< Length of the data that was previously sent. */ |
| 1039 | u16_t mss; /**< Current maximum segment size for the |
| 1040 | connection. */ |
| 1041 | u16_t initialmss; /**< Initial maximum segment size for the |
| 1042 | connection. */ |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1043 | u8_t sa; /**< Retransmission time-out calculation state |
| 1044 | variable. */ |
| 1045 | u8_t sv; /**< Retransmission time-out calculation state |
| 1046 | variable. */ |
| 1047 | u8_t rto; /**< Retransmission time-out. */ |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1048 | u8_t tcpstateflags; /**< TCP state and flags. */ |
| 1049 | u8_t timer; /**< The retransmission timer. */ |
| 1050 | u8_t nrtx; /**< The number of retransmissions for the last |
| 1051 | segment sent. */ |
| 1052 | |
| 1053 | /** The application state. */ |
| 1054 | u8_t appstate[UIP_APPSTATE_SIZE]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1055 | }; |
| 1056 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1057 | |
| 1058 | /* Pointer to the current connection. */ |
| 1059 | extern struct uip_conn *uip_conn; |
| 1060 | /* The array containing all uIP connections. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1061 | extern struct uip_conn uip_conns[UIP_CONNS]; |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1062 | /** |
| 1063 | * \addtogroup uiparch |
| 1064 | * @{ |
| 1065 | */ |
| 1066 | |
| 1067 | /** |
| 1068 | * 4-byte array used for the 32-bit sequence number calculations. |
| 1069 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1070 | extern u8_t uip_acc32[4]; |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1071 | |
| 1072 | /** @} */ |
| 1073 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1074 | |
| 1075 | #if UIP_UDP |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 1076 | /** |
| 1077 | * Representation of a uIP UDP connection. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1078 | */ |
| 1079 | struct uip_udp_conn { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1080 | u16_t ripaddr[2]; /**< The IP address of the remote peer. */ |
| 1081 | u16_t lport; /**< The local port number in network byte order. */ |
| 1082 | u16_t rport; /**< The remote port number in network byte order. */ |
adamdunkels | 399a078 | 2004-02-16 20:52:07 +0000 | [diff] [blame] | 1083 | |
| 1084 | /** The application state. */ |
| 1085 | u8_t appstate[UIP_APPSTATE_SIZE]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1086 | }; |
| 1087 | |
| 1088 | extern struct uip_udp_conn *uip_udp_conn; |
| 1089 | extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; |
| 1090 | #endif /* UIP_UDP */ |
| 1091 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1092 | /** |
| 1093 | * The structure holding the TCP/IP statistics that are gathered if |
| 1094 | * UIP_STATISTICS is set to 1. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1095 | * |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1096 | */ |
| 1097 | struct uip_stats { |
| 1098 | struct { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1099 | uip_stats_t drop; /**< Number of dropped packets at the IP |
| 1100 | layer. */ |
| 1101 | uip_stats_t recv; /**< Number of received packets at the IP |
| 1102 | layer. */ |
| 1103 | uip_stats_t sent; /**< Number of sent packets at the IP |
| 1104 | layer. */ |
| 1105 | uip_stats_t vhlerr; /**< Number of packets dropped due to wrong |
| 1106 | IP version or header length. */ |
| 1107 | uip_stats_t hblenerr; /**< Number of packets dropped due to wrong |
| 1108 | IP length, high byte. */ |
| 1109 | uip_stats_t lblenerr; /**< Number of packets dropped due to wrong |
| 1110 | IP length, low byte. */ |
| 1111 | uip_stats_t fragerr; /**< Number of packets dropped since they |
| 1112 | were IP fragments. */ |
| 1113 | uip_stats_t chkerr; /**< Number of packets dropped due to IP |
| 1114 | checksum errors. */ |
| 1115 | uip_stats_t protoerr; /**< Number of packets dropped since they |
| 1116 | were neither ICMP, UDP nor TCP. */ |
| 1117 | } ip; /**< IP statistics. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1118 | struct { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1119 | uip_stats_t drop; /**< Number of dropped ICMP packets. */ |
| 1120 | uip_stats_t recv; /**< Number of received ICMP packets. */ |
| 1121 | uip_stats_t sent; /**< Number of sent ICMP packets. */ |
| 1122 | uip_stats_t typeerr; /**< Number of ICMP packets with a wrong |
| 1123 | type. */ |
| 1124 | } icmp; /**< ICMP statistics. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1125 | struct { |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1126 | uip_stats_t drop; /**< Number of dropped TCP segments. */ |
| 1127 | uip_stats_t recv; /**< Number of recived TCP segments. */ |
| 1128 | uip_stats_t sent; /**< Number of sent TCP segments. */ |
| 1129 | uip_stats_t chkerr; /**< Number of TCP segments with a bad |
| 1130 | checksum. */ |
| 1131 | uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK |
| 1132 | number. */ |
| 1133 | uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */ |
| 1134 | uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ |
| 1135 | uip_stats_t syndrop; /**< Number of dropped SYNs due to too few |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1136 | connections was avaliable. */ |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1137 | uip_stats_t synrst; /**< Number of SYNs for closed ports, |
| 1138 | triggering a RST. */ |
| 1139 | } tcp; /**< TCP statistics. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1140 | }; |
| 1141 | |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 1142 | /** |
| 1143 | * The uIP TCP/IP statistics. |
| 1144 | * |
| 1145 | * This is the variable in which the uIP TCP/IP statistics are gathered. |
| 1146 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1147 | extern struct uip_stats uip_stat; |
| 1148 | |
| 1149 | |
| 1150 | /*-----------------------------------------------------------------------------------*/ |
| 1151 | /* All the stuff below this point is internal to uIP and should not be |
| 1152 | * used directly by an application or by a device driver. |
| 1153 | */ |
| 1154 | /*-----------------------------------------------------------------------------------*/ |
| 1155 | /* u8_t uip_flags: |
| 1156 | * |
| 1157 | * When the application is called, uip_flags will contain the flags |
| 1158 | * that are defined in this file. Please read below for more |
| 1159 | * infomation. |
| 1160 | */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1161 | extern u8_t uip_flags; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1162 | |
| 1163 | /* The following flags may be set in the global variable uip_flags |
| 1164 | before calling the application callback. The UIP_ACKDATA and |
| 1165 | UIP_NEWDATA flags may both be set at the same time, whereas the |
| 1166 | others are mutualy exclusive. Note that these flags should *NOT* be |
| 1167 | accessed directly, but through the uIP functions/macros. */ |
| 1168 | |
| 1169 | #define UIP_ACKDATA 1 /* Signifies that the outstanding data was |
| 1170 | acked and the application should send |
| 1171 | out new data instead of retransmitting |
| 1172 | the last data. */ |
| 1173 | #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent |
| 1174 | us new data. */ |
| 1175 | #define UIP_REXMIT 4 /* Tells the application to retransmit the |
| 1176 | data that was last sent. */ |
| 1177 | #define UIP_POLL 8 /* Used for polling the application, to |
| 1178 | check if the application has data that |
| 1179 | it wants to send. */ |
| 1180 | #define UIP_CLOSE 16 /* The remote host has closed the |
| 1181 | connection, thus the connection has |
| 1182 | gone away. Or the application signals |
| 1183 | that it wants to close the |
| 1184 | connection. */ |
| 1185 | #define UIP_ABORT 32 /* The remote host has aborted the |
| 1186 | connection, thus the connection has |
| 1187 | gone away. Or the application signals |
| 1188 | that it wants to abort the |
| 1189 | connection. */ |
| 1190 | #define UIP_CONNECTED 64 /* We have got a connection from a remote |
| 1191 | host and have set up a new connection |
| 1192 | for it, or an active connection has |
| 1193 | been successfully established. */ |
| 1194 | |
| 1195 | #define UIP_TIMEDOUT 128 /* The connection has been aborted due to |
| 1196 | too many retransmissions. */ |
| 1197 | |
| 1198 | |
| 1199 | /* uip_process(flag): |
| 1200 | * |
| 1201 | * The actual uIP function which does all the work. |
| 1202 | */ |
| 1203 | void uip_process(u8_t flag); |
| 1204 | |
| 1205 | /* The following flags are passed as an argument to the uip_process() |
| 1206 | function. They are used to distinguish between the two cases where |
| 1207 | uip_process() is called. It can be called either because we have |
| 1208 | incoming data that should be processed, or because the periodic |
| 1209 | timer has fired. */ |
| 1210 | |
| 1211 | #define UIP_DATA 1 /* Tells uIP that there is incoming data in |
| 1212 | the uip_buf buffer. The length of the |
| 1213 | data is stored in the global variable |
| 1214 | uip_len. */ |
| 1215 | #define UIP_TIMER 2 /* Tells uIP that the periodic timer has |
| 1216 | fired. */ |
| 1217 | #if UIP_UDP |
| 1218 | #define UIP_UDP_TIMER 3 |
| 1219 | #endif /* UIP_UDP */ |
| 1220 | |
| 1221 | /* The TCP states used in the uip_conn->tcpstateflags. */ |
| 1222 | #define CLOSED 0 |
| 1223 | #define SYN_RCVD 1 |
| 1224 | #define SYN_SENT 2 |
| 1225 | #define ESTABLISHED 3 |
| 1226 | #define FIN_WAIT_1 4 |
| 1227 | #define FIN_WAIT_2 5 |
| 1228 | #define CLOSING 6 |
| 1229 | #define TIME_WAIT 7 |
| 1230 | #define LAST_ACK 8 |
| 1231 | #define TS_MASK 15 |
| 1232 | |
| 1233 | #define UIP_STOPPED 16 |
| 1234 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1235 | #define UIP_TCPIP_HLEN 40 |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1236 | |
| 1237 | /* The TCP and IP headers. */ |
| 1238 | typedef struct { |
| 1239 | /* IP header. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1240 | u8_t vhl, |
| 1241 | tos, |
| 1242 | len[2], |
| 1243 | ipid[2], |
| 1244 | ipoffset[2], |
| 1245 | ttl, |
| 1246 | proto; |
| 1247 | u16_t ipchksum; |
| 1248 | u16_t srcipaddr[2], |
| 1249 | destipaddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1250 | |
| 1251 | /* TCP header. */ |
| 1252 | u16_t srcport, |
| 1253 | destport; |
| 1254 | u8_t seqno[4], |
| 1255 | ackno[4], |
| 1256 | tcpoffset, |
| 1257 | flags, |
| 1258 | wnd[2]; |
| 1259 | u16_t tcpchksum; |
| 1260 | u8_t urgp[2]; |
| 1261 | u8_t optdata[4]; |
| 1262 | } uip_tcpip_hdr; |
| 1263 | |
| 1264 | /* The ICMP and IP headers. */ |
| 1265 | typedef struct { |
| 1266 | /* IP header. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1267 | u8_t vhl, |
| 1268 | tos, |
| 1269 | len[2], |
| 1270 | ipid[2], |
| 1271 | ipoffset[2], |
| 1272 | ttl, |
| 1273 | proto; |
| 1274 | u16_t ipchksum; |
| 1275 | u16_t srcipaddr[2], |
| 1276 | destipaddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1277 | /* ICMP (echo) header. */ |
| 1278 | u8_t type, icode; |
| 1279 | u16_t icmpchksum; |
| 1280 | u16_t id, seqno; |
| 1281 | } uip_icmpip_hdr; |
| 1282 | |
| 1283 | |
| 1284 | /* The UDP and IP headers. */ |
| 1285 | typedef struct { |
| 1286 | /* IP header. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1287 | u8_t vhl, |
| 1288 | tos, |
| 1289 | len[2], |
| 1290 | ipid[2], |
| 1291 | ipoffset[2], |
| 1292 | ttl, |
| 1293 | proto; |
| 1294 | u16_t ipchksum; |
| 1295 | u16_t srcipaddr[2], |
| 1296 | destipaddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1297 | |
| 1298 | /* UDP header. */ |
| 1299 | u16_t srcport, |
| 1300 | destport; |
| 1301 | u16_t udplen; |
| 1302 | u16_t udpchksum; |
| 1303 | } uip_udpip_hdr; |
| 1304 | |
| 1305 | #define UIP_PROTO_ICMP 1 |
| 1306 | #define UIP_PROTO_TCP 6 |
| 1307 | #define UIP_PROTO_UDP 17 |
| 1308 | |
adamdunkels | 72a8303 | 2005-02-22 22:32:40 +0000 | [diff] [blame^] | 1309 | /* Header sizes. */ |
| 1310 | #define UIP_IPH_LEN 20 /* Size of IP header */ |
| 1311 | #define UIP_UDPH_LEN 8 /* Size of UDP header */ |
| 1312 | #define UIP_TCPH_LEN 20 /* Size of TCP header */ |
| 1313 | #define UIP_IPUDPH_LEN 28 /* Size of IP + UDP header */ |
| 1314 | #define UIP_IPTCPH_LEN 40 /* Size of IP + TCP header */ |
| 1315 | |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1316 | |
| 1317 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1318 | #if UIP_FIXEDADDR |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1319 | extern const u16_t uip_hostaddr[2], uip_netmask[2], uip_draddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1320 | #else /* UIP_FIXEDADDR */ |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1321 | extern u16_t uip_hostaddr[2], uip_netmask[2], uip_draddr[2]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1322 | #endif /* UIP_FIXEDADDR */ |
| 1323 | |
adamdunkels | 18076c6 | 2004-06-06 06:16:03 +0000 | [diff] [blame] | 1324 | |
| 1325 | |
adamdunkels | b380a3e | 2004-09-17 20:59:23 +0000 | [diff] [blame] | 1326 | /** |
| 1327 | * Representation of a 48-bit Ethernet address. |
| 1328 | */ |
| 1329 | struct uip_eth_addr { |
| 1330 | u8_t addr[6]; |
| 1331 | }; |
| 1332 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1333 | #endif /* __UIP_H__ */ |
| 1334 | |
| 1335 | |
adamdunkels | 0170b08 | 2003-10-01 11:25:37 +0000 | [diff] [blame] | 1336 | /** @} */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1337 | |