Contiki 2.6
|
00001 /** 00002 * \addtogroup uipfw 00003 * @{ 00004 */ 00005 00006 /** 00007 * \file 00008 * uIP packet forwarding header file. 00009 * \author Adam Dunkels <adam@sics.se> 00010 */ 00011 00012 /* 00013 * Copyright (c) 2004, Swedish Institute of Computer Science. 00014 * All rights reserved. 00015 * 00016 * Redistribution and use in source and binary forms, with or without 00017 * modification, are permitted provided that the following conditions 00018 * are met: 00019 * 1. Redistributions of source code must retain the above copyright 00020 * notice, this list of conditions and the following disclaimer. 00021 * 2. Redistributions in binary form must reproduce the above copyright 00022 * notice, this list of conditions and the following disclaimer in the 00023 * documentation and/or other materials provided with the distribution. 00024 * 3. Neither the name of the Institute nor the names of its contributors 00025 * may be used to endorse or promote products derived from this software 00026 * without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00029 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00031 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00032 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00033 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00034 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00035 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00036 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00037 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00038 * SUCH DAMAGE. 00039 * 00040 * This file is part of the Contiki operating system. 00041 * 00042 * Author: Adam Dunkels <adam@sics.se> 00043 * 00044 * $Id: uip-fw.h,v 1.4 2009/03/15 20:29:04 nvt-se Exp $ 00045 */ 00046 #ifndef __UIP_FW_H__ 00047 #define __UIP_FW_H__ 00048 00049 #include "net/uip.h" 00050 00051 /** 00052 * Representation of a uIP network interface. 00053 */ 00054 struct uip_fw_netif { 00055 struct uip_fw_netif *next; /**< Pointer to the next interface when 00056 linked in a list. */ 00057 uip_ipaddr_t ipaddr; /**< The IP address of this interface. */ 00058 uip_ipaddr_t netmask; /**< The netmask of the interface. */ 00059 uint8_t (* output)(void); 00060 /**< A pointer to the function that 00061 sends a packet. */ 00062 }; 00063 00064 /** 00065 * Instantiating macro for a uIP network interface. 00066 * 00067 * Example: 00068 \code 00069 struct uip_fw_netif slipnetif = 00070 {UIP_FW_NETIF(192,168,76,1, 255,255,255,0, slip_output)}; 00071 \endcode 00072 * \param ip1,ip2,ip3,ip4 The IP address of the network interface. 00073 * 00074 * \param nm1,nm2,nm3,nm4 The netmask of the network interface. 00075 * 00076 * \param outputfunc A pointer to the output function of the network interface. 00077 * 00078 * \hideinitializer 00079 */ 00080 #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \ 00081 NULL, \ 00082 { {ip1, ip2, ip3, ip4} }, \ 00083 { {nm1, nm2, nm3, nm4} }, \ 00084 outputfunc 00085 00086 /** 00087 * Set the IP address of a network interface. 00088 * 00089 * \param netif A pointer to the uip_fw_netif structure for the network interface. 00090 * 00091 * \param addr A pointer to an IP address. 00092 * 00093 * \hideinitializer 00094 */ 00095 #define uip_fw_setipaddr(netif, addr) \ 00096 do { (netif)->ipaddr[0] = ((uint16_t *)(addr))[0]; \ 00097 (netif)->ipaddr[1] = ((uint16_t *)(addr))[1]; } while(0) 00098 /** 00099 * Set the netmask of a network interface. 00100 * 00101 * \param netif A pointer to the uip_fw_netif structure for the network interface. 00102 * 00103 * \param addr A pointer to an IP address representing the netmask. 00104 * 00105 * \hideinitializer 00106 */ 00107 #define uip_fw_setnetmask(netif, addr) \ 00108 do { (netif)->netmask[0] = ((uint16_t *)(addr))[0]; \ 00109 (netif)->netmask[1] = ((uint16_t *)(addr))[1]; } while(0) 00110 00111 void uip_fw_init(void); 00112 uint8_t uip_fw_forward(void); 00113 uint8_t uip_fw_output(void); 00114 void uip_fw_register(struct uip_fw_netif *netif); 00115 void uip_fw_default(struct uip_fw_netif *netif); 00116 void uip_fw_periodic(void); 00117 00118 00119 /** 00120 * A non-error message that indicates that a packet should be 00121 * processed locally. 00122 * 00123 * \hideinitializer 00124 */ 00125 #define UIP_FW_LOCAL 0 00126 00127 /** 00128 * A non-error message that indicates that something went OK. 00129 * 00130 * \hideinitializer 00131 */ 00132 #define UIP_FW_OK 0 00133 00134 /** 00135 * A non-error message that indicates that a packet was forwarded. 00136 * 00137 * \hideinitializer 00138 */ 00139 #define UIP_FW_FORWARDED 1 00140 00141 /** 00142 * A non-error message that indicates that a zero-length packet 00143 * transmission was attempted, and that no packet was sent. 00144 * 00145 * \hideinitializer 00146 */ 00147 #define UIP_FW_ZEROLEN 2 00148 00149 /** 00150 * An error message that indicates that a packet that was too large 00151 * for the outbound network interface was detected. 00152 * 00153 * \hideinitializer 00154 */ 00155 #define UIP_FW_TOOLARGE 3 00156 00157 /** 00158 * An error message that indicates that no suitable interface could be 00159 * found for an outbound packet. 00160 * 00161 * \hideinitializer 00162 */ 00163 #define UIP_FW_NOROUTE 4 00164 00165 /** 00166 * An error message that indicates that a packet that should be 00167 * forwarded or output was dropped. 00168 * 00169 * \hideinitializer 00170 */ 00171 #define UIP_FW_DROPPED 5 00172 00173 00174 #endif /* __UIP_FW_H__ */ 00175 00176 /** @} */