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