adamdunkels | 3f5bc0a | 2005-02-07 07:06:31 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \addtogroup uipfw |
| 3 | * @{ |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * \file |
| 8 | * uIP packet forwarding header file. |
| 9 | * \author Adam Dunkels <adam@sics.se> |
| 10 | */ |
| 11 | |
adamdunkels | a2f3c42 | 2004-09-12 20:24:53 +0000 | [diff] [blame] | 12 | /* |
| 13 | * Copyright (c) 2004, Swedish Institute of Computer Science. |
| 14 | * All rights reserved. |
| 15 | * |
| 16 | * Redistribution and use in source and binary forms, with or without |
| 17 | * modification, are permitted provided that the following conditions |
| 18 | * are met: |
| 19 | * 1. Redistributions of source code must retain the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer. |
| 21 | * 2. Redistributions in binary form must reproduce the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer in the |
| 23 | * documentation and/or other materials provided with the distribution. |
| 24 | * 3. Neither the name of the Institute nor the names of its contributors |
| 25 | * may be used to endorse or promote products derived from this software |
| 26 | * without specific prior written permission. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 38 | * SUCH DAMAGE. |
| 39 | * |
| 40 | * This file is part of the Contiki operating system. |
| 41 | * |
| 42 | * Author: Adam Dunkels <adam@sics.se> |
| 43 | * |
adamdunkels | 3f5bc0a | 2005-02-07 07:06:31 +0000 | [diff] [blame] | 44 | * $Id: uip-fw.h,v 1.7 2005/02/07 07:06:31 adamdunkels Exp $ |
adamdunkels | a2f3c42 | 2004-09-12 20:24:53 +0000 | [diff] [blame] | 45 | */ |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 46 | #ifndef __UIP_FW_H__ |
| 47 | #define __UIP_FW_H__ |
| 48 | |
adamdunkels | 29cfbb8 | 2004-06-06 06:54:27 +0000 | [diff] [blame] | 49 | #include "uip.h" |
| 50 | |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 51 | /** |
| 52 | * Representation of a uIP network interface. |
| 53 | */ |
| 54 | struct uip_fw_netif { |
| 55 | struct uip_fw_netif *next; /**< Pointer to the next interface when |
| 56 | linked in a list. */ |
| 57 | u16_t ipaddr[2]; /**< The IP address of this interface. */ |
| 58 | u16_t netmask[2]; /**< The netmask of the interface. */ |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 59 | u8_t (* output)(void); |
adamdunkels | b489e7a | 2003-10-14 11:12:50 +0000 | [diff] [blame] | 60 | /**< A pointer to the function that |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 61 | sends a packet. */ |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * Intantiating macro for a uIP network interface. |
| 66 | * |
| 67 | * Example: |
| 68 | \code |
| 69 | struct uip_fw_netif slipnetif = |
| 70 | {UIP_FW_NETIF(192,168,76,1, 255,255,255,0, slip_output)}; |
| 71 | \endcode |
| 72 | * \param ip1,ip2,ip3,ip4 The IP address of the network interface. |
| 73 | * |
| 74 | * \param nm1,nm2,nm3,nm4 The netmask of the network interface. |
| 75 | * |
| 76 | * \param outputfunc A pointer to the output function of the network interface. |
| 77 | * |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 78 | * \hideinitializer |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 79 | */ |
| 80 | #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \ |
| 81 | NULL, \ |
| 82 | {HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \ |
| 83 | {HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \ |
| 84 | outputfunc |
| 85 | |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 86 | /** |
| 87 | * Set the IP address of a network interface. |
| 88 | * |
| 89 | * \param netif A pointer to the uip_fw_netif structure for the network interface. |
| 90 | * |
| 91 | * \param addr A pointer to an IP address. |
| 92 | * |
| 93 | * \hideinitializer |
| 94 | */ |
| 95 | #define uip_fw_setipaddr(netif, addr) \ |
| 96 | do { (netif)->ipaddr[0] = ((u16_t *)(addr))[0]; \ |
| 97 | (netif)->ipaddr[1] = ((u16_t *)(addr))[1]; } while(0) |
| 98 | /** |
| 99 | * Set the netmask of a network interface. |
| 100 | * |
| 101 | * \param netif A pointer to the uip_fw_netif structure for the network interface. |
| 102 | * |
| 103 | * \param addr A pointer to an IP address representing the netmask. |
| 104 | * |
| 105 | * \hideinitializer |
| 106 | */ |
| 107 | #define uip_fw_setnetmask(netif, addr) \ |
| 108 | do { (netif)->netmask[0] = ((u16_t *)(addr))[0]; \ |
| 109 | (netif)->netmask[1] = ((u16_t *)(addr))[1]; } while(0) |
| 110 | |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 111 | void uip_fw_init(void); |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 112 | u8_t uip_fw_forward(void); |
| 113 | u8_t uip_fw_output(void); |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 114 | void uip_fw_register(struct uip_fw_netif *netif); |
| 115 | void uip_fw_default(struct uip_fw_netif *netif); |
adamdunkels | 048a33f | 2004-02-16 20:48:53 +0000 | [diff] [blame] | 116 | void uip_fw_periodic(void); |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 117 | |
adamdunkels | 5f13299 | 2003-11-27 15:49:53 +0000 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * A non-error message that indicates that a packet should be |
| 121 | * processed locally. |
| 122 | * |
| 123 | * \hideinitializer |
| 124 | */ |
| 125 | #define UIP_FW_LOCAL 0 |
| 126 | |
| 127 | /** |
| 128 | * A non-error message that indicates that something went OK. |
| 129 | * |
| 130 | * \hideinitializer |
| 131 | */ |
| 132 | #define UIP_FW_OK 0 |
| 133 | |
| 134 | /** |
| 135 | * A non-error message that indicates that a packet was forwarded. |
| 136 | * |
| 137 | * \hideinitializer |
| 138 | */ |
| 139 | #define UIP_FW_FORWARDED 1 |
| 140 | |
| 141 | /** |
| 142 | * A non-error message that indicates that a zero-length packet |
| 143 | * transmission was attempted, and that no packet was sent. |
| 144 | * |
| 145 | * \hideinitializer |
| 146 | */ |
| 147 | #define UIP_FW_ZEROLEN 2 |
| 148 | |
| 149 | /** |
| 150 | * An error message that indicates that a packet that was too large |
| 151 | * for the outbound network interface was detected. |
| 152 | * |
| 153 | * \hideinitializer |
| 154 | */ |
| 155 | #define UIP_FW_TOOLARGE 3 |
| 156 | |
| 157 | /** |
| 158 | * An error message that indicates that no suitable interface could be |
| 159 | * found for an outbound packet. |
| 160 | * |
| 161 | * \hideinitializer |
| 162 | */ |
| 163 | #define UIP_FW_NOROUTE 4 |
| 164 | |
| 165 | /** |
| 166 | * An error message that indicates that a packet that should be |
| 167 | * forwarded or output was dropped. |
| 168 | * |
| 169 | * \hideinitializer |
| 170 | */ |
| 171 | #define UIP_FW_DROPPED 5 |
| 172 | |
adamdunkels | 048a33f | 2004-02-16 20:48:53 +0000 | [diff] [blame] | 173 | |
adamdunkels | 4b70611 | 2003-09-23 08:57:40 +0000 | [diff] [blame] | 174 | #endif /* __UIP_FW_H__ */ |
adamdunkels | 3f5bc0a | 2005-02-07 07:06:31 +0000 | [diff] [blame] | 175 | |
| 176 | /** @} */ |