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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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 <stdbool.h> 00041 #include "lwip/opt.h" 00042 00043 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) 00044 00045 #include "lwip/err.h" 00046 00047 #include "lwip/ip_addr.h" 00048 00049 #include "lwip/def.h" 00050 #include "lwip/pbuf.h" 00051 #include "lwip/stats.h" 00052 00053 #ifdef __cplusplus 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 This does not have to be changed, normally. */ 00063 #ifndef NETIF_MAX_HWADDR_LEN 00064 #define NETIF_MAX_HWADDR_LEN 6U 00065 #endif 00066 00067 /** The size of a fully constructed netif name which the 00068 * netif can be identified by in APIs. Composed of 00069 * 2 chars, 3 (max) digits, and 1 \0 00070 */ 00071 #define NETIF_NAMESIZE 6 00072 00073 /** 00074 * @defgroup netif_flags Flags 00075 * @ingroup netif 00076 * @{ 00077 */ 00078 00079 /** Whether the network interface is 'up'. This is 00080 * a software flag used to control whether this network 00081 * interface is enabled and processes traffic. 00082 * It must be set by the startup code before this netif can be used 00083 * (also for dhcp/autoip). 00084 */ 00085 #define NETIF_FLAG_UP 0x01U 00086 /** If set, the netif has broadcast capability. 00087 * Set by the netif driver in its init function. */ 00088 #define NETIF_FLAG_BROADCAST 0x02U 00089 /** If set, the interface has an active link 00090 * (set by the network interface driver). 00091 * Either set by the netif driver in its init function (if the link 00092 * is up at that time) or at a later point once the link comes up 00093 * (if link detection is supported by the hardware). */ 00094 #define NETIF_FLAG_LINK_UP 0x04U 00095 /** If set, the netif is an ethernet device using ARP. 00096 * Set by the netif driver in its init function. 00097 * Used to check input packet types and use of DHCP. */ 00098 #define NETIF_FLAG_ETHARP 0x08U 00099 /** If set, the netif is an ethernet device. It might not use 00100 * ARP or TCP/IP if it is used for PPPoE only. 00101 */ 00102 #define NETIF_FLAG_ETHERNET 0x10U 00103 /** If set, the netif has IGMP capability. 00104 * Set by the netif driver in its init function. */ 00105 #define NETIF_FLAG_IGMP 0x20U 00106 /** If set, the netif has MLD6 capability. 00107 * Set by the netif driver in its init function. */ 00108 #define NETIF_FLAG_MLD6 0x40U 00109 00110 /** 00111 * @} 00112 */ 00113 00114 enum lwip_internal_netif_client_data_index 00115 { 00116 #if LWIP_IPV4 00117 #if LWIP_DHCP 00118 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, 00119 #endif 00120 #if LWIP_AUTOIP 00121 LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, 00122 #endif 00123 #if LWIP_IGMP 00124 LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, 00125 #endif 00126 #endif /* LWIP_IPV4 */ 00127 #if LWIP_IPV6 00128 #if LWIP_IPV6_DHCP6 00129 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, 00130 #endif 00131 #if LWIP_IPV6_MLD 00132 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, 00133 #endif 00134 #endif /* LWIP_IPV6 */ 00135 LWIP_NETIF_CLIENT_DATA_INDEX_MAX 00136 }; 00137 00138 #if LWIP_CHECKSUM_CTRL_PER_NETIF 00139 #define NETIF_CHECKSUM_GEN_IP 0x0001 00140 #define NETIF_CHECKSUM_GEN_UDP 0x0002 00141 #define NETIF_CHECKSUM_GEN_TCP 0x0004 00142 #define NETIF_CHECKSUM_GEN_ICMP 0x0008 00143 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010 00144 #define NETIF_CHECKSUM_CHECK_IP 0x0100 00145 #define NETIF_CHECKSUM_CHECK_UDP 0x0200 00146 #define NETIF_CHECKSUM_CHECK_TCP 0x0400 00147 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800 00148 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000 00149 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF 00150 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000 00151 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 00152 00153 struct netif; 00154 00155 /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or 00156 * mld_mac_filter callback function. */ 00157 enum netif_mac_filter_action { 00158 /** Delete a filter entry */ 00159 NETIF_DEL_MAC_FILTER = 0, 00160 /** Add a filter entry */ 00161 NETIF_ADD_MAC_FILTER = 1 00162 }; 00163 00164 /** Function prototype for netif init functions. Set up flags and output/linkoutput 00165 * callback functions in this function. 00166 * 00167 * @param netif The netif to initialize 00168 */ 00169 typedef err_t (*netif_init_fn)(struct netif *netif); 00170 /** Function prototype for netif->input functions. This function is saved as 'input' 00171 * callback function in the netif struct. Call it when a packet has been received. 00172 * 00173 * @param p The received packet, copied into a pbuf 00174 * @param inp The netif which received the packet 00175 * @return ERR_OK if the packet was handled 00176 * != ERR_OK is the packet was NOT handled, in this case, the caller has 00177 * to free the pbuf 00178 */ 00179 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); 00180 00181 #if LWIP_IPV4 00182 /** Function prototype for netif->output functions. Called by lwIP when a packet 00183 * shall be sent. For ethernet netif, set this to 'etharp_output' and set 00184 * 'linkoutput'. 00185 * 00186 * @param netif The netif which shall send a packet 00187 * @param p The packet to send (p->payload points to IP header) 00188 * @param ipaddr The IP address to which the packet shall be sent 00189 */ 00190 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, 00191 const ip4_addr_t *ipaddr); 00192 #endif /* LWIP_IPV4*/ 00193 00194 #if LWIP_IPV6 00195 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet 00196 * shall be sent. For ethernet netif, set this to 'ethip6_output' and set 00197 * 'linkoutput'. 00198 * 00199 * @param netif The netif which shall send a packet 00200 * @param p The packet to send (p->payload points to IP header) 00201 * @param ipaddr The IPv6 address to which the packet shall be sent 00202 */ 00203 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, 00204 const ip6_addr_t *ipaddr); 00205 #endif /* LWIP_IPV6 */ 00206 00207 /** Function prototype for netif->linkoutput functions. Only used for ethernet 00208 * netifs. This function is called by ARP when a packet shall be sent. 00209 * 00210 * @param netif The netif which shall send a packet 00211 * @param p The packet to send (raw ethernet packet) 00212 */ 00213 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); 00214 /** Function prototype for netif status- or link-callback functions. */ 00215 typedef void (*netif_status_callback_fn)(struct netif *netif); 00216 #if LWIP_IPV4 && LWIP_IGMP 00217 /** Function prototype for netif igmp_mac_filter functions */ 00218 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, 00219 const ip4_addr_t *group, enum netif_mac_filter_action action); 00220 #endif /* LWIP_IPV4 && LWIP_IGMP */ 00221 #if LWIP_IPV6 && LWIP_IPV6_MLD 00222 /** Function prototype for netif mld_mac_filter functions */ 00223 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, 00224 const ip6_addr_t *group, enum netif_mac_filter_action action); 00225 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 00226 00227 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || LWIP_IPV6_DHCP6 || (LWIP_NUM_NETIF_CLIENT_DATA > 0) 00228 #if LWIP_NUM_NETIF_CLIENT_DATA > 0 00229 u8_t netif_alloc_client_data_id(void); 00230 #endif 00231 /** @ingroup netif_cd 00232 * Set client data. Obtain ID from netif_alloc_client_data_id(). 00233 */ 00234 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) 00235 /** @ingroup netif_cd 00236 * Get client data. Obtain ID from netif_alloc_client_data_id(). 00237 */ 00238 #define netif_get_client_data(netif, id) (netif)->client_data[(id)] 00239 #endif 00240 00241 #if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f)) 00242 typedef u16_t netif_addr_idx_t; 00243 #define NETIF_ADDR_IDX_MAX 0x7FFF 00244 #else 00245 typedef u8_t netif_addr_idx_t; 00246 #define NETIF_ADDR_IDX_MAX 0x7F 00247 #endif 00248 00249 #if LWIP_NETIF_HWADDRHINT 00250 #define LWIP_NETIF_USE_HINTS 1 00251 struct netif_hint { 00252 netif_addr_idx_t addr_hint; 00253 }; 00254 #else /* LWIP_NETIF_HWADDRHINT */ 00255 #define LWIP_NETIF_USE_HINTS 0 00256 #endif /* LWIP_NETIF_HWADDRHINT */ 00257 00258 /** Generic data structure used for all lwIP network interfaces. 00259 * The following fields should be filled in by the initialization 00260 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ 00261 struct netif { 00262 #if !LWIP_SINGLE_NETIF 00263 /** pointer to next in linked list */ 00264 struct netif *next; 00265 #endif 00266 00267 #if LWIP_IPV4 00268 /** IP address configuration in network byte order */ 00269 ip_addr_t ip_addr; 00270 ip_addr_t netmask; 00271 ip_addr_t gw; 00272 #endif /* LWIP_IPV4 */ 00273 #if LWIP_IPV6 00274 /** Array of IPv6 addresses for this netif. */ 00275 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; 00276 /** The state of each IPv6 address (Tentative, Preferred, etc). 00277 * @see ip6_addr.h */ 00278 u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; 00279 #if LWIP_IPV6_ADDRESS_LIFETIMES 00280 /** Remaining valid and preferred lifetime of each IPv6 address, in seconds. 00281 * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0) 00282 * indicates the address is static and has no lifetimes. */ 00283 u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES]; 00284 u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES]; 00285 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */ 00286 #endif /* LWIP_IPV6 */ 00287 /** This function is called by the network device driver 00288 * to pass a packet up the TCP/IP stack. */ 00289 netif_input_fn input; 00290 #if LWIP_IPV4 00291 /** This function is called by the IP module when it wants 00292 * to send a packet on the interface. This function typically 00293 * first resolves the hardware address, then sends the packet. 00294 * For ethernet physical layer, this is usually etharp_output() */ 00295 netif_output_fn output; 00296 #endif /* LWIP_IPV4 */ 00297 /** This function is called by ethernet_output() when it wants 00298 * to send a packet on the interface. This function outputs 00299 * the pbuf as-is on the link medium. */ 00300 netif_linkoutput_fn linkoutput; 00301 #if LWIP_IPV6 00302 /** This function is called by the IPv6 module when it wants 00303 * to send a packet on the interface. This function typically 00304 * first resolves the hardware address, then sends the packet. 00305 * For ethernet physical layer, this is usually ethip6_output() */ 00306 netif_output_ip6_fn output_ip6; 00307 #endif /* LWIP_IPV6 */ 00308 #if LWIP_NETIF_STATUS_CALLBACK 00309 /** This function is called when the netif state is set to up or down 00310 */ 00311 netif_status_callback_fn status_callback; 00312 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 00313 #if LWIP_NETIF_LINK_CALLBACK 00314 /** This function is called when the netif link is set to up or down 00315 */ 00316 netif_status_callback_fn link_callback; 00317 #endif /* LWIP_NETIF_LINK_CALLBACK */ 00318 #if LWIP_NETIF_REMOVE_CALLBACK 00319 /** This function is called when the netif has been removed */ 00320 netif_status_callback_fn remove_callback; 00321 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 00322 /** This field can be set by the device driver and could point 00323 * to state information for the device. */ 00324 void *state; 00325 #ifdef netif_get_client_data 00326 void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; 00327 #endif 00328 #if LWIP_NETIF_HOSTNAME 00329 /* the hostname for this netif, NULL is a valid value */ 00330 const char* hostname; 00331 #endif /* LWIP_NETIF_HOSTNAME */ 00332 #if LWIP_CHECKSUM_CTRL_PER_NETIF 00333 u16_t chksum_flags; 00334 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/ 00335 /** maximum transfer unit (in bytes) */ 00336 u16_t mtu; 00337 #if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES 00338 /** maximum transfer unit (in bytes), updated by RA */ 00339 u16_t mtu6; 00340 #endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */ 00341 /** link level hardware address of this interface */ 00342 u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; 00343 /** number of bytes used in hwaddr */ 00344 u8_t hwaddr_len; 00345 /** flags (@see @ref netif_flags) */ 00346 u8_t flags; 00347 /** descriptive abbreviation */ 00348 char name[2]; 00349 /** number of this interface. Used for @ref if_api and @ref netifapi_netif, 00350 * as well as for IPv6 zones */ 00351 u8_t num; 00352 #if LWIP_IPV6_AUTOCONFIG 00353 /** is this netif enabled for IPv6 autoconfiguration */ 00354 u8_t ip6_autoconfig_enabled; 00355 #endif /* LWIP_IPV6_AUTOCONFIG */ 00356 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 00357 /** Number of Router Solicitation messages that remain to be sent. */ 00358 u8_t rs_count; 00359 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ 00360 #if MIB2_STATS 00361 /** link type (from "snmp_ifType" enum from snmp_mib2.h) */ 00362 u8_t link_type; 00363 /** (estimate) link speed */ 00364 u32_t link_speed; 00365 /** timestamp at last change made (up/down) */ 00366 u32_t ts; 00367 /** counters */ 00368 struct stats_mib2_netif_ctrs mib2_counters; 00369 #endif /* MIB2_STATS */ 00370 #if LWIP_IPV4 && LWIP_IGMP 00371 /** This function could be called to add or delete an entry in the multicast 00372 filter table of the ethernet MAC.*/ 00373 netif_igmp_mac_filter_fn igmp_mac_filter; 00374 #endif /* LWIP_IPV4 && LWIP_IGMP */ 00375 #if LWIP_IPV6 && LWIP_IPV6_MLD 00376 /** This function could be called to add or delete an entry in the IPv6 multicast 00377 filter table of the ethernet MAC. */ 00378 netif_mld_mac_filter_fn mld_mac_filter; 00379 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 00380 #if LWIP_NETIF_USE_HINTS 00381 struct netif_hint *hints; 00382 #endif /* LWIP_NETIF_USE_HINTS */ 00383 #if ENABLE_LOOPBACK 00384 /* List of packets to be queued for ourselves. */ 00385 struct pbuf *loop_first; 00386 struct pbuf *loop_last; 00387 #if LWIP_LOOPBACK_MAX_PBUFS 00388 u16_t loop_cnt_current; 00389 #endif /* LWIP_LOOPBACK_MAX_PBUFS */ 00390 #endif /* ENABLE_LOOPBACK */ 00391 }; 00392 00393 #if LWIP_CHECKSUM_CTRL_PER_NETIF 00394 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \ 00395 (netif)->chksum_flags = chksumflags; } while(0) 00396 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0)) 00397 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 00398 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) 00399 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) 00400 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 00401 00402 #if LWIP_SINGLE_NETIF 00403 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL) 00404 #else /* LWIP_SINGLE_NETIF */ 00405 /** The list of network interfaces. */ 00406 extern struct netif *netif_list; 00407 #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next) 00408 #endif /* LWIP_SINGLE_NETIF */ 00409 /** The default network interface. */ 00410 extern struct netif *netif_default; 00411 00412 void netif_init(void); 00413 00414 struct netif *netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); 00415 00416 #if LWIP_IPV4 00417 struct netif *netif_add(struct netif *netif, 00418 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, 00419 void *state, netif_init_fn init, netif_input_fn input); 00420 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, 00421 const ip4_addr_t *gw); 00422 #else /* LWIP_IPV4 */ 00423 struct netif *netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); 00424 #endif /* LWIP_IPV4 */ 00425 void netif_remove(struct netif * netif); 00426 00427 /* Returns a network interface given its name. The name is of the form 00428 "et0", where the first two letters are the "name" field in the 00429 netif structure, and the digit is in the num field in the same 00430 structure. */ 00431 struct netif *netif_find(const char *name); 00432 00433 /* Returns a network interface name in the form 00434 "et0", where the first two letters are the "name" field in the 00435 netif structure, and the digit is in the num field in the same 00436 structure. */ 00437 const char *netif_get_name(struct netif *netif); 00438 00439 void netif_set_default(struct netif *netif); 00440 bool netif_check_default(struct netif *netif); 00441 00442 00443 #if LWIP_IPV4 00444 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); 00445 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); 00446 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); 00447 /** @ingroup netif_ip4 */ 00448 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) 00449 /** @ingroup netif_ip4 */ 00450 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) 00451 /** @ingroup netif_ip4 */ 00452 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) 00453 /** @ingroup netif_ip4 */ 00454 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) 00455 /** @ingroup netif_ip4 */ 00456 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) 00457 /** @ingroup netif_ip4 */ 00458 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) 00459 #endif /* LWIP_IPV4 */ 00460 00461 #define netif_set_flags(netif, set_flags) do { (netif)->flags = (u8_t)((netif)->flags | (set_flags)); } while(0) 00462 #define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u8_t)((netif)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) 00463 #define netif_is_flag_set(nefif, flag) (((netif)->flags & (flag)) != 0) 00464 00465 void netif_set_up(struct netif *netif); 00466 void netif_set_down(struct netif *netif); 00467 /** @ingroup netif 00468 * Ask if an interface is up 00469 */ 00470 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) 00471 00472 #if LWIP_NETIF_STATUS_CALLBACK 00473 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); 00474 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 00475 #if LWIP_NETIF_REMOVE_CALLBACK 00476 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); 00477 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 00478 00479 void netif_set_link_up(struct netif *netif); 00480 void netif_set_link_down(struct netif *netif); 00481 /** Ask if a link is up */ 00482 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) 00483 00484 #if LWIP_NETIF_LINK_CALLBACK 00485 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); 00486 #endif /* LWIP_NETIF_LINK_CALLBACK */ 00487 00488 #if LWIP_NETIF_HOSTNAME 00489 /** @ingroup netif */ 00490 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) 00491 /** @ingroup netif */ 00492 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) 00493 #endif /* LWIP_NETIF_HOSTNAME */ 00494 00495 #if LWIP_IGMP 00496 /** @ingroup netif */ 00497 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) 00498 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) 00499 #endif /* LWIP_IGMP */ 00500 00501 #if LWIP_IPV6 && LWIP_IPV6_MLD 00502 /** @ingroup netif */ 00503 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) 00504 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) 00505 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) 00506 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 00507 00508 #if ENABLE_LOOPBACK 00509 err_t netif_loop_output(struct netif *netif, struct pbuf *p); 00510 void netif_poll(struct netif *netif); 00511 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 00512 void netif_poll_all(void); 00513 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ 00514 #endif /* ENABLE_LOOPBACK */ 00515 00516 err_t netif_input(struct pbuf *p, struct netif *inp); 00517 00518 #if LWIP_IPV6 00519 /** @ingroup netif_ip6 */ 00520 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) 00521 /** @ingroup netif_ip6 */ 00522 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) 00523 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); 00524 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); 00525 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) 00526 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); 00527 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); 00528 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); 00529 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); 00530 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0) 00531 #if LWIP_IPV6_ADDRESS_LIFETIMES 00532 #define netif_ip6_addr_valid_life(netif, i) \ 00533 (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC) 00534 #define netif_ip6_addr_set_valid_life(netif, i, secs) \ 00535 do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0) 00536 #define netif_ip6_addr_pref_life(netif, i) \ 00537 (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC) 00538 #define netif_ip6_addr_set_pref_life(netif, i, secs) \ 00539 do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0) 00540 #define netif_ip6_addr_isstatic(netif, i) \ 00541 (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC) 00542 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 00543 #define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */ 00544 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 00545 #if LWIP_ND6_ALLOW_RA_UPDATES 00546 #define netif_mtu6(netif) ((netif)->mtu6) 00547 #else /* LWIP_ND6_ALLOW_RA_UPDATES */ 00548 #define netif_mtu6(netif) ((netif)->mtu) 00549 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */ 00550 #endif /* LWIP_IPV6 */ 00551 00552 #if LWIP_NETIF_USE_HINTS 00553 #define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint) 00554 #define NETIF_RESET_HINTS(netif) (netif)->hints = NULL 00555 #else /* LWIP_NETIF_USE_HINTS */ 00556 #define NETIF_SET_HINTS(netif, netifhint) 00557 #define NETIF_RESET_HINTS(netif) 00558 #endif /* LWIP_NETIF_USE_HINTS */ 00559 00560 u8_t netif_name_to_index(const char *name); 00561 char * netif_index_to_name(u8_t idx, char *name); 00562 struct netif* netif_get_by_index(u8_t idx); 00563 00564 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/ 00565 #define netif_get_index(netif) ((u8_t)((netif)->num + 1)) 00566 #define NETIF_NO_INDEX (0) 00567 00568 /** 00569 * @ingroup netif 00570 * Extended netif status callback (NSC) reasons flags. 00571 * May be extended in the future! 00572 */ 00573 typedef u16_t netif_nsc_reason_t; 00574 00575 /* used for initialization only */ 00576 #define LWIP_NSC_NONE 0x0000 00577 /** netif was added. arg: NULL. Called AFTER netif was added. */ 00578 #define LWIP_NSC_NETIF_ADDED 0x0001 00579 /** netif was removed. arg: NULL. Called BEFORE netif is removed. */ 00580 #define LWIP_NSC_NETIF_REMOVED 0x0002 00581 /** link changed */ 00582 #define LWIP_NSC_LINK_CHANGED 0x0004 00583 /** netif administrative status changed.\n 00584 * up is called AFTER netif is set up.\n 00585 * down is called BEFORE the netif is actually set down. */ 00586 #define LWIP_NSC_STATUS_CHANGED 0x0008 00587 /** IPv4 address has changed */ 00588 #define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010 00589 /** IPv4 gateway has changed */ 00590 #define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020 00591 /** IPv4 netmask has changed */ 00592 #define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040 00593 /** called AFTER IPv4 address/gateway/netmask changes have been applied */ 00594 #define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080 00595 /** IPv6 address was added */ 00596 #define LWIP_NSC_IPV6_SET 0x0100 00597 /** IPv6 address state has changed */ 00598 #define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200 00599 00600 /** @ingroup netif 00601 * Argument supplied to netif_ext_callback_fn. 00602 */ 00603 typedef union 00604 { 00605 /** Args to LWIP_NSC_LINK_CHANGED callback */ 00606 struct link_changed_s 00607 { 00608 /** 1: up; 0: down */ 00609 u8_t state; 00610 } link_changed; 00611 /** Args to LWIP_NSC_STATUS_CHANGED callback */ 00612 struct status_changed_s 00613 { 00614 /** 1: up; 0: down */ 00615 u8_t state; 00616 } status_changed; 00617 /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */ 00618 struct ipv4_changed_s 00619 { 00620 /** Old IPv4 address */ 00621 const ip_addr_t* old_address; 00622 const ip_addr_t* old_netmask; 00623 const ip_addr_t* old_gw; 00624 } ipv4_changed; 00625 /** Args to LWIP_NSC_IPV6_SET callback */ 00626 struct ipv6_set_s 00627 { 00628 /** Index of changed IPv6 address */ 00629 s8_t addr_index; 00630 /** Old IPv6 address */ 00631 const ip_addr_t* old_address; 00632 } ipv6_set; 00633 /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */ 00634 struct ipv6_addr_state_changed_s 00635 { 00636 /** Index of affected IPv6 address */ 00637 s8_t addr_index; 00638 /** Old IPv6 address state */ 00639 u8_t old_state; 00640 /** Affected IPv6 address */ 00641 const ip_addr_t* address; 00642 } ipv6_addr_state_changed; 00643 } netif_ext_callback_args_t; 00644 00645 /** 00646 * @ingroup netif 00647 * Function used for extended netif status callbacks 00648 * Note: When parsing reason argument, keep in mind that more reasons may be added in the future! 00649 * @param netif netif that is affected by change 00650 * @param reason change reason 00651 * @param args depends on reason, see reason description 00652 */ 00653 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 00654 00655 #if LWIP_NETIF_EXT_STATUS_CALLBACK 00656 struct netif_ext_callback; 00657 typedef struct netif_ext_callback 00658 { 00659 netif_ext_callback_fn callback_fn; 00660 struct netif_ext_callback* next; 00661 } netif_ext_callback_t; 00662 00663 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name; 00664 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn); 00665 void netif_remove_ext_callback(netif_ext_callback_t* callback); 00666 void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 00667 #else 00668 #define NETIF_DECLARE_EXT_CALLBACK(name) 00669 #define netif_add_ext_callback(callback, fn) 00670 #define netif_remove_ext_callback(callback) 00671 #define netif_invoke_ext_callback(netif, reason, args) 00672 #endif 00673 00674 #ifdef __cplusplus 00675 } 00676 #endif 00677 00678 #endif /* LWIP_HDR_NETIF_H */
Generated on Tue Jul 12 2022 13:54:37 by
