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