]> Joshua Wise's Git repositories - netwatch.git/blame - lwip/src/include/lwip/netif.h
initial checkin of lwip, enough to build
[netwatch.git] / lwip / src / include / lwip / netif.h
CommitLineData
6e6d4a8b
JP
1/*
2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <adam@sics.se>
30 *
31 */
32#ifndef __LWIP_NETIF_H__
33#define __LWIP_NETIF_H__
34
35#include "lwip/opt.h"
36
37#include "lwip/err.h"
38
39#include "lwip/ip_addr.h"
40
41#include "lwip/inet.h"
42#include "lwip/pbuf.h"
43#if LWIP_DHCP
44struct dhcp;
45#endif
46#if LWIP_AUTOIP
47struct autoip;
48#endif
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54/* Throughout this file, IP addresses are expected to be in
55 * the same byte order as in IP_PCB. */
56
57/** must be the maximum of all used hardware address lengths
58 across all types of interfaces in use */
59#define NETIF_MAX_HWADDR_LEN 6U
60
61/** TODO: define the use (where, when, whom) of netif flags */
62
63/** whether the network interface is 'up'. this is
64 * a software flag used to control whether this network
65 * interface is enabled and processes traffic.
66 */
67#define NETIF_FLAG_UP 0x01U
68/** if set, the netif has broadcast capability */
69#define NETIF_FLAG_BROADCAST 0x02U
70/** if set, the netif is one end of a point-to-point connection */
71#define NETIF_FLAG_POINTTOPOINT 0x04U
72/** if set, the interface is configured using DHCP */
73#define NETIF_FLAG_DHCP 0x08U
74/** if set, the interface has an active link
75 * (set by the network interface driver) */
76#define NETIF_FLAG_LINK_UP 0x10U
77/** if set, the netif is an device using ARP */
78#define NETIF_FLAG_ETHARP 0x20U
79/** if set, the netif has IGMP capability */
80#define NETIF_FLAG_IGMP 0x40U
81
82/** Generic data structure used for all lwIP network interfaces.
83 * The following fields should be filled in by the initialization
84 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
85
86struct netif {
87 /** pointer to next in linked list */
88 struct netif *next;
89
90 /** IP address configuration in network byte order */
91 struct ip_addr ip_addr;
92 struct ip_addr netmask;
93 struct ip_addr gw;
94
95 /** This function is called by the network device driver
96 * to pass a packet up the TCP/IP stack. */
97 err_t (* input)(struct pbuf *p, struct netif *inp);
98 /** This function is called by the IP module when it wants
99 * to send a packet on the interface. This function typically
100 * first resolves the hardware address, then sends the packet. */
101 err_t (* output)(struct netif *netif, struct pbuf *p,
102 struct ip_addr *ipaddr);
103 /** This function is called by the ARP module when it wants
104 * to send a packet on the interface. This function outputs
105 * the pbuf as-is on the link medium. */
106 err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
107#if LWIP_NETIF_STATUS_CALLBACK
108 /** This function is called when the netif state is set to up or down
109 */
110 void (* status_callback)(struct netif *netif);
111#endif /* LWIP_NETIF_STATUS_CALLBACK */
112#if LWIP_NETIF_LINK_CALLBACK
113 /** This function is called when the netif link is set to up or down
114 */
115 void (* link_callback)(struct netif *netif);
116#endif /* LWIP_NETIF_LINK_CALLBACK */
117 /** This field can be set by the device driver and could point
118 * to state information for the device. */
119 void *state;
120#if LWIP_DHCP
121 /** the DHCP client state information for this netif */
122 struct dhcp *dhcp;
123#endif /* LWIP_DHCP */
124#if LWIP_AUTOIP
125 /** the AutoIP client state information for this netif */
126 struct autoip *autoip;
127#endif
128#if LWIP_NETIF_HOSTNAME
129 /* the hostname for this netif, NULL is a valid value */
130 char* hostname;
131#endif /* LWIP_NETIF_HOSTNAME */
132 /** number of bytes used in hwaddr */
133 u8_t hwaddr_len;
134 /** link level hardware address of this interface */
135 u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
136 /** maximum transfer unit (in bytes) */
137 u16_t mtu;
138 /** flags (see NETIF_FLAG_ above) */
139 u8_t flags;
140 /** descriptive abbreviation */
141 char name[2];
142 /** number of this interface */
143 u8_t num;
144#if LWIP_SNMP
145 /** link type (from "snmp_ifType" enum from snmp.h) */
146 u8_t link_type;
147 /** (estimate) link speed */
148 u32_t link_speed;
149 /** timestamp at last change made (up/down) */
150 u32_t ts;
151 /** counters */
152 u32_t ifinoctets;
153 u32_t ifinucastpkts;
154 u32_t ifinnucastpkts;
155 u32_t ifindiscards;
156 u32_t ifoutoctets;
157 u32_t ifoutucastpkts;
158 u32_t ifoutnucastpkts;
159 u32_t ifoutdiscards;
160#endif /* LWIP_SNMP */
161#if LWIP_IGMP
162 /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
163 err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
164#endif /* LWIP_IGMP */
165#if LWIP_NETIF_HWADDRHINT
166 u8_t *addr_hint;
167#endif /* LWIP_NETIF_HWADDRHINT */
168};
169
170#if LWIP_SNMP
171#define NETIF_INIT_SNMP(netif, type, speed) \
172 /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
173 netif->link_type = type; \
174 /* your link speed here (units: bits per second) */ \
175 netif->link_speed = speed; \
176 netif->ts = 0; \
177 netif->ifinoctets = 0; \
178 netif->ifinucastpkts = 0; \
179 netif->ifinnucastpkts = 0; \
180 netif->ifindiscards = 0; \
181 netif->ifoutoctets = 0; \
182 netif->ifoutucastpkts = 0; \
183 netif->ifoutnucastpkts = 0; \
184 netif->ifoutdiscards = 0
185#else /* LWIP_SNMP */
186#define NETIF_INIT_SNMP(netif, type, speed)
187#endif /* LWIP_SNMP */
188
189
190/** The list of network interfaces. */
191extern struct netif *netif_list;
192/** The default network interface. */
193extern struct netif *netif_default;
194
195#define netif_init() /* Compatibility define, not init needed. */
196
197struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
198 struct ip_addr *gw,
199 void *state,
200 err_t (* init)(struct netif *netif),
201 err_t (* input)(struct pbuf *p, struct netif *netif));
202
203void
204netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
205 struct ip_addr *gw);
206void netif_remove(struct netif * netif);
207
208/* Returns a network interface given its name. The name is of the form
209 "et0", where the first two letters are the "name" field in the
210 netif structure, and the digit is in the num field in the same
211 structure. */
212struct netif *netif_find(char *name);
213
214void netif_set_default(struct netif *netif);
215
216void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
217void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
218void netif_set_gw(struct netif *netif, struct ip_addr *gw);
219
220void netif_set_up(struct netif *netif);
221void netif_set_down(struct netif *netif);
222u8_t netif_is_up(struct netif *netif);
223
224#if LWIP_NETIF_STATUS_CALLBACK
225/*
226 * Set callback to be called when interface is brought up/down
227 */
228void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
229#endif /* LWIP_NETIF_STATUS_CALLBACK */
230
231#if LWIP_NETIF_LINK_CALLBACK
232void netif_set_link_up(struct netif *netif);
233void netif_set_link_down(struct netif *netif);
234u8_t netif_is_link_up(struct netif *netif);
235/*
236 * Set callback to be called when link is brought up/down
237 */
238void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
239#endif /* LWIP_NETIF_LINK_CALLBACK */
240
241#ifdef __cplusplus
242}
243#endif
244
245#endif /* __LWIP_NETIF_H__ */
This page took 0.042767 seconds and 4 git commands to generate.