2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without modification,
\r
6 * are permitted provided that the following conditions are met:
\r
8 * 1. Redistributions of source code must retain the above copyright notice,
\r
9 * this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
11 * this list of conditions and the following disclaimer in the documentation
\r
12 * and/or other materials provided with the distribution.
\r
13 * 3. The name of the author may not be used to endorse or promote products
\r
14 * derived from this software without specific prior written permission.
\r
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
\r
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
\r
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
\r
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
\r
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
\r
27 * This file is part of the lwIP TCP/IP stack.
\r
29 * Author: Adam Dunkels <adam@sics.se>
\r
32 #ifndef __LWIP_NETIF_H__
\r
33 #define __LWIP_NETIF_H__
\r
35 #include "lwip/opt.h"
\r
37 #include "lwip/err.h"
\r
39 #include "lwip/ip_addr.h"
\r
41 #include "lwip/inet.h"
\r
42 #include "lwip/pbuf.h"
\r
44 # include "lwip/dhcp.h"
\r
47 /** must be the maximum of all used hardware address lengths
\r
48 across all types of interfaces in use */
\r
49 #define NETIF_MAX_HWADDR_LEN 6U
\r
51 /** TODO: define the use (where, when, whom) of netif flags */
\r
53 /** whether the network interface is 'up'. this is
\r
54 * a software flag used to control whether this network
\r
55 * interface is enabled and processes traffic.
\r
57 #define NETIF_FLAG_UP 0x1U
\r
58 /** if set, the netif has broadcast capability */
\r
59 #define NETIF_FLAG_BROADCAST 0x2U
\r
60 /** if set, the netif is one end of a point-to-point connection */
\r
61 #define NETIF_FLAG_POINTTOPOINT 0x4U
\r
62 /** if set, the interface is configured using DHCP */
\r
63 #define NETIF_FLAG_DHCP 0x08U
\r
64 /** if set, the interface has an active link
\r
65 * (set by the network interface driver) */
\r
66 #define NETIF_FLAG_LINK_UP 0x10U
\r
68 /** Generic data structure used for all lwIP network interfaces.
\r
69 * The following fields should be filled in by the initialization
\r
70 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
\r
73 /** pointer to next in linked list */
\r
76 /** IP address configuration in network byte order */
\r
77 struct ip_addr ip_addr;
\r
78 struct ip_addr netmask;
\r
81 /** This function is called by the network device driver
\r
82 * to pass a packet up the TCP/IP stack. */
\r
83 err_t (* input)(struct pbuf *p, struct netif *inp);
\r
84 /** This function is called by the IP module when it wants
\r
85 * to send a packet on the interface. This function typically
\r
86 * first resolves the hardware address, then sends the packet. */
\r
87 err_t (* output)(struct netif *netif, struct pbuf *p,
\r
88 struct ip_addr *ipaddr);
\r
89 /** This function is called by the ARP module when it wants
\r
90 * to send a packet on the interface. This function outputs
\r
91 * the pbuf as-is on the link medium. */
\r
92 err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
\r
93 /** This field can be set by the device driver and could point
\r
94 * to state information for the device. */
\r
97 /** the DHCP client state information for this netif */
\r
100 /** number of bytes used in hwaddr */
\r
102 /** link level hardware address of this interface */
\r
103 u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
\r
104 /** maximum transfer unit (in bytes) */
\r
106 /** flags (see NETIF_FLAG_ above) */
\r
108 /** descriptive abbreviation */
\r
110 /** number of this interface */
\r
113 /** link type (ifType values per RFC1213) */
\r
115 /** (estimate) link speed */
\r
117 /** timestamp at last change made (up/down) */
\r
121 u32_t ifinucastpkts;
\r
122 u32_t ifinnucastpkts;
\r
123 u32_t ifindiscards;
\r
125 u32_t ifoutucastpkts;
\r
126 u32_t ifoutnucastpkts;
\r
127 u32_t ifoutdiscards;
\r
131 /** The list of network interfaces. */
\r
132 extern struct netif *netif_list;
\r
133 /** The default network interface. */
\r
134 extern struct netif *netif_default;
\r
136 /* netif_init() must be called first. */
\r
137 void netif_init(void);
\r
139 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
\r
140 struct ip_addr *gw,
\r
142 err_t (* init)(struct netif *netif),
\r
143 err_t (* input)(struct pbuf *p, struct netif *netif));
\r
146 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
\r
147 struct ip_addr *gw);
\r
148 void netif_remove(struct netif * netif);
\r
150 /* Returns a network interface given its name. The name is of the form
\r
151 "et0", where the first two letters are the "name" field in the
\r
152 netif structure, and the digit is in the num field in the same
\r
154 struct netif *netif_find(char *name);
\r
156 void netif_set_default(struct netif *netif);
\r
158 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
\r
159 void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
\r
160 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
\r
161 void netif_set_up(struct netif *netif);
\r
162 void netif_set_down(struct netif *netif);
\r
163 u8_t netif_is_up(struct netif *netif);
\r
165 #endif /* __LWIP_NETIF_H__ */
\r