2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
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.
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
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
32 #ifndef __LWIP_NETIF_H__
33 #define __LWIP_NETIF_H__
39 #include "lwip/ip_addr.h"
41 #include "lwip/inet.h"
42 #include "lwip/pbuf.h"
54 /* Throughout this file, IP addresses are expected to be in
55 * the same byte order as in IP_PCB. */
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
61 /** TODO: define the use (where, when, whom) of netif flags */
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.
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
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 */
87 /** pointer to next in linked list */
90 /** IP address configuration in network byte order */
91 struct ip_addr ip_addr;
92 struct ip_addr netmask;
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
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
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. */
121 /** the DHCP client state information for this netif */
123 #endif /* LWIP_DHCP */
125 /** the AutoIP client state information for this netif */
126 struct autoip *autoip;
128 #if LWIP_NETIF_HOSTNAME
129 /* the hostname for this netif, NULL is a valid value */
131 #endif /* LWIP_NETIF_HOSTNAME */
132 /** number of bytes used in hwaddr */
134 /** link level hardware address of this interface */
135 u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
136 /** maximum transfer unit (in bytes) */
138 /** flags (see NETIF_FLAG_ above) */
140 /** descriptive abbreviation */
142 /** number of this interface */
145 /** link type (from "snmp_ifType" enum from snmp.h) */
147 /** (estimate) link speed */
149 /** timestamp at last change made (up/down) */
154 u32_t ifinnucastpkts;
157 u32_t ifoutucastpkts;
158 u32_t ifoutnucastpkts;
160 #endif /* LWIP_SNMP */
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
167 #endif /* LWIP_NETIF_HWADDRHINT */
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; \
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 */
190 /** The list of network interfaces. */
191 extern struct netif *netif_list;
192 /** The default network interface. */
193 extern struct netif *netif_default;
195 #define netif_init() /* Compatibility define, not init needed. */
197 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
200 err_t (* init)(struct netif *netif),
201 err_t (* input)(struct pbuf *p, struct netif *netif));
204 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
206 void netif_remove(struct netif * netif);
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
212 struct netif *netif_find(char *name);
214 void netif_set_default(struct netif *netif);
216 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
217 void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
218 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
220 void netif_set_up(struct netif *netif);
221 void netif_set_down(struct netif *netif);
222 u8_t netif_is_up(struct netif *netif);
224 #if LWIP_NETIF_STATUS_CALLBACK
226 * Set callback to be called when interface is brought up/down
228 void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
229 #endif /* LWIP_NETIF_STATUS_CALLBACK */
231 #if LWIP_NETIF_LINK_CALLBACK
232 void netif_set_link_up(struct netif *netif);
233 void netif_set_link_down(struct netif *netif);
234 u8_t netif_is_link_up(struct netif *netif);
236 * Set callback to be called when link is brought up/down
238 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
239 #endif /* LWIP_NETIF_LINK_CALLBACK */
245 #endif /* __LWIP_NETIF_H__ */