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 #include "lwip/prot/ethernet.h" 52 #if LWIP_NETIF_PROMISC 53 #include "lwip/sys.h" 54 #endif 55 56 #ifdef __cplusplus 57 extern "C" { 58 #endif 59 60 /* Throughout this file, IP addresses are expected to be in 61 * the same byte order as in IP_PCB. */ 62 63 /** Must be the maximum of all used hardware address lengths 64 across all types of interfaces in use. 65 This does not have to be changed, normally. */ 66 #ifndef NETIF_MAX_HWADDR_LEN 67 #define NETIF_MAX_HWADDR_LEN 6U 68 #endif 69 70 /** The size of a fully constructed netif name which the 71 * netif can be identified by in APIs. 72 */ 73 #ifdef IFNAMSIZ 74 #define NETIF_NAMESIZE IFNAMSIZ 75 #else 76 #define NETIF_NAMESIZE 16 77 #endif 78 79 #define NETIF_LOOPBACK_MTU ((16 * 1024) + 20 + 20 + 12) 80 81 /** Type of link layer, these macros should be used for link_layer_type of struct netif */ 82 #define LOOPBACK_IF 772 83 /** Type of link layer, these macros should be used for link_layer_type of struct netif */ 84 #define ETHERNET_DRIVER_IF 1 85 /** Type of link layer, these macros should be used for link_layer_type of struct netif */ 86 #define WIFI_DRIVER_IF 801 87 88 /** Short names of link layer */ 89 #define LOOPBACK_IFNAME "lo" 90 /** Short names of link layer */ 91 #define ETHERNET_IFNAME "eth" 92 /** Short names of link layer */ 93 #define WIFI_IFNAME "wlan" 94 95 /** 96 * @defgroup netif_flags Flags 97 * @ingroup netif 98 * @{ 99 */ 100 101 /** Whether the network interface is 'up'. This is 102 * a software flag used to control whether this network 103 * interface is enabled and processes traffic. 104 * It must be set by the startup code before this netif can be used 105 * (also for dhcp/autoip). 106 */ 107 #define NETIF_FLAG_UP 0x01U 108 /** If set, the netif has broadcast capability. 109 * Set by the netif driver in its init function. */ 110 #define NETIF_FLAG_BROADCAST 0x02U 111 /** If set, the interface has an active link 112 * (set by the network interface driver). 113 * Either set by the netif driver in its init function (if the link 114 * is up at that time) or at a later point once the link comes up 115 * (if link detection is supported by the hardware). */ 116 #define NETIF_FLAG_LINK_UP 0x04U 117 /** If set, the netif is an ethernet device using ARP. 118 * Set by the netif driver in its init function. 119 * Used to check input packet types and use of DHCP. */ 120 #define NETIF_FLAG_ETHARP 0x08U 121 /** If set, the netif is an ethernet device. It might not use 122 * ARP or TCP/IP if it is used for PPPoE only. 123 */ 124 #define NETIF_FLAG_ETHERNET 0x10U 125 /** If set, the netif has IGMP capability. 126 * Set by the netif driver in its init function. */ 127 #define NETIF_FLAG_IGMP 0x20U 128 /** If set, the netif has MLD6 capability. 129 * Set by the netif driver in its init function. */ 130 #define NETIF_FLAG_MLD6 0x40U 131 132 /** If set, the interface is configured using DHCP. 133 * Set by the DHCP code when starting or stopping DHCP. */ 134 #define NETIF_FLAG_DHCP 0x80U 135 136 #if DRIVER_STATUS_CHECK 137 /** If set, the netif has send capability. 138 * Set by the netif driver when its is ready to send. */ 139 #define NETIF_FLAG_DRIVER_RDY 0x100U 140 #endif 141 142 #define NETIF_FLAG_LOOPBACK 0x800 143 144 #if LWIP_NETIF_PROMISC 145 #define NETIF_FLAG_PROMISC 0x1000 146 #define NETIF_FLAG_PROMISC_RUNNING 0x2000U 147 #endif /* LWIP_NETIF_PROMISC */ 148 149 #if LWIP_IPV6 && LWIP_RIPPLE 150 #define NETIF_IS_RPL_UP 0x8000U 151 #endif 152 153 #define LWIP_API_VAR_REF(name) API_VAR_REF(name) 154 #define LWIP_API_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name) 155 #define LWIP_API_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM) 156 #define LWIP_API_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name) 157 158 /** 159 * @} 160 */ 161 162 enum lwip_internal_netif_client_data_index 163 { 164 #if LWIP_IPV4 165 #if LWIP_DHCP 166 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, 167 #endif 168 #if LWIP_AUTOIP 169 LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, 170 #endif 171 #if LWIP_IGMP 172 LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, 173 #endif 174 #endif /* LWIP_IPV4 */ 175 #if LWIP_IPV6 176 #if LWIP_IPV6_DHCP6 177 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, 178 #endif 179 #if LWIP_IPV6_MLD 180 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, 181 #endif 182 #if LWIP_IPV6_MLD_QUERIER 183 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6_QUERIER, 184 #endif /* LWIP_IPV6_MLD_QUERIER */ 185 #endif /* LWIP_IPV6 */ 186 LWIP_NETIF_CLIENT_DATA_INDEX_MAX 187 }; 188 189 #if LWIP_CHECKSUM_CTRL_PER_NETIF 190 #define NETIF_CHECKSUM_GEN_IP 0x0001 191 #define NETIF_CHECKSUM_GEN_UDP 0x0002 192 #define NETIF_CHECKSUM_GEN_TCP 0x0004 193 #define NETIF_CHECKSUM_GEN_ICMP 0x0008 194 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010 195 #define NETIF_CHECKSUM_CHECK_IP 0x0100 196 #define NETIF_CHECKSUM_CHECK_UDP 0x0200 197 #define NETIF_CHECKSUM_CHECK_TCP 0x0400 198 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800 199 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000 200 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF 201 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000 202 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 203 204 struct netif; 205 206 /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or 207 * mld_mac_filter callback function. */ 208 enum netif_mac_filter_action { 209 /** Delete a filter entry */ 210 NETIF_DEL_MAC_FILTER = 0, 211 /** Add a filter entry */ 212 NETIF_ADD_MAC_FILTER = 1 213 }; 214 215 struct linklayer_addr { 216 u8_t addr[NETIF_MAX_HWADDR_LEN]; 217 u8_t addrlen; 218 }; 219 220 typedef struct linklayer_addr linklayer_addr_t; 221 222 s8_t netif_find_dst_ip6addr_mac_addr(const ip_addr_t *ipaddr, ip_addr_t **dst_addr, struct eth_addr **eth_ret); 223 /** Function prototype for netif init functions. Set up flags and output/linkoutput 224 * callback functions in this function. 225 * 226 * @param netif The netif to initialize 227 */ 228 typedef err_t (*netif_init_fn)(struct netif *netif); 229 /** Function prototype for netif->input functions. This function is saved as 'input' 230 * callback function in the netif struct. Call it when a packet has been received. 231 * 232 * @param p The received packet, copied into a pbuf 233 * @param inp The netif which received the packet 234 * @return ERR_OK if the packet was handled 235 * != ERR_OK is the packet was NOT handled, in this case, the caller has 236 * to free the pbuf 237 */ 238 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); 239 240 #if LWIP_IPV4 241 /** Function prototype for netif->output functions. Called by lwIP when a packet 242 * shall be sent. For ethernet netif, set this to 'etharp_output' and set 243 * 'linkoutput'. 244 * 245 * @param netif The netif which shall send a packet 246 * @param p The packet to send (p->payload points to IP header) 247 * @param ipaddr The IP address to which the packet shall be sent 248 */ 249 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, 250 const ip4_addr_t *ipaddr); 251 #endif /* LWIP_IPV4*/ 252 253 #if LWIP_IPV6 254 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet 255 * shall be sent. For ethernet netif, set this to 'ethip6_output' and set 256 * 'linkoutput'. 257 * 258 * @param netif The netif which shall send a packet 259 * @param p The packet to send (p->payload points to IP header) 260 * @param ipaddr The IPv6 address to which the packet shall be sent 261 */ 262 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, 263 const ip6_addr_t *ipaddr); 264 #endif /* LWIP_IPV6 */ 265 266 /** Function prototype for netif->linkoutput functions. Only used for ethernet 267 * netifs. This function is called by ARP when a packet shall be sent. 268 * 269 * @param netif The netif which shall send a packet 270 * @param p The packet to send (raw ethernet packet) 271 */ 272 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); 273 /** Function prototype for netif status- or link-callback functions. */ 274 typedef void (*netif_status_callback_fn)(struct netif *netif); 275 #if LWIP_NETIF_PROMISC 276 /** Function pointer of driver set/unset promiscuous mode on interface */ 277 typedef void (*drv_config_fn)(struct netif *netif, u32_t config_flags, u8_t setBit); 278 #endif /* LWIP_NETIF_PROMISC */ 279 #if LWIP_IPV4 && LWIP_IGMP && LWIP_LINK_MCAST_FILTER 280 /** Function prototype for netif igmp_mac_filter functions */ 281 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, 282 const ip4_addr_t *group, enum netif_mac_filter_action action); 283 #endif /* LWIP_IPV4 && LWIP_IGMP && LWIP_LINK_MCAST_FILTER */ 284 #if LWIP_IPV6 && LWIP_IPV6_MLD && LWIP_LINK_MCAST_FILTER 285 /** Function prototype for netif mld_mac_filter functions */ 286 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, 287 const ip6_addr_t *group, enum netif_mac_filter_action action); 288 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD && LWIP_LINK_MCAST_FILTER */ 289 290 #if LWIP_API_MESH 291 typedef enum linklayer_event_type { 292 LL_EVENT_TX_INFO = 0, 293 LL_EVENT_NEW_PEER, 294 LL_EVENT_DEL_PEER, 295 LL_EVENT_AP_CONN, 296 LL_EVENT_AP_DISCONN, 297 LL_EVENT_STA_CONN, 298 LL_EVENT_STA_DISCONN, 299 LL_EVENT_MAX 300 } linklayer_event_type_e; 301 302 typedef struct linklayer_event_ap_conn { 303 struct linklayer_addr addr; 304 u8_t is_mesh_ap; 305 s8_t rssi; 306 } linklayer_event_ap_conn_t; 307 typedef struct linklayer_event_sta_conn { 308 struct linklayer_addr addr; 309 } linklayer_event_sta_conn_t; 310 311 typedef err_t (*netif_linklayer_event_fn)(struct netif *netif, u8_t evt_type, const void *evt_info); 312 313 #if LWIP_RIPPLE 314 typedef u16_t uniqid_t; 315 316 typedef struct linklayer_event_tx_info { 317 struct linklayer_addr addr; 318 u8_t status; 319 u8_t retry_count; 320 u16_t pkt_sz; 321 u32_t data_rate; /* unit kbps */ 322 u32_t bandwidth; /* unit kbps */ 323 } linklayer_event_tx_info_t; 324 325 typedef struct linklayer_event_new_peer { 326 struct linklayer_addr addr; 327 u8_t is_mesh_user; 328 s8_t rssi; 329 u8_t beacon_prio; 330 u8_t lqi; 331 } linklayer_event_new_peer_t; 332 333 typedef struct linklayer_event_del_peer { 334 struct linklayer_addr addr; 335 u8_t is_mesh_user; 336 } linklayer_event_del_peer_t; 337 338 typedef err_t (*netif_remove_peer_fn)(struct netif *netif, struct linklayer_addr *peeraddr); 339 typedef err_t (*netif_set_beacon_prio_fn)(struct netif *netif, u8_t prio); 340 typedef err_t (*netif_set_unique_id_fn)(struct netif *netif, uniqid_t id); 341 typedef err_t (*netif_get_peer_count_fn)(struct netif *netif, u16_t *count); 342 typedef err_t (*netif_set_rank_fn)(struct netif *netif, u16_t rank); 343 typedef err_t (*netif_get_link_metric_fn)(struct netif *netif, u16_t *metric); 344 #endif /* LWIP_RIPPLE */ 345 #endif /* LWIP_API_MESH */ 346 /** Function pointer of driver send function */ 347 typedef void (*drv_send_fn)(struct netif *netif, struct pbuf *p); 348 /** Function pointer of driver set hw address function */ 349 /* This callback function should return 0 in case of success */ 350 typedef u8_t (*drv_set_hwaddr_fn)(struct netif *netif, u8_t *addr, u8_t len); 351 352 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || LWIP_IPV6_DHCP6 || (LWIP_NUM_NETIF_CLIENT_DATA > 0) 353 #if LWIP_NUM_NETIF_CLIENT_DATA > 0 354 #define NETIF_CLIENT_DATA_INVALID_INDEX 255u 355 u8_t netif_alloc_client_data_id(void); 356 #endif 357 /** @ingroup netif_cd 358 * Set client data. Obtain ID from netif_alloc_client_data_id(). 359 */ 360 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) 361 /** @ingroup netif_cd 362 * Get client data. Obtain ID from netif_alloc_client_data_id(). 363 */ 364 #define netif_get_client_data(netif, id) (netif)->client_data[(id)] 365 #endif 366 367 #ifndef LOOPBACK_IF 368 /** Type of link layer, these macros should be used for link_layer_type of struct netif */ 369 #define LOOPBACK_IF 772 370 #endif 371 372 #if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f)) 373 typedef u16_t netif_addr_idx_t; 374 #define NETIF_ADDR_IDX_MAX 0x7FFF 375 #else 376 typedef u8_t netif_addr_idx_t; 377 #define NETIF_ADDR_IDX_MAX 0x7F 378 #endif 379 380 #if LWIP_NETIF_HWADDRHINT 381 #define LWIP_NETIF_USE_HINTS 1 382 struct netif_hint { 383 netif_addr_idx_t addr_hint; 384 }; 385 #else /* LWIP_NETIF_HWADDRHINT */ 386 #define LWIP_NETIF_USE_HINTS 0 387 #endif /* LWIP_NETIF_HWADDRHINT */ 388 389 /* route entry scope, Actually it is not scope, but distance to the destination. */ 390 typedef enum rt_scope { 391 RT_SCOPE_UNIVERSAL = 0, /* everywhere in the Universe */ 392 RT_SCOPE_LINK = 1, /* destinations located on directly attached link, maybe not same IP network */ 393 RT_SCOPE_HOST = 2 /* our local address */ 394 } rt_scope_t; 395 396 #if LWIP_IPV6 397 /** 398 * @ingroup Duplicate_Address_Callback 399 * @brief 400 * This callback is invoked when duplicate addresses are available in the 401 * system, default behavior is to stop using those addresses. 402 * 403 * @param[in] netif Indicates pointer to the pre-allocated netif structure on 404 * which duplicate addr has occured. 405 * @param[in] ipaddr Indicates duplicate IP6 address. 406 * @param[in] state Indicates current state of duplicate Ip6 address. 407 * 408 * @returns 409 * void 410 * @note 411 * prototype void (*lwip_duplicate_addr_handler_callback)(struct netif *, ip6_addr_t , u8_t ); 412 */ 413 414 415 /* A callback prototype for handling duplicate address. */ 416 typedef void (*lwip_ipv6_addr_event)(struct netif *, ip6_addr_t, u8_t); 417 418 #define LWIP_IPV6_ND6_FLAG_DAD 0x01U 419 #define LWIP_IPV6_ND6_FLAG_DEPRECATED 0x02U 420 421 #if (defined(LWIP_IPV6_DUP_DETECT_ATTEMPTS) && LWIP_IPV6_DUP_DETECT_ATTEMPTS) 422 #define LWIP_IS_DAD_ENABLED(netif) (((netif)->ipv6_flags & LWIP_IPV6_ND6_FLAG_DAD)) 423 #else 424 #define LWIP_IS_DAD_ENABLED(netif) 0 425 #endif 426 #endif /* LWIP_IPV6 */ 427 428 /** Generic data structure used for all lwIP network interfaces. 429 * The following fields should be filled in by the initialization 430 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ 431 struct netif { 432 #if !LWIP_SINGLE_NETIF 433 /** pointer to next in linked list */ 434 struct netif *next; 435 #endif 436 #if LWIP_API_MESH 437 netif_linklayer_event_fn linklayer_event; /* registered by lwip and called by linklayer */ 438 #if LWIP_RIPPLE 439 netif_remove_peer_fn remove_peer; 440 netif_set_beacon_prio_fn set_beacon_prio; 441 netif_set_unique_id_fn set_unique_id; 442 netif_get_peer_count_fn get_peer_count; 443 netif_set_rank_fn set_rank; 444 netif_get_link_metric_fn get_link_metric; 445 #endif 446 #endif /* LWIP_API_MESH */ 447 448 #if LWIP_IPV4 449 /** IP address configuration in network byte order */ 450 ip_addr_t ip_addr; 451 ip_addr_t netmask; 452 ip_addr_t gw; 453 #endif /* LWIP_IPV4 */ 454 #if LWIP_IPV6 455 /** Array of IPv6 addresses for this netif. */ 456 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; 457 /** The state of each IPv6 address (Tentative, Preferred, etc). 458 * @see ip6_addr.h */ 459 u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; 460 #if LWIP_IPV6_ADDRESS_LIFETIMES 461 /** Remaining valid and preferred lifetime of each IPv6 address, in seconds. 462 * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0) 463 * indicates the address is static and has no lifetimes. */ 464 u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES]; 465 u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES]; 466 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */ 467 #endif /* LWIP_IPV6 */ 468 /** This function is called by the network device driver 469 * to pass a packet up the TCP/IP stack. */ 470 netif_input_fn input; 471 #if LWIP_IPV4 472 /** This function is called by the IP module when it wants 473 * to send a packet on the interface. This function typically 474 * first resolves the hardware address, then sends the packet. 475 * For ethernet physical layer, this is usually etharp_output() */ 476 netif_output_fn output; 477 #endif /* LWIP_IPV4 */ 478 /** This function is called by ethernet_output() when it wants 479 * to send a packet on the interface. This function outputs 480 * the pbuf as-is on the link medium. */ 481 netif_linkoutput_fn linkoutput; 482 #if LWIP_IPV6 483 /** This function is called by the IPv6 module when it wants 484 * to send a packet on the interface. This function typically 485 * first resolves the hardware address, then sends the packet. 486 * For ethernet physical layer, this is usually ethip6_output() */ 487 netif_output_ip6_fn output_ip6; 488 #endif /* LWIP_IPV6 */ 489 #if LWIP_L2_NETDEV_STATUS_CALLBACK 490 netif_status_callback_fn l2_netdev_status_callback; /**< notice for wifi when AT command is ifconfig down/up */ 491 #endif 492 #if LWIP_NETIF_STATUS_CALLBACK 493 /** This function is called when the netif state is set to up or down 494 */ 495 netif_status_callback_fn status_callback; 496 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 497 #if LWIP_NETIF_LINK_CALLBACK 498 /** This function is called when the netif link is set to up or down 499 */ 500 netif_status_callback_fn link_callback; 501 #endif /* LWIP_NETIF_LINK_CALLBACK */ 502 #if LWIP_NETIF_REMOVE_CALLBACK 503 /** This function is called when the netif has been removed */ 504 netif_status_callback_fn remove_callback; 505 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 506 /** This field can be set by the device driver and could point 507 * to state information for the device. */ 508 void *state; 509 /* This function is called by lwIP to send a packet on the interface. */ 510 drv_send_fn drv_send; /**< This function is called when lwIP wants to send a packet to interface. */ 511 /* This function is called by lwIP 512 * to set the mac_address of the interface. */ 513 drv_set_hwaddr_fn drv_set_hwaddr; 514 #if LWIP_NETIF_ETHTOOL && LWIP_SOCKET 515 void *ethtool_ops; 516 #endif 517 #if LWIP_DHCPS 518 /* DHCP Server Informarion for this netif */ 519 struct dhcps *dhcps; 520 #endif 521 #if LWIP_NETIF_PROMISC 522 /** This function is called by lwIP 523 * to set/unset the promiscuous mode of the interface. */ 524 drv_config_fn drv_config; 525 #endif /* LWIP_NETIF_PROMISC */ 526 #ifdef netif_get_client_data 527 void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; 528 #endif 529 #if LWIP_NETIF_HOSTNAME 530 /* the hostname for this netif, NULL is a valid value */ 531 char hostname[NETIF_HOSTNAME_MAX_LEN]; 532 #endif /* LWIP_NETIF_HOSTNAME */ 533 #if LWIP_CHECKSUM_CTRL_PER_NETIF 534 u16_t chksum_flags; 535 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 536 /** maximum transfer unit (in bytes) */ 537 u16_t mtu; 538 #if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES 539 /** maximum transfer unit (in bytes), updated by RA */ 540 u16_t mtu6; 541 #endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */ 542 /** link level hardware address of this interface */ 543 u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; 544 /** number of bytes used in hwaddr */ 545 u8_t hwaddr_len; 546 /* link layer type, ethernet or wifi */ 547 u16_t link_layer_type; /**< Indicates whether the link layer type is ethernet or wifi. */ 548 /** flags (@see @ref netif_flags) */ 549 u32_t flags; 550 551 #if LWIP_NETIF_PROMISC 552 atomic_t flags_ext; 553 u32_t flags_ext1; 554 #endif /* LWIP_NETIF_PROMISC */ 555 /** descriptive abbreviation */ 556 char name[NETIF_NAMESIZE]; 557 /** number of this interface. Used for @ref if_api and @ref netifapi_netif, 558 * as well as for IPv6 zones */ 559 u8_t num; 560 u8_t ifindex; /* Interface Index mapped to each netif. Starts from 1 */ 561 #if DRIVER_STATUS_CHECK 562 s32_t waketime; /**< Started when netif_stop_queue is called from driver. */ 563 #endif 564 #if LWIP_IPV6_AUTOCONFIG 565 /** is this netif enabled for IPv6 autoconfiguration */ 566 u8_t ip6_autoconfig_enabled; 567 #endif /* LWIP_IPV6_AUTOCONFIG */ 568 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 569 /** Number of Router Solicitation messages that remain to be sent. */ 570 u8_t rs_count; 571 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ 572 #if MIB2_STATS 573 /** link type (from "snmp_ifType" enum from snmp_mib2.h) */ 574 u8_t link_type; 575 /** (estimate) link speed */ 576 u32_t link_speed; 577 /** timestamp at last change made (up/down) */ 578 u32_t ts; 579 /** counters */ 580 struct stats_mib2_netif_ctrs mib2_counters; 581 #endif /* MIB2_STATS */ 582 #if LWIP_IPV4 && LWIP_IGMP && LWIP_LINK_MCAST_FILTER 583 /** This function could be called to add or delete an entry in the multicast 584 filter table of the ethernet MAC.*/ 585 netif_igmp_mac_filter_fn igmp_mac_filter; 586 #endif /* LWIP_IPV4 && LWIP_IGMP && LWIP_LINK_MCAST_FILTER */ 587 #if LWIP_IPV6 && LWIP_IPV6_MLD && LWIP_LINK_MCAST_FILTER 588 /** This function could be called to add or delete an entry in the IPv6 multicast 589 filter table of the ethernet MAC. */ 590 netif_mld_mac_filter_fn mld_mac_filter; 591 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD && LWIP_LINK_MCAST_FILTER */ 592 #if LWIP_NETIF_USE_HINTS 593 struct netif_hint *hints; 594 #endif /* LWIP_NETIF_USE_HINTS */ 595 #if ENABLE_LOOPBACK 596 /* List of packets to be queued for ourselves. */ 597 struct pbuf *loop_first; 598 struct pbuf *loop_last; 599 #if LWIP_LOOPBACK_MAX_PBUFS 600 u16_t loop_cnt_current; 601 #endif /* LWIP_LOOPBACK_MAX_PBUFS */ 602 #if LWIP_NETIF_LOOPBACK_MULTITHREADING 603 /* Used if the original scheduling failed. */ 604 u8_t reschedule_poll; 605 #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ 606 #endif /* ENABLE_LOOPBACK */ 607 #if LWIP_SO_DONTROUTE 608 /** The scope of the netif, this is set in ip4_route/ip6_route, the usr can use this 609 to decide whether the netif is in desired sope */ 610 rt_scope_t scope; 611 #endif 612 #if LWIP_IPV6 613 /** Call back needs to be registered if adaptor requires notification for IPv6 DAD */ 614 lwip_ipv6_addr_event ipv6_addr_event_cb; 615 u8_t ipv6_flags; 616 #if LWIP_ND6_ROUTER 617 u8_t forwarding; 618 u8_t accept_ra; 619 u8_t ra_enable; 620 u8_t ra_init_cnt; 621 u32_t ra_timer; 622 #endif 623 #endif 624 #if LWIP_ARP && LWIP_ARP_GRATUITOUS_REXMIT 625 u8_t arp_gratuitous_doing : 1; 626 u8_t arp_gratuitous_cnt : 7; 627 #endif 628 }; 629 630 #if LWIP_CHECKSUM_CTRL_PER_NETIF 631 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \ 632 (netif)->chksum_flags = chksumflags; } while(0) 633 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0)) 634 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 635 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) 636 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) 637 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 638 639 #if LWIP_SINGLE_NETIF 640 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL) 641 #else /* LWIP_SINGLE_NETIF */ 642 /** The list of network interfaces. */ 643 extern struct netif *netif_list; 644 #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next) 645 #endif /* LWIP_SINGLE_NETIF */ 646 /** The default network interface. */ 647 extern struct netif *netif_default; 648 s8_t netif_find_dst_ipaddr(const ip_addr_t *ipaddr, ip_addr_t **dst_addr); 649 void netif_init(void); 650 651 #if LWIP_DHCP 652 err_t netif_dhcp_off(struct netif *netif); 653 #endif 654 655 u8_t netif_check_num_isusing(const char *ifname, const u8_t num); 656 657 /** 658 * open or close netdev by netif without block as not using mutex 659 * the api only called by AT command ifconfig up/down 660 * @param netif the lwip network interface structure 661 * @return ERR_OK callback is ok 662 * ERR_VAL netif is NULL 663 */ 664 #if LWIP_L2_NETDEV_STATUS_CALLBACK 665 u8_t netif_l2_netdev_status_callback(struct netif *nif); 666 #endif 667 struct netif *netif_add_noaddr(struct netif *netif); 668 669 #if LWIP_IPV4 670 struct netif *netif_add(struct netif *netif, 671 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw); 672 err_t netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, 673 const ip4_addr_t *gw); 674 675 err_t 676 netif_get_addr(const struct netif *netif, ip4_addr_t *ipaddr, ip4_addr_t *netmask, ip4_addr_t *gw); 677 678 #else /* LWIP_IPV4 */ 679 struct netif *netif_add(struct netif *netif); 680 #endif /* LWIP_IPV4 */ 681 #ifdef LWIP_TESTBED 682 err_t netif_reset(struct netif *netif); 683 #endif 684 err_t netif_remove(struct netif *netif); 685 686 /* Returns a network interface given its name. The name is of the form 687 "et0", where the first two letters are the "name" field in the 688 netif structure, and the digit is in the num field in the same 689 structure. */ 690 struct netif *netif_find(const char *name); 691 692 struct netif *netif_find_by_ipaddr(const ip_addr_t *ipaddr); 693 694 struct netif *netif_find_by_ifindex(u8_t ifindex); 695 u8_t netif_ipaddr_isbrdcast(const ip_addr_t *ipaddr); 696 err_t netif_set_default(struct netif *netif); 697 698 #if LWIP_IPV4 699 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); 700 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); 701 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); 702 struct netif *netif_find_by_ip4addr(const ip_addr_t *ipaddr); 703 /** @ingroup netif_ip4 */ 704 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) 705 /** @ingroup netif_ip4 */ 706 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) 707 /** @ingroup netif_ip4 */ 708 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) 709 /** @ingroup netif_ip4 */ 710 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) 711 /** @ingroup netif_ip4 */ 712 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) 713 /** @ingroup netif_ip4 */ 714 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) 715 #endif /* LWIP_IPV4 */ 716 717 #define netif_set_flags(netif, set_flags) do { (netif)->flags = (u32_t)((netif)->flags | (set_flags)); } while (0) 718 #define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u32_t)((netif)->flags & (u32_t)(~(clr_flags) & LWIP_UINT32_MAX)); } while (0) 719 #define netif_is_flag_set(netif, flag) (((netif)->flags & (flag)) != 0) 720 721 err_t netif_set_up(struct netif *netif); 722 err_t netif_set_down(struct netif *netif); 723 #ifndef PPP_SUPPORT 724 err_t netif_set_mtu(struct netif *netif, u16_t netif_mtu); 725 #endif 726 err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw_len); 727 void netif_get_hwaddr(const struct netif *netif, unsigned char *hw_addr, int hw_len); 728 /** @ingroup netif 729 * Ask if an interface is up 730 */ 731 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) 732 733 #if LWIP_NETIF_STATUS_CALLBACK 734 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); 735 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 736 #if LWIP_NETIF_REMOVE_CALLBACK 737 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); 738 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 739 740 err_t netif_set_link_up(struct netif *netif); 741 err_t netif_set_link_down(struct netif *netif); 742 void netif_set_link_up_interface(void *arg); 743 void netif_set_link_down_interface(void *arg); 744 745 /** Ask if a link is up */ 746 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) 747 748 #if LWIP_NETIF_PROMISC 749 void netif_update_promiscuous_mode_status(struct netif *netif, u8_t set); 750 void netif_start_promisc_mode(u8_t ifindex); 751 void netif_stop_promisc_mode(u8_t ifindex); 752 #endif /* LWIP_NETIF_PROMISC */ 753 754 #if DRIVER_STATUS_CHECK 755 err_t 756 netif_wake_queue(struct netif *netif); 757 err_t 758 netif_stop_queue(struct netif *netif); 759 760 /** Ask if a driver is ready to send */ 761 #define netif_is_ready(netif) (((netif)->flags & NETIF_FLAG_DRIVER_RDY) ? (u8_t)1 : (u8_t)0) 762 #endif 763 764 #if LWIP_NETIF_LINK_CALLBACK 765 err_t netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); 766 #endif /* LWIP_NETIF_LINK_CALLBACK */ 767 768 #if LWIP_NETIF_HOSTNAME 769 /** @ingroup netif */ 770 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) 771 /** @ingroup netif */ 772 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) 773 #endif /* LWIP_NETIF_HOSTNAME */ 774 775 #if LWIP_IGMP 776 /** @ingroup netif */ 777 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) 778 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) 779 #endif /* LWIP_IGMP */ 780 781 #if LWIP_IPV6 && LWIP_IPV6_MLD 782 /** @ingroup netif */ 783 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) 784 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) 785 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) 786 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 787 788 #if ENABLE_LOOPBACK 789 err_t netif_loop_output(struct netif *netif, struct pbuf *p); 790 void netif_poll(struct netif *netif); 791 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 792 void netif_poll_all(void); 793 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ 794 #endif /* ENABLE_LOOPBACK */ 795 796 err_t netif_input(struct pbuf *p, struct netif *inp); 797 798 #if LWIP_IPV6 799 /** @ingroup netif_ip6 */ 800 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) 801 /** @ingroup netif_ip6 */ 802 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) 803 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); 804 err_t netif_do_add_ipv6_addr(struct netif *netif, void *arguments); 805 err_t netif_do_rmv_ipv6_addr(struct netif *netif, void *arguments); 806 807 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); 808 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) 809 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); 810 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); 811 err_t netif_get_ip6_linklocal_address(const struct netif *netif, ip6_addr_t *addr); 812 err_t netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); 813 err_t netif_create_ip6_linklocal_address_from_mac(const linklayer_addr_t *mac, ip6_addr_t *ip6addr); 814 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); 815 void netif_ip6_addr_setinvalid(struct netif *netif, const ip6_addr_t *addr6); 816 #if defined(LWIP_RA_PREFIX_DYNAMIC) && LWIP_RA_PREFIX_DYNAMIC 817 void netif_create_ip6_address_80bit_prefix(struct netif *netif, const ip6_addr_t *prefix, ip6_addr_t *ip6addr); 818 #endif /* defined(LWIP_RA_PREFIX_DYNAMIC) && LWIP_RA_PREFIX_DYNAMIC */ 819 struct netif *netif_find_by_ip6addr(const ip6_addr_t *ip6addr); 820 821 #if LWIP_IPV6_AUTOCONFIG 822 void netif_set_ip6_autoconfig_enabled(struct netif *netif); 823 void netif_set_ip6_autoconfig_disabled(struct netif *netif); 824 #endif /* LWIP_IPV6_AUTOCONFIG */ 825 826 #if LWIP_IPV6_ADDRESS_LIFETIMES 827 #define netif_ip6_addr_valid_life(netif, i) \ 828 (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC) 829 #define netif_ip6_addr_set_valid_life(netif, i, secs) \ 830 do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0) 831 #define netif_ip6_addr_pref_life(netif, i) \ 832 (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC) 833 #define netif_ip6_addr_set_pref_life(netif, i, secs) \ 834 do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0) 835 #define netif_ip6_addr_isstatic(netif, i) \ 836 (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC) 837 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 838 #define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */ 839 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 840 841 #if LWIP_IPV6_DHCP6 842 u8_t netif_ip6_addr_isdhcp6(struct netif *netif, s8_t i); 843 #else 844 #define netif_ip6_addr_isdhcp6(netif, i) (0) 845 #endif 846 847 #if LWIP_ND6_ALLOW_RA_UPDATES 848 #define netif_mtu6(netif) ((netif)->mtu6) 849 #else /* LWIP_ND6_ALLOW_RA_UPDATES */ 850 #define netif_mtu6(netif) ((netif)->mtu) 851 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */ 852 #endif /* LWIP_IPV6 */ 853 854 #if LWIP_NETIF_USE_HINTS 855 #define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint) 856 #define NETIF_RESET_HINTS(netif) (netif)->hints = NULL 857 #else /* LWIP_NETIF_USE_HINTS */ 858 #define NETIF_SET_HINTS(netif, netifhint) 859 #define NETIF_RESET_HINTS(netif) 860 #endif /* LWIP_NETIF_USE_HINTS */ 861 862 #define LWIP_INVALID_IPV6_IDX 255 863 u8_t netif_name_to_index(const char *name); 864 char * netif_index_to_name(u8_t idx, char *name); 865 err_t netif_get_nameindex_all(void *arg); 866 867 struct netif* netif_get_by_index(u8_t idx); 868 869 #if LWIP_RIPPLE 870 u8_t netif_count(void); 871 #endif /* LWIP_RIPPLE */ 872 873 #if LWIP_API_MESH 874 /* 875 * Linklayer Event Indication handler 876 */ 877 struct linklayer_event_info { 878 u8_t type; 879 union { 880 #if LWIP_RIPPLE 881 linklayer_event_tx_info_t tx_info; 882 linklayer_event_new_peer_t new_peer; 883 linklayer_event_del_peer_t del_peer; 884 #endif /* LWIP_RIPPLE */ 885 linklayer_event_ap_conn_t ap_conn; 886 linklayer_event_sta_conn_t sta_conn; 887 } info; 888 }; 889 890 err_t netif_linklayer_event_callback(struct netif *netif, u8_t evt_type, const void *evt_info); 891 #if LWIP_RIPPLE 892 893 /** 894 * Function prototype for linklayer event handler. Called by 895 * netif_linklayer_event_callback() 896 * 897 * @param netif The netif on which event has occurred 898 * @param evt The event received from linklayer 899 */ 900 err_t netif_linklayer_event_handler(struct netif *netif, 901 const struct linklayer_event_info *evt); 902 903 #ifndef NETIF_BEACON_PRIORITY_MAX 904 #define NETIF_BEACON_PRIORITY_MAX 254 905 #endif 906 907 err_t netif_remove_peer(struct netif *netif, struct linklayer_addr *peeraddr); 908 err_t netif_set_beacon_prio(struct netif *netif, u8_t prio); 909 err_t netif_set_unique_id(struct netif *netif, uniqid_t id); 910 err_t netif_get_peer_count(struct netif *netif, u16_t *count); 911 err_t netif_set_rank(struct netif *netif, u16_t rank); 912 err_t netif_get_link_metric(struct netif *netif, u16_t *metric); 913 #endif /* LWIP_RIPPLE */ 914 #endif /* LWIP_API_MESH */ 915 916 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/ 917 #define netif_get_index(netif) ((netif)->ifindex) 918 #define NETIF_NO_INDEX (0) 919 920 #if LWIP_SO_DONTROUTE 921 #define NETIF_SET_SCOPE(netif, rt_scope) ((netif)->scope = rt_scope) 922 #else 923 #define NETIF_SET_SCOPE(netif, rt_scope) 924 #endif 925 /** 926 * @ingroup netif 927 * Extended netif status callback (NSC) reasons flags. 928 * May be extended in the future! 929 */ 930 typedef u16_t netif_nsc_reason_t; 931 932 /* used for initialization only */ 933 #define LWIP_NSC_NONE 0x0000 934 /** netif was added. arg: NULL. Called AFTER netif was added. */ 935 #define LWIP_NSC_NETIF_ADDED 0x0001 936 /** netif was removed. arg: NULL. Called BEFORE netif is removed. */ 937 #define LWIP_NSC_NETIF_REMOVED 0x0002 938 /** link changed */ 939 #define LWIP_NSC_LINK_CHANGED 0x0004 940 /** netif administrative status changed.\n 941 * up is called AFTER netif is set up.\n 942 * down is called BEFORE the netif is actually set down. */ 943 #define LWIP_NSC_STATUS_CHANGED 0x0008 944 /** IPv4 address has changed */ 945 #define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010 946 /** IPv4 gateway has changed */ 947 #define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020 948 /** IPv4 netmask has changed */ 949 #define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040 950 /** called AFTER IPv4 address/gateway/netmask changes have been applied */ 951 #define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080 952 /** IPv6 address was added */ 953 #define LWIP_NSC_IPV6_SET 0x0100 954 /** IPv6 address state has changed */ 955 #define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200 956 /** IPv4 settings: valid address set, application may start to communicate */ 957 #define LWIP_NSC_IPV4_ADDR_VALID 0x0400 958 959 /** @ingroup netif 960 * Argument supplied to netif_ext_callback_fn. 961 */ 962 typedef union 963 { 964 /** Args to LWIP_NSC_LINK_CHANGED callback */ 965 struct link_changed_s 966 { 967 /** 1: up; 0: down */ 968 u8_t state; 969 } link_changed; 970 /** Args to LWIP_NSC_STATUS_CHANGED callback */ 971 struct status_changed_s 972 { 973 /** 1: up; 0: down */ 974 u8_t state; 975 } status_changed; 976 /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */ 977 struct ipv4_changed_s 978 { 979 /** Old IPv4 address */ 980 const ip_addr_t* old_address; 981 const ip_addr_t* old_netmask; 982 const ip_addr_t* old_gw; 983 } ipv4_changed; 984 /** Args to LWIP_NSC_IPV6_SET callback */ 985 struct ipv6_set_s 986 { 987 /** Index of changed IPv6 address */ 988 s8_t addr_index; 989 /** Old IPv6 address */ 990 const ip_addr_t* old_address; 991 } ipv6_set; 992 /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */ 993 struct ipv6_addr_state_changed_s 994 { 995 /** Index of affected IPv6 address */ 996 s8_t addr_index; 997 /** Old IPv6 address state */ 998 u8_t old_state; 999 /** Affected IPv6 address */ 1000 const ip_addr_t* address; 1001 } ipv6_addr_state_changed; 1002 } netif_ext_callback_args_t; 1003 1004 /** 1005 * @ingroup netif 1006 * Function used for extended netif status callbacks 1007 * Note: When parsing reason argument, keep in mind that more reasons may be added in the future! 1008 * @param netif netif that is affected by change 1009 * @param reason change reason 1010 * @param args depends on reason, see reason description 1011 */ 1012 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 1013 1014 extern void driverif_input(struct netif *netif, struct pbuf *p); 1015 #if LWIP_NETIF_EXT_STATUS_CALLBACK 1016 struct netif_ext_callback; 1017 typedef struct netif_ext_callback 1018 { 1019 netif_ext_callback_fn callback_fn; 1020 struct netif_ext_callback* next; 1021 } netif_ext_callback_t; 1022 1023 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name; 1024 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn); 1025 void netif_remove_ext_callback(netif_ext_callback_t* callback); 1026 void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 1027 #else 1028 #define NETIF_DECLARE_EXT_CALLBACK(name) 1029 #define netif_add_ext_callback(callback, fn) 1030 #define netif_remove_ext_callback(callback) 1031 #define netif_invoke_ext_callback(netif, reason, args) 1032 #endif 1033 #define netif_get_netdev(netif) (((netif) != NULL) ? ((netif)->state) : NULL) 1034 #define netif_set_netdev(netif, netdev) do { if((netif) != NULL) { (netif)->state = netdev; }}while(0) 1035 #ifdef __cplusplus 1036 } 1037 #endif 1038 1039 #define NETIF_MTU_MIN 1280 1040 #endif /* LWIP_HDR_NETIF_H */ 1041