Prusa MINI Firmware overview
Network interface (NETIF)
Collaboration diagram for Network interface (NETIF):

Modules

 IPv4 address handling
 
 IPv6 address handling
 
 Client data handling
 Store data (void*) on a netif for application usage.
 
 Flags
 
 MIB2 statistics
 

Macros

#define netif_is_up(netif)   (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
 

Functions

struct netifnetif_add (struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
 
void netif_remove (struct netif *netif)
 
struct netifnetif_find (const char *name)
 
void netif_set_default (struct netif *netif)
 
void netif_set_up (struct netif *netif)
 
void netif_set_down (struct netif *netif)
 
void netif_set_link_up (struct netif *netif)
 
void netif_set_link_down (struct netif *netif)
 

Detailed Description

Macro Definition Documentation

◆ netif_is_up

#define netif_is_up (   netif)    (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)

Ask if an interface is up

Function Documentation

◆ netif_add()

struct netif* netif_add ( struct netif netif,
void state,
netif_init_fn  init,
netif_input_fn  input 
)

Add a network interface to the list of lwIP netifs.

Parameters
netifa pre-allocated netif structure
ipaddrIP address for the new netif
netmasknetwork mask for the new netif
gwdefault gateway IP address for the new netif
stateopaque data passed to the new netif
initcallback function that initializes the interface
inputcallback function that is called to pass ingress packets up in the protocol layer stack.
It is recommended to use a function that passes the input directly to the stack (netif_input(), NO_SYS=1 mode) or via sending a message to TCPIP thread (tcpip_input(), NO_SYS=0 mode).
These functions use netif flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET to decide whether to forward to ethernet_input() or ip_input(). In other words, the functions only work when the netif driver is implemented correctly!
Most members of struct netif should be be initialized by the netif init function = netif driver (init parameter of this function).
IPv6: Don't forget to call netif_create_ip6_linklocal_address() after setting the MAC address in struct netif.hwaddr (IPv6 requires a link-local address).
Returns
netif, or NULL if failed.
246 {
247 #if LWIP_IPV6
248  s8_t i;
249 #endif
250 
251  LWIP_ASSERT("No init function given", init != NULL);
252 
253  /* reset new interface configuration state */
254 #if LWIP_IPV4
255  ip_addr_set_zero_ip4(&netif->ip_addr);
256  ip_addr_set_zero_ip4(&netif->netmask);
257  ip_addr_set_zero_ip4(&netif->gw);
258 #endif /* LWIP_IPV4 */
259 #if LWIP_IPV6
260  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
261  ip_addr_set_zero_ip6(&netif->ip6_addr[i]);
262  netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
263  }
264  netif->output_ip6 = netif_null_output_ip6;
265 #endif /* LWIP_IPV6 */
266  NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL);
267  netif->flags = 0;
268 #ifdef netif_get_client_data
269  memset(netif->client_data, 0, sizeof(netif->client_data));
270 #endif /* LWIP_NUM_NETIF_CLIENT_DATA */
271 #if LWIP_IPV6_AUTOCONFIG
272  /* IPv6 address autoconfiguration not enabled by default */
273  netif->ip6_autoconfig_enabled = 0;
274 #endif /* LWIP_IPV6_AUTOCONFIG */
275 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
277 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
278 #if LWIP_NETIF_STATUS_CALLBACK
279  netif->status_callback = NULL;
280 #endif /* LWIP_NETIF_STATUS_CALLBACK */
281 #if LWIP_NETIF_LINK_CALLBACK
282  netif->link_callback = NULL;
283 #endif /* LWIP_NETIF_LINK_CALLBACK */
284 #if LWIP_IGMP
285  netif->igmp_mac_filter = NULL;
286 #endif /* LWIP_IGMP */
287 #if LWIP_IPV6 && LWIP_IPV6_MLD
288  netif->mld_mac_filter = NULL;
289 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
290 #if ENABLE_LOOPBACK
291  netif->loop_first = NULL;
292  netif->loop_last = NULL;
293 #endif /* ENABLE_LOOPBACK */
294 
295  /* remember netif specific state information data */
296  netif->state = state;
297  netif->num = netif_num++;
298  netif->input = input;
299 
301 #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
302  netif->loop_cnt_current = 0;
303 #endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
304 
305 #if LWIP_IPV4
306  netif_set_addr(netif, ipaddr, netmask, gw);
307 #endif /* LWIP_IPV4 */
308 
309  /* call user specified initialization function for netif */
310  if (init(netif) != ERR_OK) {
311  return NULL;
312  }
313 
314  /* add this netif to the list */
315  netif->next = netif_list;
316  netif_list = netif;
318 
319 #if LWIP_IGMP
320  /* start IGMP processing */
321  if (netif->flags & NETIF_FLAG_IGMP) {
322  igmp_start(netif);
323  }
324 #endif /* LWIP_IGMP */
325 
326  LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP",
327  netif->name[0], netif->name[1]));
328 #if LWIP_IPV4
329  LWIP_DEBUGF(NETIF_DEBUG, (" addr "));
330  ip4_addr_debug_print(NETIF_DEBUG, ipaddr);
331  LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
332  ip4_addr_debug_print(NETIF_DEBUG, netmask);
333  LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
334  ip4_addr_debug_print(NETIF_DEBUG, gw);
335 #endif /* LWIP_IPV4 */
336  LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
337  return netif;
338 }
Here is the caller graph for this function:

◆ netif_remove()

void netif_remove ( struct netif netif)

Remove a network interface from the list of lwIP netifs.

Parameters
netifthe network interface to remove
378 {
379 #if LWIP_IPV6
380  int i;
381 #endif
382 
383  if (netif == NULL) {
384  return;
385  }
386 
387 #if LWIP_IPV4
388  if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
389 #if LWIP_TCP
390  tcp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL);
391 #endif /* LWIP_TCP */
392 #if LWIP_UDP
393  udp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL);
394 #endif /* LWIP_UDP */
395 #if LWIP_RAW
396  raw_netif_ip_addr_changed(netif_ip_addr4(netif), NULL);
397 #endif /* LWIP_RAW */
398  }
399 
400 #if LWIP_IGMP
401  /* stop IGMP processing */
402  if (netif->flags & NETIF_FLAG_IGMP) {
403  igmp_stop(netif);
404  }
405 #endif /* LWIP_IGMP */
406 #endif /* LWIP_IPV4*/
407 
408 #if LWIP_IPV6
409  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
410  if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) {
411 #if LWIP_TCP
412  tcp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
413 #endif /* LWIP_TCP */
414 #if LWIP_UDP
415  udp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
416 #endif /* LWIP_UDP */
417 #if LWIP_RAW
418  raw_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
419 #endif /* LWIP_RAW */
420  }
421  }
422 #if LWIP_IPV6_MLD
423  /* stop MLD processing */
424  mld6_stop(netif);
425 #endif /* LWIP_IPV6_MLD */
426 #endif /* LWIP_IPV6 */
427  if (netif_is_up(netif)) {
428  /* set netif down before removing (call callback function) */
430  }
431 
433 
434  /* this netif is default? */
435  if (netif_default == netif) {
436  /* reset default netif */
438  }
439  /* is it the first netif? */
440  if (netif_list == netif) {
441  netif_list = netif->next;
442  } else {
443  /* look for netif further down the list */
444  struct netif * tmp_netif;
445  for (tmp_netif = netif_list; tmp_netif != NULL; tmp_netif = tmp_netif->next) {
446  if (tmp_netif->next == netif) {
447  tmp_netif->next = netif->next;
448  break;
449  }
450  }
451  if (tmp_netif == NULL) {
452  return; /* netif is not on the list */
453  }
454  }
456 #if LWIP_NETIF_REMOVE_CALLBACK
457  if (netif->remove_callback) {
458  netif->remove_callback(netif);
459  }
460 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
461  LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
462 }
Here is the call graph for this function:

◆ netif_find()

struct netif* netif_find ( const char *  name)

Find a network interface by searching for its name

Parameters
namethe name of the netif (like netif->name) plus concatenated number in ascii representation (e.g. 'en0')
473 {
474  struct netif *netif;
475  u8_t num;
476 
477  if (name == NULL) {
478  return NULL;
479  }
480 
481  num = (u8_t)(name[2] - '0');
482 
483  for (netif = netif_list; netif != NULL; netif = netif->next) {
484  if (num == netif->num &&
485  name[0] == netif->name[0] &&
486  name[1] == netif->name[1]) {
487  LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
488  return netif;
489  }
490  }
491  LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
492  return NULL;
493 }

◆ netif_set_default()

void netif_set_default ( struct netif netif)

Set a network interface as the default network interface (used to output all packets for which no specific route is found)

Parameters
netifthe default network interface
605 {
606  if (netif == NULL) {
607  /* remove default route */
609  } else {
610  /* install default route */
612  }
614  LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
615  netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
616 }
Here is the caller graph for this function:

◆ netif_set_up()

void netif_set_up ( struct netif netif)

Bring an interface up, available for processing traffic.

625 {
626  if (!(netif->flags & NETIF_FLAG_UP)) {
628 
630 
632 
633  if (netif->flags & NETIF_FLAG_LINK_UP) {
635  }
636  }
637 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netif_set_down()

void netif_set_down ( struct netif netif)

Bring an interface down, disabling any traffic processing.

683 {
684  if (netif->flags & NETIF_FLAG_UP) {
687 
688 #if LWIP_IPV4 && LWIP_ARP
689  if (netif->flags & NETIF_FLAG_ETHARP) {
690  etharp_cleanup_netif(netif);
691  }
692 #endif /* LWIP_IPV4 && LWIP_ARP */
693 
694 #if LWIP_IPV6
695  nd6_cleanup_netif(netif);
696 #endif /* LWIP_IPV6 */
697 
699  }
700 }
Here is the caller graph for this function:

◆ netif_set_link_up()

void netif_set_link_up ( struct netif netif)

Called by a driver when its link goes up

736 {
737  if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
739 
740 #if LWIP_DHCP
741  dhcp_network_changed(netif);
742 #endif /* LWIP_DHCP */
743 
744 #if LWIP_AUTOIP
745  autoip_network_changed(netif);
746 #endif /* LWIP_AUTOIP */
747 
748  if (netif->flags & NETIF_FLAG_UP) {
750  }
752  }
753 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netif_set_link_down()

void netif_set_link_down ( struct netif netif)

Called by a driver when its link goes down

761 {
762  if (netif->flags & NETIF_FLAG_LINK_UP) {
765  }
766 }
NETIF_FLAG_UP
#define NETIF_FLAG_UP
Definition: netif.h:78
NETIF_FLAG_IGMP
#define NETIF_FLAG_IGMP
Definition: netif.h:98
netif_set_down
void netif_set_down(struct netif *netif)
Definition: netif.c:682
ip_addr_set_zero_ip6
#define ip_addr_set_zero_ip6(ipaddr)
Definition: ip_addr.h:310
ipaddr
ip4_addr_t ipaddr
Definition: lwip.c:73
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
netif::input
netif_input_fn input
Definition: netif.h:244
NETIF_FLAG_ETHARP
#define NETIF_FLAG_ETHARP
Definition: netif.h:91
NETIF_STATUS_CALLBACK
#define NETIF_STATUS_CALLBACK(n)
Definition: netif.c:95
netif::state
void * state
Definition: netif.h:279
mib2_netif_added
#define mib2_netif_added(ni)
Definition: snmp.h:177
i
uint8_t i
Definition: screen_test_graph.c:72
state
static volatile fsensor_t state
Definition: filament_sensor.c:23
NETIF_SET_CHECKSUM_CTRL
#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
Definition: netif.h:348
netif::flags
u8_t flags
Definition: netif.h:305
NETIF_REPORT_TYPE_IPV4
#define NETIF_REPORT_TYPE_IPV4
Definition: netif.c:113
NETIF_SET_HWADDRHINT
#define NETIF_SET_HWADDRHINT(netif, hint)
Definition: netif.h:467
NULL
#define NULL
Definition: usbd_def.h:53
gw
ip4_addr_t gw
Definition: lwip.c:75
netif::num
u8_t num
Definition: netif.h:309
u8_t
uint8_t u8_t
Definition: arch.h:119
netmask
ip4_addr_t netmask
Definition: lwip.c:74
mib2_add_route_ip4
#define mib2_add_route_ip4(dflt, ni)
Definition: snmp.h:187
netif_list
struct netif * netif_list
Definition: netif.c:104
mib2_remove_route_ip4
#define mib2_remove_route_ip4(dflt, ni)
Definition: snmp.h:188
netif
Definition: netif.h:225
netif::name
char name[2]
Definition: netif.h:307
netif_default
struct netif * netif_default
Definition: netif.c:105
mib2_netif_removed
#define mib2_netif_removed(ni)
Definition: snmp.h:178
netif::next
struct netif * next
Definition: netif.h:227
s8_t
int8_t s8_t
Definition: arch.h:120
netif_set_default
void netif_set_default(struct netif *netif)
Definition: netif.c:604
netif_issue_reports
static void netif_issue_reports(struct netif *netif, u8_t report_type)
Definition: netif.c:642
ERR_OK
Definition: err.h:63
LWIP_ND6_MAX_MULTICAST_SOLICIT
#define LWIP_ND6_MAX_MULTICAST_SOLICIT
Definition: opt.h:2319
netif_num
static u8_t netif_num
Definition: netif.c:107
NETIF_DEBUG
#define NETIF_DEBUG
Definition: opt.h:2638
NETIF_FLAG_LINK_UP
#define NETIF_FLAG_LINK_UP
Definition: netif.h:87
LWIP_IPV6_NUM_ADDRESSES
#define LWIP_IPV6_NUM_ADDRESSES
Definition: opt.h:2160
MIB2_COPY_SYSUPTIME_TO
#define MIB2_COPY_SYSUPTIME_TO(ptrToVal)
Definition: snmp.h:136
mib2_remove_ip4
#define mib2_remove_ip4(ni)
Definition: snmp.h:186
LWIP_DEBUGF
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:164
NETIF_REPORT_TYPE_IPV6
#define NETIF_REPORT_TYPE_IPV6
Definition: netif.c:114
NETIF_LINK_CALLBACK
#define NETIF_LINK_CALLBACK(n)
Definition: netif.c:101
netif_is_up
#define netif_is_up(netif)
Definition: netif.h:401