A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
netif.h
00001 /* 00002 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 #ifndef __LWIP_NETIF_H__ 00033 #define __LWIP_NETIF_H__ 00034 00035 #include "lwip/opt.h" 00036 00037 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) 00038 00039 #include "lwip/err.h" 00040 00041 #include "lwip/ip_addr.h" 00042 00043 #include "lwip/inet.h" 00044 #include "lwip/pbuf.h" 00045 #if LWIP_DHCP 00046 struct dhcp; 00047 #endif 00048 #if LWIP_AUTOIP 00049 struct autoip; 00050 #endif 00051 00052 #ifdef __cplusplus 00053 // XXX: WTF 00054 //extern "C" { 00055 #endif 00056 00057 /* Throughout this file, IP addresses are expected to be in 00058 * the same byte order as in IP_PCB. */ 00059 00060 /** must be the maximum of all used hardware address lengths 00061 across all types of interfaces in use */ 00062 #define NETIF_MAX_HWADDR_LEN 6U 00063 00064 /** TODO: define the use (where, when, whom) of netif flags */ 00065 00066 /** whether the network interface is 'up'. this is 00067 * a software flag used to control whether this network 00068 * interface is enabled and processes traffic. 00069 */ 00070 #define NETIF_FLAG_UP 0x01U 00071 /** if set, the netif has broadcast capability */ 00072 #define NETIF_FLAG_BROADCAST 0x02U 00073 /** if set, the netif is one end of a point-to-point connection */ 00074 #define NETIF_FLAG_POINTTOPOINT 0x04U 00075 /** if set, the interface is configured using DHCP */ 00076 #define NETIF_FLAG_DHCP 0x08U 00077 /** if set, the interface has an active link 00078 * (set by the network interface driver) */ 00079 #define NETIF_FLAG_LINK_UP 0x10U 00080 /** if set, the netif is an device using ARP */ 00081 #define NETIF_FLAG_ETHARP 0x20U 00082 /** if set, the netif has IGMP capability */ 00083 #define NETIF_FLAG_IGMP 0x40U 00084 00085 /** Generic data structure used for all lwIP network interfaces. 00086 * The following fields should be filled in by the initialization 00087 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ 00088 00089 struct netif { 00090 /** pointer to next in linked list */ 00091 struct netif *next; 00092 00093 /** IP address configuration in network byte order */ 00094 struct ip_addr ip_addr; 00095 struct ip_addr netmask; 00096 struct ip_addr gw; 00097 00098 /** This function is called by the network device driver 00099 * to pass a packet up the TCP/IP stack. */ 00100 err_t (* input)(struct pbuf *p, struct netif *inp); 00101 /** This function is called by the IP module when it wants 00102 * to send a packet on the interface. This function typically 00103 * first resolves the hardware address, then sends the packet. */ 00104 err_t (* output)(struct netif *netif, struct pbuf *p, 00105 struct ip_addr *ipaddr); 00106 /** This function is called by the ARP module when it wants 00107 * to send a packet on the interface. This function outputs 00108 * the pbuf as-is on the link medium. */ 00109 err_t (* linkoutput)(struct netif *netif, struct pbuf *p); 00110 #if LWIP_NETIF_STATUS_CALLBACK 00111 /** This function is called when the netif state is set to up or down 00112 */ 00113 void (* status_callback)(struct netif *netif); 00114 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 00115 #if LWIP_NETIF_LINK_CALLBACK 00116 /** This function is called when the netif link is set to up or down 00117 */ 00118 void (* link_callback)(struct netif *netif); 00119 #endif /* LWIP_NETIF_LINK_CALLBACK */ 00120 /** This field can be set by the device driver and could point 00121 * to state information for the device. */ 00122 void *state; 00123 #if LWIP_DHCP 00124 /** the DHCP client state information for this netif */ 00125 struct dhcp *dhcp; 00126 #endif /* LWIP_DHCP */ 00127 #if LWIP_AUTOIP 00128 /** the AutoIP client state information for this netif */ 00129 struct autoip *autoip; 00130 #endif 00131 #if LWIP_NETIF_HOSTNAME 00132 /* the hostname for this netif, NULL is a valid value */ 00133 char* hostname; 00134 #endif /* LWIP_NETIF_HOSTNAME */ 00135 /** number of bytes used in hwaddr */ 00136 u8_t hwaddr_len; 00137 /** link level hardware address of this interface */ 00138 u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; 00139 /** maximum transfer unit (in bytes) */ 00140 u16_t mtu; 00141 /** flags (see NETIF_FLAG_ above) */ 00142 u8_t flags; 00143 /** descriptive abbreviation */ 00144 char name[2]; 00145 /** number of this interface */ 00146 u8_t num; 00147 #if LWIP_SNMP 00148 /** link type (from "snmp_ifType" enum from snmp.h) */ 00149 u8_t link_type; 00150 /** (estimate) link speed */ 00151 u32_t link_speed; 00152 /** timestamp at last change made (up/down) */ 00153 u32_t ts; 00154 /** counters */ 00155 u32_t ifinoctets; 00156 u32_t ifinucastpkts; 00157 u32_t ifinnucastpkts; 00158 u32_t ifindiscards; 00159 u32_t ifoutoctets; 00160 u32_t ifoutucastpkts; 00161 u32_t ifoutnucastpkts; 00162 u32_t ifoutdiscards; 00163 #endif /* LWIP_SNMP */ 00164 #if LWIP_IGMP 00165 /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/ 00166 err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action); 00167 #endif /* LWIP_IGMP */ 00168 #if LWIP_NETIF_HWADDRHINT 00169 u8_t *addr_hint; 00170 #endif /* LWIP_NETIF_HWADDRHINT */ 00171 #if ENABLE_LOOPBACK 00172 /* List of packets to be queued for ourselves. */ 00173 struct pbuf *loop_first; 00174 struct pbuf *loop_last; 00175 #if LWIP_LOOPBACK_MAX_PBUFS 00176 u16_t loop_cnt_current; 00177 #endif /* LWIP_LOOPBACK_MAX_PBUFS */ 00178 #endif /* ENABLE_LOOPBACK */ 00179 }; 00180 00181 #if LWIP_SNMP 00182 #define NETIF_INIT_SNMP(netif, type, speed) \ 00183 /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \ 00184 netif->link_type = type; \ 00185 /* your link speed here (units: bits per second) */ \ 00186 netif->link_speed = speed; \ 00187 netif->ts = 0; \ 00188 netif->ifinoctets = 0; \ 00189 netif->ifinucastpkts = 0; \ 00190 netif->ifinnucastpkts = 0; \ 00191 netif->ifindiscards = 0; \ 00192 netif->ifoutoctets = 0; \ 00193 netif->ifoutucastpkts = 0; \ 00194 netif->ifoutnucastpkts = 0; \ 00195 netif->ifoutdiscards = 0 00196 #else /* LWIP_SNMP */ 00197 #define NETIF_INIT_SNMP(netif, type, speed) 00198 #endif /* LWIP_SNMP */ 00199 00200 00201 /** The list of network interfaces. */ 00202 extern struct netif *netif_list; 00203 /** The default network interface. */ 00204 extern struct netif *netif_default; 00205 00206 #define netif_init() /* Compatibility define, not init needed. */ 00207 00208 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, 00209 struct ip_addr *gw, 00210 void *state, 00211 err_t (* init)(struct netif *netif), 00212 err_t (* input)(struct pbuf *p, struct netif *netif)); 00213 00214 void 00215 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask, 00216 struct ip_addr *gw); 00217 void netif_remove(struct netif * netif); 00218 00219 /* Returns a network interface given its name. The name is of the form 00220 "et0", where the first two letters are the "name" field in the 00221 netif structure, and the digit is in the num field in the same 00222 structure. */ 00223 struct netif *netif_find(char *name); 00224 00225 void netif_set_default(struct netif *netif); 00226 00227 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr); 00228 void netif_set_netmask(struct netif *netif, struct ip_addr *netmask); 00229 void netif_set_gw(struct netif *netif, struct ip_addr *gw); 00230 00231 void netif_set_up(struct netif *netif); 00232 void netif_set_down(struct netif *netif); 00233 u8_t netif_is_up(struct netif *netif); 00234 00235 #if LWIP_NETIF_STATUS_CALLBACK 00236 /* 00237 * Set callback to be called when interface is brought up/down 00238 */ 00239 void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif)); 00240 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 00241 00242 #if LWIP_NETIF_LINK_CALLBACK 00243 void netif_set_link_up(struct netif *netif); 00244 void netif_set_link_down(struct netif *netif); 00245 u8_t netif_is_link_up(struct netif *netif); 00246 /* 00247 * Set callback to be called when link is brought up/down 00248 */ 00249 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif)); 00250 #endif /* LWIP_NETIF_LINK_CALLBACK */ 00251 00252 #ifdef __cplusplus 00253 // XXX: WTF 00254 //} 00255 #endif 00256 00257 #if ENABLE_LOOPBACK 00258 err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip); 00259 void netif_poll(struct netif *netif); 00260 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 00261 void netif_poll_all(void); 00262 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ 00263 #endif /* ENABLE_LOOPBACK */ 00264 00265 #endif /* __LWIP_NETIF_H__ */
Generated on Tue Jul 12 2022 16:06:18 by 1.7.2