Contiki-Inga 3.x
uip-fw.h
Go to the documentation of this file.
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 
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  *
44  */
45 #ifndef UIP_FW_H_
46 #define UIP_FW_H_
47 
48 #include "net/ip/uip.h"
49 
50 /**
51  * Representation of a uIP network interface.
52  */
53 struct uip_fw_netif {
54  struct uip_fw_netif *next; /**< Pointer to the next interface when
55  linked in a list. */
56  uip_ipaddr_t ipaddr; /**< The IP address of this interface. */
57  uip_ipaddr_t netmask; /**< The netmask of the interface. */
58  uint8_t (* output)(void);
59  /**< A pointer to the function that
60  sends a packet. */
61 };
62 
63 /**
64  * Instantiating macro for a uIP network interface.
65  *
66  * Example:
67  \code
68  struct uip_fw_netif slipnetif =
69  {UIP_FW_NETIF(192,168,76,1, 255,255,255,0, slip_output)};
70  \endcode
71  * \param ip1,ip2,ip3,ip4 The IP address of the network interface.
72  *
73  * \param nm1,nm2,nm3,nm4 The netmask of the network interface.
74  *
75  * \param outputfunc A pointer to the output function of the network interface.
76  *
77  * \hideinitializer
78  */
79 #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
80  NULL, \
81  { {ip1, ip2, ip3, ip4} }, \
82  { {nm1, nm2, nm3, nm4} }, \
83  outputfunc
84 
85 /**
86  * Set the IP address of a network interface.
87  *
88  * \param netif A pointer to the uip_fw_netif structure for the network interface.
89  *
90  * \param addr A pointer to an IP address.
91  *
92  * \hideinitializer
93  */
94 #define uip_fw_setipaddr(netif, addr) \
95  do { (netif)->ipaddr[0] = ((uint16_t *)(addr))[0]; \
96  (netif)->ipaddr[1] = ((uint16_t *)(addr))[1]; } while(0)
97 /**
98  * Set the netmask of a network interface.
99  *
100  * \param netif A pointer to the uip_fw_netif structure for the network interface.
101  *
102  * \param addr A pointer to an IP address representing the netmask.
103  *
104  * \hideinitializer
105  */
106 #define uip_fw_setnetmask(netif, addr) \
107  do { (netif)->netmask[0] = ((uint16_t *)(addr))[0]; \
108  (netif)->netmask[1] = ((uint16_t *)(addr))[1]; } while(0)
109 
110 void uip_fw_init(void);
111 uint8_t uip_fw_forward(void);
112 uint8_t uip_fw_output(void);
113 void uip_fw_register(struct uip_fw_netif *netif);
114 void uip_fw_default(struct uip_fw_netif *netif);
115 void uip_fw_periodic(void);
116 
117 
118 /**
119  * A non-error message that indicates that a packet should be
120  * processed locally.
121  *
122  * \hideinitializer
123  */
124 #define UIP_FW_LOCAL 0
125 
126 /**
127  * A non-error message that indicates that something went OK.
128  *
129  * \hideinitializer
130  */
131 #define UIP_FW_OK 0
132 
133 /**
134  * A non-error message that indicates that a packet was forwarded.
135  *
136  * \hideinitializer
137  */
138 #define UIP_FW_FORWARDED 1
139 
140 /**
141  * A non-error message that indicates that a zero-length packet
142  * transmission was attempted, and that no packet was sent.
143  *
144  * \hideinitializer
145  */
146 #define UIP_FW_ZEROLEN 2
147 
148 /**
149  * An error message that indicates that a packet that was too large
150  * for the outbound network interface was detected.
151  *
152  * \hideinitializer
153  */
154 #define UIP_FW_TOOLARGE 3
155 
156 /**
157  * An error message that indicates that no suitable interface could be
158  * found for an outbound packet.
159  *
160  * \hideinitializer
161  */
162 #define UIP_FW_NOROUTE 4
163 
164 /**
165  * An error message that indicates that a packet that should be
166  * forwarded or output was dropped.
167  *
168  * \hideinitializer
169  */
170 #define UIP_FW_DROPPED 5
171 
172 
173 #endif /* UIP_FW_H_ */
174 
175 /** @} */