Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
netif.h
00001 /** 00002 * @file 00003 * netif API (to be used from TCPIP thread) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 #ifndef LWIP_HDR_NETIF_H 00038 #define LWIP_HDR_NETIF_H 00039 00040 #include "lwip/opt.h" 00041 00042 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) 00043 00044 #include "lwip/err.h" 00045 00046 #include "lwip/ip_addr.h" 00047 00048 #include "lwip/def.h" 00049 #include "lwip/pbuf.h" 00050 #include "lwip/stats.h" 00051 00052 #if LWIP_DHCP 00053 struct dhcp; 00054 #endif 00055 #if LWIP_AUTOIP 00056 struct autoip; 00057 #endif 00058 #if LWIP_IPV6_DHCP6 00059 struct dhcp6; 00060 #endif /* LWIP_IPV6_DHCP6 */ 00061 00062 #ifdef __cplusplus 00063 extern "C" { 00064 #endif 00065 00066 /* Throughout this file, IP addresses are expected to be in 00067 * the same byte order as in IP_PCB. */ 00068 00069 /** Must be the maximum of all used hardware address lengths 00070 across all types of interfaces in use. 00071 This does not have to be changed, normally. */ 00072 #ifndef NETIF_MAX_HWADDR_LEN 00073 #define NETIF_MAX_HWADDR_LEN 6U 00074 #endif 00075 00076 /** 00077 * @defgroup netif_flags Flags 00078 * @ingroup netif 00079 * @{ 00080 */ 00081 00082 /** Whether the network interface is 'up'. This is 00083 * a software flag used to control whether this network 00084 * interface is enabled and processes traffic. 00085 * It must be set by the startup code before this netif can be used 00086 * (also for dhcp/autoip). 00087 */ 00088 #define NETIF_FLAG_UP 0x01U 00089 /** If set, the netif has broadcast capability. 00090 * Set by the netif driver in its init function. */ 00091 #define NETIF_FLAG_BROADCAST 0x02U 00092 /** If set, the interface has an active link 00093 * (set by the network interface driver). 00094 * Either set by the netif driver in its init function (if the link 00095 * is up at that time) or at a later point once the link comes up 00096 * (if link detection is supported by the hardware). */ 00097 #define NETIF_FLAG_LINK_UP 0x04U 00098 /** If set, the netif is an ethernet device using ARP. 00099 * Set by the netif driver in its init function. 00100 * Used to check input packet types and use of DHCP. */ 00101 #define NETIF_FLAG_ETHARP 0x08U 00102 /** If set, the netif is an ethernet device. It might not use 00103 * ARP or TCP/IP if it is used for PPPoE only. 00104 */ 00105 #define NETIF_FLAG_ETHERNET 0x10U 00106 /** If set, the netif has IGMP capability. 00107 * Set by the netif driver in its init function. */ 00108 #define NETIF_FLAG_IGMP 0x20U 00109 /** If set, the netif has MLD6 capability. 00110 * Set by the netif driver in its init function. */ 00111 #define NETIF_FLAG_MLD6 0x40U 00112 00113 /** 00114 * @} 00115 */ 00116 00117 #if LWIP_CHECKSUM_CTRL_PER_NETIF 00118 #define NETIF_CHECKSUM_GEN_IP 0x0001 00119 #define NETIF_CHECKSUM_GEN_UDP 0x0002 00120 #define NETIF_CHECKSUM_GEN_TCP 0x0004 00121 #define NETIF_CHECKSUM_GEN_ICMP 0x0008 00122 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010 00123 #define NETIF_CHECKSUM_CHECK_IP 0x0100 00124 #define NETIF_CHECKSUM_CHECK_UDP 0x0200 00125 #define NETIF_CHECKSUM_CHECK_TCP 0x0400 00126 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800 00127 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000 00128 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF 00129 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000 00130 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 00131 00132 struct netif; 00133 00134 /** Function prototype for netif init functions. Set up flags and output/linkoutput 00135 * callback functions in this function. 00136 * 00137 * @param netif The netif to initialize 00138 */ 00139 typedef err_t (*netif_init_fn)(struct netif *netif); 00140 /** Function prototype for netif->input functions. This function is saved as 'input' 00141 * callback function in the netif struct. Call it when a packet has been received. 00142 * 00143 * @param p The received packet, copied into a pbuf 00144 * @param inp The netif which received the packet 00145 */ 00146 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); 00147 00148 #if LWIP_IPV4 00149 /** Function prototype for netif->output functions. Called by lwIP when a packet 00150 * shall be sent. For ethernet netif, set this to 'etharp_output' and set 00151 * 'linkoutput'. 00152 * 00153 * @param netif The netif which shall send a packet 00154 * @param p The packet to send (p->payload points to IP header) 00155 * @param ipaddr The IP address to which the packet shall be sent 00156 */ 00157 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, 00158 const ip4_addr_t *ipaddr); 00159 #endif /* LWIP_IPV4*/ 00160 00161 #if LWIP_IPV6 00162 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet 00163 * shall be sent. For ethernet netif, set this to 'ethip6_output' and set 00164 * 'linkoutput'. 00165 * 00166 * @param netif The netif which shall send a packet 00167 * @param p The packet to send (p->payload points to IP header) 00168 * @param ipaddr The IPv6 address to which the packet shall be sent 00169 */ 00170 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, 00171 const ip6_addr_t *ipaddr); 00172 #endif /* LWIP_IPV6 */ 00173 00174 /** Function prototype for netif->linkoutput functions. Only used for ethernet 00175 * netifs. This function is called by ARP when a packet shall be sent. 00176 * 00177 * @param netif The netif which shall send a packet 00178 * @param p The packet to send (raw ethernet packet) 00179 */ 00180 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); 00181 /** Function prototype for netif status- or link-callback functions. */ 00182 typedef void (*netif_status_callback_fn)(struct netif *netif); 00183 #if LWIP_IPV4 && LWIP_IGMP 00184 /** Function prototype for netif igmp_mac_filter functions */ 00185 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, 00186 const ip4_addr_t *group, u8_t action); 00187 #endif /* LWIP_IPV4 && LWIP_IGMP */ 00188 #if LWIP_IPV6 && LWIP_IPV6_MLD 00189 /** Function prototype for netif mld_mac_filter functions */ 00190 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, 00191 const ip6_addr_t *group, u8_t action); 00192 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 00193 00194 /** Generic data structure used for all lwIP network interfaces. 00195 * The following fields should be filled in by the initialization 00196 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ 00197 struct netif { 00198 /** pointer to next in linked list */ 00199 struct netif *next; 00200 00201 #if LWIP_IPV4 00202 /** IP address configuration in network byte order */ 00203 ip_addr_t ip_addr; 00204 ip_addr_t netmask; 00205 ip_addr_t gw; 00206 #endif /* LWIP_IPV4 */ 00207 #if LWIP_IPV6 00208 /** Array of IPv6 addresses for this netif. */ 00209 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; 00210 /** The state of each IPv6 address (Tentative, Preferred, etc). 00211 * @see ip6_addr.h */ 00212 u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; 00213 #endif /* LWIP_IPV6 */ 00214 /** This function is called by the network device driver 00215 * to pass a packet up the TCP/IP stack. */ 00216 netif_input_fn input; 00217 #if LWIP_IPV4 00218 /** This function is called by the IP module when it wants 00219 * to send a packet on the interface. This function typically 00220 * first resolves the hardware address, then sends the packet. */ 00221 netif_output_fn output; 00222 #endif /* LWIP_IPV4 */ 00223 /** This function is called by the ARP module when it wants 00224 * to send a packet on the interface. This function outputs 00225 * the pbuf as-is on the link medium. */ 00226 netif_linkoutput_fn linkoutput; 00227 #if LWIP_IPV6 00228 /** This function is called by the IPv6 module when it wants 00229 * to send a packet on the interface. This function typically 00230 * first resolves the hardware address, then sends the packet. */ 00231 netif_output_ip6_fn output_ip6; 00232 #endif /* LWIP_IPV6 */ 00233 #if LWIP_NETIF_STATUS_CALLBACK 00234 /** This function is called when the netif state is set to up or down 00235 */ 00236 netif_status_callback_fn status_callback; 00237 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 00238 #if LWIP_NETIF_LINK_CALLBACK 00239 /** This function is called when the netif link is set to up or down 00240 */ 00241 netif_status_callback_fn link_callback; 00242 #endif /* LWIP_NETIF_LINK_CALLBACK */ 00243 #if LWIP_NETIF_REMOVE_CALLBACK 00244 /** This function is called when the netif has been removed */ 00245 netif_status_callback_fn remove_callback; 00246 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 00247 /** This field can be set by the device driver and could point 00248 * to state information for the device. */ 00249 void *state; 00250 #if LWIP_DHCP 00251 /** the DHCP client state information for this netif */ 00252 struct dhcp *dhcp; 00253 #endif /* LWIP_DHCP */ 00254 #if LWIP_AUTOIP 00255 /** the AutoIP client state information for this netif */ 00256 struct autoip *autoip; 00257 #endif 00258 #if LWIP_IPV6_AUTOCONFIG 00259 /** is this netif enabled for IPv6 autoconfiguration */ 00260 u8_t ip6_autoconfig_enabled; 00261 #endif /* LWIP_IPV6_AUTOCONFIG */ 00262 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 00263 /** Number of Router Solicitation messages that remain to be sent. */ 00264 u8_t rs_count; 00265 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ 00266 #if LWIP_IPV6_DHCP6 00267 /** the DHCPv6 client state information for this netif */ 00268 struct dhcp6 *dhcp6; 00269 #endif /* LWIP_IPV6_DHCP6 */ 00270 #if LWIP_NETIF_HOSTNAME 00271 /* the hostname for this netif, NULL is a valid value */ 00272 const char* hostname; 00273 #endif /* LWIP_NETIF_HOSTNAME */ 00274 #if LWIP_CHECKSUM_CTRL_PER_NETIF 00275 u16_t chksum_flags; 00276 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/ 00277 /** maximum transfer unit (in bytes) */ 00278 u16_t mtu; 00279 /** number of bytes used in hwaddr */ 00280 u8_t hwaddr_len; 00281 /** link level hardware address of this interface */ 00282 u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; 00283 /** flags (@see @ref netif_flags) */ 00284 u8_t flags; 00285 /** descriptive abbreviation */ 00286 char name[2]; 00287 /** number of this interface */ 00288 u8_t num; 00289 #if MIB2_STATS 00290 /** link type (from "snmp_ifType" enum from snmp_mib2.h) */ 00291 u8_t link_type; 00292 /** (estimate) link speed */ 00293 u32_t link_speed; 00294 /** timestamp at last change made (up/down) */ 00295 u32_t ts; 00296 /** counters */ 00297 struct stats_mib2_netif_ctrs mib2_counters; 00298 #endif /* MIB2_STATS */ 00299 #if LWIP_IPV4 && LWIP_IGMP 00300 /** This function could be called to add or delete an entry in the multicast 00301 filter table of the ethernet MAC.*/ 00302 netif_igmp_mac_filter_fn igmp_mac_filter; 00303 #endif /* LWIP_IPV4 && LWIP_IGMP */ 00304 #if LWIP_IPV6 && LWIP_IPV6_MLD 00305 /** This function could be called to add or delete an entry in the IPv6 multicast 00306 filter table of the ethernet MAC. */ 00307 netif_mld_mac_filter_fn mld_mac_filter; 00308 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 00309 #if LWIP_NETIF_HWADDRHINT 00310 u8_t *addr_hint; 00311 #endif /* LWIP_NETIF_HWADDRHINT */ 00312 #if ENABLE_LOOPBACK 00313 /* List of packets to be queued for ourselves. */ 00314 struct pbuf *loop_first; 00315 struct pbuf *loop_last; 00316 #if LWIP_LOOPBACK_MAX_PBUFS 00317 u16_t loop_cnt_current; 00318 #endif /* LWIP_LOOPBACK_MAX_PBUFS */ 00319 #endif /* ENABLE_LOOPBACK */ 00320 }; 00321 00322 #if LWIP_CHECKSUM_CTRL_PER_NETIF 00323 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \ 00324 (netif)->chksum_flags = chksumflags; } while(0) 00325 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0)) 00326 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 00327 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) 00328 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) 00329 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 00330 00331 /** The list of network interfaces. */ 00332 extern struct netif *netif_list; 00333 /** The default network interface. */ 00334 extern struct netif *netif_default; 00335 00336 void netif_init(void); 00337 00338 struct netif *netif_add(struct netif *netif, 00339 #if LWIP_IPV4 00340 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, 00341 #endif /* LWIP_IPV4 */ 00342 void *state, netif_init_fn init, netif_input_fn input); 00343 #if LWIP_IPV4 00344 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, 00345 const ip4_addr_t *gw); 00346 #endif /* LWIP_IPV4 */ 00347 void netif_remove(struct netif * netif); 00348 00349 /* Returns a network interface given its name. The name is of the form 00350 "et0", where the first two letters are the "name" field in the 00351 netif structure, and the digit is in the num field in the same 00352 structure. */ 00353 struct netif *netif_find(const char *name); 00354 00355 void netif_set_default(struct netif *netif); 00356 00357 #if LWIP_IPV4 00358 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); 00359 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); 00360 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); 00361 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) 00362 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) 00363 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) 00364 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) 00365 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) 00366 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) 00367 #endif /* LWIP_IPV4 */ 00368 00369 void netif_set_up(struct netif *netif); 00370 void netif_set_down(struct netif *netif); 00371 /** @ingroup netif 00372 * Ask if an interface is up 00373 */ 00374 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) 00375 00376 #if LWIP_NETIF_STATUS_CALLBACK 00377 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); 00378 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 00379 #if LWIP_NETIF_REMOVE_CALLBACK 00380 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); 00381 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 00382 00383 void netif_set_link_up(struct netif *netif); 00384 void netif_set_link_down(struct netif *netif); 00385 /** Ask if a link is up */ 00386 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) 00387 00388 #if LWIP_NETIF_LINK_CALLBACK 00389 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); 00390 #endif /* LWIP_NETIF_LINK_CALLBACK */ 00391 00392 #if LWIP_NETIF_HOSTNAME 00393 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) 00394 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) 00395 #endif /* LWIP_NETIF_HOSTNAME */ 00396 00397 #if LWIP_IGMP 00398 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) 00399 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) 00400 #endif /* LWIP_IGMP */ 00401 00402 #if LWIP_IPV6 && LWIP_IPV6_MLD 00403 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) 00404 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) 00405 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) 00406 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 00407 00408 #if ENABLE_LOOPBACK 00409 err_t netif_loop_output(struct netif *netif, struct pbuf *p); 00410 void netif_poll(struct netif *netif); 00411 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 00412 void netif_poll_all(void); 00413 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ 00414 #endif /* ENABLE_LOOPBACK */ 00415 00416 err_t netif_input(struct pbuf *p, struct netif *inp); 00417 00418 #if LWIP_IPV6 00419 /** @ingroup netif */ 00420 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) 00421 /** @ingroup netif */ 00422 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) 00423 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, ip6_addr_t *addr6); 00424 void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3); 00425 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) 00426 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); 00427 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); 00428 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); 00429 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); 00430 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0) 00431 #endif /* LWIP_IPV6 */ 00432 00433 #if LWIP_NETIF_HWADDRHINT 00434 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint)) 00435 #else /* LWIP_NETIF_HWADDRHINT */ 00436 #define NETIF_SET_HWADDRHINT(netif, hint) 00437 #endif /* LWIP_NETIF_HWADDRHINT */ 00438 00439 #ifdef __cplusplus 00440 } 00441 #endif 00442 00443 #endif /* LWIP_HDR_NETIF_H */
Generated on Tue Jul 12 2022 18:19:32 by
1.7.2