1 /** 2 * @file 3 * netif API (to be used from TCPIP thread) 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Adam Dunkels <adam@sics.se> 35 * 36 */ 37 #ifndef LWIP_HDR_NETIF_H 38 #define LWIP_HDR_NETIF_H 39 40 #include "lwip/opt.h" 41 42 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) 43 44 #include "lwip/err.h" 45 46 #include "lwip/ip_addr.h" 47 48 #include "lwip/def.h" 49 #include "lwip/pbuf.h" 50 #include "lwip/stats.h" 51 52 #ifdef __cplusplus 53 extern "C" { 54 #endif 55 56 /* Throughout this file, IP addresses are expected to be in 57 * the same byte order as in IP_PCB. */ 58 59 /** Must be the maximum of all used hardware address lengths 60 across all types of interfaces in use. 61 This does not have to be changed, normally. */ 62 #ifndef NETIF_MAX_HWADDR_LEN 63 #define NETIF_MAX_HWADDR_LEN 6U 64 #endif 65 66 /** The size of a fully constructed netif name which the 67 * netif can be identified by in APIs. Composed of 68 * 2 chars, 3 (max) digits, and 1 \0 69 */ 70 #define NETIF_NAMESIZE 6 71 72 /** 73 * @defgroup netif_flags Flags 74 * @ingroup netif 75 * @{ 76 */ 77 78 /** Whether the network interface is 'up'. This is 79 * a software flag used to control whether this network 80 * interface is enabled and processes traffic. 81 * It must be set by the startup code before this netif can be used 82 * (also for dhcp/autoip). 83 */ 84 #define NETIF_FLAG_UP 0x01U 85 /** If set, the netif has broadcast capability. 86 * Set by the netif driver in its init function. */ 87 #define NETIF_FLAG_BROADCAST 0x02U 88 /** If set, the interface has an active link 89 * (set by the network interface driver). 90 * Either set by the netif driver in its init function (if the link 91 * is up at that time) or at a later point once the link comes up 92 * (if link detection is supported by the hardware). */ 93 #define NETIF_FLAG_LINK_UP 0x04U 94 /** If set, the netif is an ethernet device using ARP. 95 * Set by the netif driver in its init function. 96 * Used to check input packet types and use of DHCP. */ 97 #define NETIF_FLAG_ETHARP 0x08U 98 /** If set, the netif is an ethernet device. It might not use 99 * ARP or TCP/IP if it is used for PPPoE only. 100 */ 101 #define NETIF_FLAG_ETHERNET 0x10U 102 /** If set, the netif has IGMP capability. 103 * Set by the netif driver in its init function. */ 104 #define NETIF_FLAG_IGMP 0x20U 105 /** If set, the netif has MLD6 capability. 106 * Set by the netif driver in its init function. */ 107 #define NETIF_FLAG_MLD6 0x40U 108 109 #if ESP_GRATUITOUS_ARP 110 /** If set, the netif will send gratuitous ARP periodically */ 111 #define NETIF_FLAG_GARP 0x80U 112 #endif 113 114 /** 115 * @} 116 */ 117 118 enum lwip_internal_netif_client_data_index 119 { 120 #if LWIP_IPV4 121 #if LWIP_DHCP 122 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, 123 #endif 124 #if LWIP_AUTOIP 125 LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, 126 #endif 127 #if LWIP_IGMP 128 LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, 129 #endif 130 #endif /* LWIP_IPV4 */ 131 #if LWIP_IPV6 132 #if LWIP_IPV6_DHCP6 133 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, 134 #endif 135 #if LWIP_IPV6_MLD 136 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, 137 #endif 138 #endif /* LWIP_IPV6 */ 139 LWIP_NETIF_CLIENT_DATA_INDEX_MAX 140 }; 141 142 #if LWIP_CHECKSUM_CTRL_PER_NETIF 143 #define NETIF_CHECKSUM_GEN_IP 0x0001 144 #define NETIF_CHECKSUM_GEN_UDP 0x0002 145 #define NETIF_CHECKSUM_GEN_TCP 0x0004 146 #define NETIF_CHECKSUM_GEN_ICMP 0x0008 147 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010 148 #define NETIF_CHECKSUM_CHECK_IP 0x0100 149 #define NETIF_CHECKSUM_CHECK_UDP 0x0200 150 #define NETIF_CHECKSUM_CHECK_TCP 0x0400 151 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800 152 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000 153 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF 154 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000 155 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 156 157 struct netif; 158 159 /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or 160 * mld_mac_filter callback function. */ 161 enum netif_mac_filter_action { 162 /** Delete a filter entry */ 163 NETIF_DEL_MAC_FILTER = 0, 164 /** Add a filter entry */ 165 NETIF_ADD_MAC_FILTER = 1 166 }; 167 168 /** Function prototype for netif init functions. Set up flags and output/linkoutput 169 * callback functions in this function. 170 * 171 * @param netif The netif to initialize 172 */ 173 typedef err_t (*netif_init_fn)(struct netif *netif); 174 /** Function prototype for netif->input functions. This function is saved as 'input' 175 * callback function in the netif struct. Call it when a packet has been received. 176 * 177 * @param p The received packet, copied into a pbuf 178 * @param inp The netif which received the packet 179 * @return ERR_OK if the packet was handled 180 * != ERR_OK is the packet was NOT handled, in this case, the caller has 181 * to free the pbuf 182 */ 183 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); 184 185 #if LWIP_IPV4 186 /** Function prototype for netif->output functions. Called by lwIP when a packet 187 * shall be sent. For ethernet netif, set this to 'etharp_output' and set 188 * 'linkoutput'. 189 * 190 * @param netif The netif which shall send a packet 191 * @param p The packet to send (p->payload points to IP header) 192 * @param ipaddr The IP address to which the packet shall be sent 193 */ 194 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, 195 const ip4_addr_t *ipaddr); 196 #endif /* LWIP_IPV4*/ 197 198 #if LWIP_IPV6 199 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet 200 * shall be sent. For ethernet netif, set this to 'ethip6_output' and set 201 * 'linkoutput'. 202 * 203 * @param netif The netif which shall send a packet 204 * @param p The packet to send (p->payload points to IP header) 205 * @param ipaddr The IPv6 address to which the packet shall be sent 206 */ 207 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, 208 const ip6_addr_t *ipaddr); 209 #endif /* LWIP_IPV6 */ 210 211 /** Function prototype for netif->linkoutput functions. Only used for ethernet 212 * netifs. This function is called by ARP when a packet shall be sent. 213 * 214 * @param netif The netif which shall send a packet 215 * @param p The packet to send (raw ethernet packet) 216 */ 217 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); 218 /** Function prototype for netif status- or link-callback functions. */ 219 typedef void (*netif_status_callback_fn)(struct netif *netif); 220 #if LWIP_IPV4 && LWIP_IGMP 221 /** Function prototype for netif igmp_mac_filter functions */ 222 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, 223 const ip4_addr_t *group, enum netif_mac_filter_action action); 224 #endif /* LWIP_IPV4 && LWIP_IGMP */ 225 #if LWIP_IPV6 && LWIP_IPV6_MLD 226 /** Function prototype for netif mld_mac_filter functions */ 227 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, 228 const ip6_addr_t *group, enum netif_mac_filter_action action); 229 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 230 231 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || LWIP_IPV6_DHCP6 || (LWIP_NUM_NETIF_CLIENT_DATA > 0) 232 #if LWIP_NUM_NETIF_CLIENT_DATA > 0 233 u8_t netif_alloc_client_data_id(void); 234 #endif 235 /** @ingroup netif_cd 236 * Set client data. Obtain ID from netif_alloc_client_data_id(). 237 */ 238 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) 239 /** @ingroup netif_cd 240 * Get client data. Obtain ID from netif_alloc_client_data_id(). 241 */ 242 #define netif_get_client_data(netif, id) (netif)->client_data[(id)] 243 #endif 244 245 #if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f)) 246 typedef u16_t netif_addr_idx_t; 247 #define NETIF_ADDR_IDX_MAX 0x7FFF 248 #else 249 typedef u8_t netif_addr_idx_t; 250 #define NETIF_ADDR_IDX_MAX 0x7F 251 #endif 252 253 #if LWIP_NETIF_HWADDRHINT 254 #define LWIP_NETIF_USE_HINTS 1 255 struct netif_hint { 256 netif_addr_idx_t addr_hint; 257 }; 258 #else /* LWIP_NETIF_HWADDRHINT */ 259 #define LWIP_NETIF_USE_HINTS 0 260 #endif /* LWIP_NETIF_HWADDRHINT */ 261 262 #if ESP_DHCP 263 /*add DHCP event processing by LiuHan*/ 264 typedef void (*dhcp_event_fn)(void); 265 #endif 266 267 /** Generic data structure used for all lwIP network interfaces. 268 * The following fields should be filled in by the initialization 269 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ 270 struct netif { 271 #if !LWIP_SINGLE_NETIF 272 /** pointer to next in linked list */ 273 struct netif *next; 274 #endif 275 276 #if LWIP_IPV4 277 /** IP address configuration in network byte order */ 278 ip_addr_t ip_addr; 279 ip_addr_t netmask; 280 ip_addr_t gw; 281 #endif /* LWIP_IPV4 */ 282 #if LWIP_IPV6 283 /** Array of IPv6 addresses for this netif. */ 284 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; 285 /** The state of each IPv6 address (Tentative, Preferred, etc). 286 * @see ip6_addr.h */ 287 u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; 288 #if LWIP_IPV6_ADDRESS_LIFETIMES 289 /** Remaining valid and preferred lifetime of each IPv6 address, in seconds. 290 * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0) 291 * indicates the address is static and has no lifetimes. */ 292 u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES]; 293 u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES]; 294 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */ 295 #if ESP_LWIP 296 void (*ipv6_addr_cb)(struct netif* netif, u8_t ip_idex); /* callback for ipv6 addr states changed */ 297 #endif 298 #endif /* LWIP_IPV6 */ 299 /** This function is called by the network device driver 300 * to pass a packet up the TCP/IP stack. */ 301 netif_input_fn input; 302 #if LWIP_IPV4 303 /** This function is called by the IP module when it wants 304 * to send a packet on the interface. This function typically 305 * first resolves the hardware address, then sends the packet. 306 * For ethernet physical layer, this is usually etharp_output() */ 307 netif_output_fn output; 308 #endif /* LWIP_IPV4 */ 309 /** This function is called by ethernet_output() when it wants 310 * to send a packet on the interface. This function outputs 311 * the pbuf as-is on the link medium. */ 312 netif_linkoutput_fn linkoutput; 313 #if LWIP_IPV6 314 /** This function is called by the IPv6 module when it wants 315 * to send a packet on the interface. This function typically 316 * first resolves the hardware address, then sends the packet. 317 * For ethernet physical layer, this is usually ethip6_output() */ 318 netif_output_ip6_fn output_ip6; 319 #endif /* LWIP_IPV6 */ 320 #if LWIP_NETIF_STATUS_CALLBACK 321 /** This function is called when the netif state is set to up or down 322 */ 323 netif_status_callback_fn status_callback; 324 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 325 #if LWIP_NETIF_LINK_CALLBACK 326 /** This function is called when the netif link is set to up or down 327 */ 328 netif_status_callback_fn link_callback; 329 #endif /* LWIP_NETIF_LINK_CALLBACK */ 330 #if LWIP_NETIF_REMOVE_CALLBACK 331 /** This function is called when the netif has been removed */ 332 netif_status_callback_fn remove_callback; 333 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 334 /** This field can be set by the device driver and could point 335 * to state information for the device. */ 336 void *state; 337 #ifdef netif_get_client_data 338 void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; 339 #endif 340 341 #if ESP_DHCP 342 struct udp_pcb *dhcps_pcb; 343 dhcp_event_fn dhcp_event; 344 #endif 345 346 #if LWIP_NETIF_HOSTNAME 347 /* the hostname for this netif, NULL is a valid value */ 348 const char* hostname; 349 #endif /* LWIP_NETIF_HOSTNAME */ 350 #if LWIP_CHECKSUM_CTRL_PER_NETIF 351 u16_t chksum_flags; 352 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/ 353 /** maximum transfer unit (in bytes) */ 354 u16_t mtu; 355 #if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES 356 /** maximum transfer unit (in bytes), updated by RA */ 357 u16_t mtu6; 358 #endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */ 359 /** link level hardware address of this interface */ 360 u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; 361 /** number of bytes used in hwaddr */ 362 u8_t hwaddr_len; 363 /** flags (@see @ref netif_flags) */ 364 u8_t flags; 365 /** descriptive abbreviation */ 366 char name[2]; 367 /** number of this interface. Used for @ref if_api and @ref netifapi_netif, 368 * as well as for IPv6 zones */ 369 u8_t num; 370 #if LWIP_IPV6_AUTOCONFIG 371 /** is this netif enabled for IPv6 autoconfiguration */ 372 u8_t ip6_autoconfig_enabled; 373 #endif /* LWIP_IPV6_AUTOCONFIG */ 374 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 375 /** Number of Router Solicitation messages that remain to be sent. */ 376 u8_t rs_count; 377 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ 378 #if MIB2_STATS 379 /** link type (from "snmp_ifType" enum from snmp_mib2.h) */ 380 u8_t link_type; 381 /** (estimate) link speed */ 382 u32_t link_speed; 383 /** timestamp at last change made (up/down) */ 384 u32_t ts; 385 /** counters */ 386 struct stats_mib2_netif_ctrs mib2_counters; 387 #endif /* MIB2_STATS */ 388 #if LWIP_IPV4 && LWIP_IGMP 389 /** This function could be called to add or delete an entry in the multicast 390 filter table of the ethernet MAC.*/ 391 netif_igmp_mac_filter_fn igmp_mac_filter; 392 #endif /* LWIP_IPV4 && LWIP_IGMP */ 393 #if LWIP_IPV6 && LWIP_IPV6_MLD 394 /** This function could be called to add or delete an entry in the IPv6 multicast 395 filter table of the ethernet MAC. */ 396 netif_mld_mac_filter_fn mld_mac_filter; 397 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 398 #if LWIP_NETIF_USE_HINTS 399 struct netif_hint *hints; 400 #endif /* LWIP_NETIF_USE_HINTS */ 401 #if ENABLE_LOOPBACK 402 /* List of packets to be queued for ourselves. */ 403 struct pbuf *loop_first; 404 struct pbuf *loop_last; 405 u8_t reschedule_poll; 406 #if LWIP_LOOPBACK_MAX_PBUFS 407 u16_t loop_cnt_current; 408 #endif /* LWIP_LOOPBACK_MAX_PBUFS */ 409 #endif /* ENABLE_LOOPBACK */ 410 #if ESP_PBUF 411 void (*l2_buffer_free_notify)(struct netif *lwip_netif, void *user_buf); /* Allows LWIP to notify driver when a L2-supplied pbuf can be freed */ 412 ip_addr_t last_ip_addr; /* Store last non-zero ip address */ 413 #endif 414 #if ESP_LWIP 415 #if LWIP_IPV4 && IP_NAPT 416 u8_t napt; 417 #endif 418 #endif /* ESP_LWIP */ 419 void (*drv_send)(struct netif *netif, struct pbuf *p); 420 u8_t (*drv_set_hwaddr)(struct netif *netif, u8_t *addr, u8_t len); 421 void (*drv_config)(struct netif *netif, u32_t config_flags, u8_t setBit); 422 char full_name[16]; 423 u16_t link_layer_type; 424 }; 425 #if LWIP_CHECKSUM_CTRL_PER_NETIF 426 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \ 427 (netif)->chksum_flags = chksumflags; } while(0) 428 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0)) 429 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 430 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) 431 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) 432 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 433 434 #if LWIP_SINGLE_NETIF 435 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL) 436 #else /* LWIP_SINGLE_NETIF */ 437 /** The list of network interfaces. */ 438 extern struct netif *netif_list; 439 #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next) 440 #endif /* LWIP_SINGLE_NETIF */ 441 /** The default network interface. */ 442 extern struct netif *netif_default; 443 444 void netif_init(void); 445 446 struct netif *netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); 447 448 #if LWIP_IPV4 449 struct netif *netif_add(struct netif *netif, 450 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, 451 void *state, netif_init_fn init, netif_input_fn input); 452 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, 453 const ip4_addr_t *gw); 454 #else /* LWIP_IPV4 */ 455 struct netif *netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); 456 #endif /* LWIP_IPV4 */ 457 458 #if ESP_GRATUITOUS_ARP 459 void netif_set_garp_flag(struct netif *netif); 460 #endif 461 462 void netif_remove(struct netif * netif); 463 464 /* Returns a network interface given its name. The name is of the form 465 "et0", where the first two letters are the "name" field in the 466 netif structure, and the digit is in the num field in the same 467 structure. */ 468 struct netif *netif_find(const char *name); 469 470 void netif_set_default(struct netif *netif); 471 472 #if LWIP_IPV4 473 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); 474 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); 475 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); 476 /** @ingroup netif_ip4 */ 477 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) 478 /** @ingroup netif_ip4 */ 479 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) 480 /** @ingroup netif_ip4 */ 481 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) 482 /** @ingroup netif_ip4 */ 483 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) 484 /** @ingroup netif_ip4 */ 485 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) 486 /** @ingroup netif_ip4 */ 487 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) 488 #endif /* LWIP_IPV4 */ 489 490 #define netif_set_flags(netif, set_flags) do { (netif)->flags = (u8_t)((netif)->flags | (set_flags)); } while(0) 491 #define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u8_t)((netif)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) 492 #define netif_is_flag_set(nefif, flag) (((netif)->flags & (flag)) != 0) 493 494 void netif_set_up(struct netif *netif); 495 void netif_set_down(struct netif *netif); 496 /** @ingroup netif 497 * Ask if an interface is up 498 */ 499 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) 500 501 #if LWIP_NETIF_STATUS_CALLBACK 502 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); 503 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 504 #if LWIP_NETIF_REMOVE_CALLBACK 505 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); 506 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 507 508 void netif_set_link_up(struct netif *netif); 509 void netif_set_link_down(struct netif *netif); 510 /** Ask if a link is up */ 511 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) 512 513 #if LWIP_NETIF_LINK_CALLBACK 514 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); 515 #endif /* LWIP_NETIF_LINK_CALLBACK */ 516 517 #if LWIP_NETIF_HOSTNAME 518 /** @ingroup netif */ 519 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) 520 /** @ingroup netif */ 521 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) 522 #endif /* LWIP_NETIF_HOSTNAME */ 523 524 #if LWIP_IGMP 525 /** @ingroup netif */ 526 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) 527 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) 528 #endif /* LWIP_IGMP */ 529 530 #if LWIP_IPV6 && LWIP_IPV6_MLD 531 /** @ingroup netif */ 532 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) 533 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) 534 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) 535 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 536 537 #if ENABLE_LOOPBACK 538 err_t netif_loop_output(struct netif *netif, struct pbuf *p); 539 void netif_poll(struct netif *netif); 540 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 541 void netif_poll_all(void); 542 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ 543 #endif /* ENABLE_LOOPBACK */ 544 545 err_t netif_input(struct pbuf *p, struct netif *inp); 546 547 #if LWIP_IPV6 548 /** @ingroup netif_ip6 */ 549 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) 550 /** @ingroup netif_ip6 */ 551 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) 552 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); 553 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); 554 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) 555 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); 556 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); 557 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); 558 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); 559 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0) 560 #if LWIP_IPV6_ADDRESS_LIFETIMES 561 #define netif_ip6_addr_valid_life(netif, i) \ 562 (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC) 563 #define netif_ip6_addr_set_valid_life(netif, i, secs) \ 564 do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0) 565 #define netif_ip6_addr_pref_life(netif, i) \ 566 (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC) 567 #define netif_ip6_addr_set_pref_life(netif, i, secs) \ 568 do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0) 569 #define netif_ip6_addr_isstatic(netif, i) \ 570 (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC) 571 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 572 #define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */ 573 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 574 #if LWIP_ND6_ALLOW_RA_UPDATES 575 #define netif_mtu6(netif) ((netif)->mtu6) 576 #else /* LWIP_ND6_ALLOW_RA_UPDATES */ 577 #define netif_mtu6(netif) ((netif)->mtu) 578 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */ 579 #endif /* LWIP_IPV6 */ 580 581 #if LWIP_NETIF_USE_HINTS 582 #define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint) 583 #define NETIF_RESET_HINTS(netif) (netif)->hints = NULL 584 #else /* LWIP_NETIF_USE_HINTS */ 585 #define NETIF_SET_HINTS(netif, netifhint) 586 #define NETIF_RESET_HINTS(netif) 587 #endif /* LWIP_NETIF_USE_HINTS */ 588 589 u8_t netif_name_to_index(const char *name); 590 char * netif_index_to_name(u8_t idx, char *name); 591 struct netif* netif_get_by_index(u8_t idx); 592 593 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/ 594 #define netif_get_index(netif) ((u8_t)((netif)->num + 1)) 595 #define NETIF_NO_INDEX (0) 596 597 /** 598 * @ingroup netif 599 * Extended netif status callback (NSC) reasons flags. 600 * May be extended in the future! 601 */ 602 typedef u16_t netif_nsc_reason_t; 603 604 /* used for initialization only */ 605 #define LWIP_NSC_NONE 0x0000 606 /** netif was added. arg: NULL. Called AFTER netif was added. */ 607 #define LWIP_NSC_NETIF_ADDED 0x0001 608 /** netif was removed. arg: NULL. Called BEFORE netif is removed. */ 609 #define LWIP_NSC_NETIF_REMOVED 0x0002 610 /** link changed */ 611 #define LWIP_NSC_LINK_CHANGED 0x0004 612 /** netif administrative status changed.\n 613 * up is called AFTER netif is set up.\n 614 * down is called BEFORE the netif is actually set down. */ 615 #define LWIP_NSC_STATUS_CHANGED 0x0008 616 /** IPv4 address has changed */ 617 #define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010 618 /** IPv4 gateway has changed */ 619 #define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020 620 /** IPv4 netmask has changed */ 621 #define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040 622 /** called AFTER IPv4 address/gateway/netmask changes have been applied */ 623 #define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080 624 /** IPv6 address was added */ 625 #define LWIP_NSC_IPV6_SET 0x0100 626 /** IPv6 address state has changed */ 627 #define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200 628 629 /** @ingroup netif 630 * Argument supplied to netif_ext_callback_fn. 631 */ 632 typedef union 633 { 634 /** Args to LWIP_NSC_LINK_CHANGED callback */ 635 struct link_changed_s 636 { 637 /** 1: up; 0: down */ 638 u8_t state; 639 } link_changed; 640 /** Args to LWIP_NSC_STATUS_CHANGED callback */ 641 struct status_changed_s 642 { 643 /** 1: up; 0: down */ 644 u8_t state; 645 } status_changed; 646 /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */ 647 struct ipv4_changed_s 648 { 649 /** Old IPv4 address */ 650 const ip_addr_t* old_address; 651 const ip_addr_t* old_netmask; 652 const ip_addr_t* old_gw; 653 } ipv4_changed; 654 /** Args to LWIP_NSC_IPV6_SET callback */ 655 struct ipv6_set_s 656 { 657 /** Index of changed IPv6 address */ 658 s8_t addr_index; 659 /** Old IPv6 address */ 660 const ip_addr_t* old_address; 661 } ipv6_set; 662 /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */ 663 struct ipv6_addr_state_changed_s 664 { 665 /** Index of affected IPv6 address */ 666 s8_t addr_index; 667 /** Old IPv6 address state */ 668 u8_t old_state; 669 /** Affected IPv6 address */ 670 const ip_addr_t* address; 671 } ipv6_addr_state_changed; 672 } netif_ext_callback_args_t; 673 674 /** 675 * @ingroup netif 676 * Function used for extended netif status callbacks 677 * Note: When parsing reason argument, keep in mind that more reasons may be added in the future! 678 * @param netif netif that is affected by change 679 * @param reason change reason 680 * @param args depends on reason, see reason description 681 */ 682 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 683 684 #if LWIP_NETIF_EXT_STATUS_CALLBACK 685 struct netif_ext_callback; 686 typedef struct netif_ext_callback 687 { 688 netif_ext_callback_fn callback_fn; 689 struct netif_ext_callback* next; 690 } netif_ext_callback_t; 691 692 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name; 693 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn); 694 void netif_remove_ext_callback(netif_ext_callback_t* callback); 695 void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 696 #else 697 #define NETIF_DECLARE_EXT_CALLBACK(name) 698 #define netif_add_ext_callback(callback, fn) 699 #define netif_remove_ext_callback(callback) 700 #define netif_invoke_ext_callback(netif, reason, args) 701 #endif 702 703 #ifdef __cplusplus 704 } 705 #endif 706 707 err_t tcpip_input(struct pbuf *p, struct netif *inp); 708 void driverif_input(struct netif *netif, struct pbuf *p); 709 #endif /* LWIP_HDR_NETIF_H */ 710