TizenRT Libs&Environment  v2.0 M2
netif.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /*
19  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without modification,
23  * are permitted provided that the following conditions are met:
24  *
25  * 1. Redistributions of source code must retain the above copyright notice,
26  * this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright notice,
28  * this list of conditions and the following disclaimer in the documentation
29  * and/or other materials provided with the distribution.
30  * 3. The name of the author may not be used to endorse or promote products
31  * derived from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
34  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
36  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
38  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
42  * OF SUCH DAMAGE.
43  *
44  * This file is part of the lwIP TCP/IP stack.
45  *
46  * Author: Adam Dunkels <adam@sics.se>
47  *
48  */
49 
61 #ifndef __LWIP_NETIF_H__
62 #define __LWIP_NETIF_H__
63 #include <tinyara/config.h>
64 #include <net/ethernet.h>
65 
66 #include <net/lwip/opt.h>
67 #ifdef CONFIG_NET_ETH_MTU
68 #define MAX_NET_DEV_MTU CONFIG_NET_ETH_MTU
69 #else
70 #define MAX_NET_DEV_MTU 1500
71 #endif
72 
73 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
74 
75 #include <net/lwip/err.h>
76 #include <net/lwip/ip_addr.h>
77 #include <net/lwip/def.h>
78 #include <net/lwip/pbuf.h>
79 #include <net/lwip/stats.h>
80 
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 
85 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
86 
87 /* Throughout this file, IP addresses are expected to be in
88  * the same byte order as in IP_PCB. */
89 
93 #ifndef NETIF_MAX_HWADDR_LEN
94 #define NETIF_MAX_HWADDR_LEN 6U
95 #endif
96 
109 #define NETIF_FLAG_UP 0x01U
110 
112 #define NETIF_FLAG_BROADCAST 0x02U
113 
118 #define NETIF_FLAG_LINK_UP 0x04U
119 
122 #define NETIF_FLAG_ETHARP 0x08U
123 
126 #define NETIF_FLAG_ETHERNET 0x10U
127 
129 #define NETIF_FLAG_IGMP 0x20U
130 
132 #define NETIF_FLAG_MLD6 0x40U
133 
139 #if LWIP_DHCP
141 #endif
142 #if LWIP_AUTOIP
143  LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
144 #endif
145 #if LWIP_IGMP
146  LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
147 #endif
148 #if LWIP_IPV6_MLD
149  LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
150 #endif
152 };
153 
154 #if LWIP_CHECKSUM_CTRL_PER_NETIF
155 
156 #define NETIF_CHECKSUM_GEN_IP 0x0001
157 #define NETIF_CHECKSUM_GEN_UDP 0x0002
158 #define NETIF_CHECKSUM_GEN_TCP 0x0004
159 #define NETIF_CHECKSUM_GEN_ICMP 0x0008
160 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010
161 #define NETIF_CHECKSUM_CHECK_IP 0x0100
162 #define NETIF_CHECKSUM_CHECK_UDP 0x0200
163 #define NETIF_CHECKSUM_CHECK_TCP 0x0400
164 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800
165 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
166 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
167 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000
168 
169 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
170 
171 struct netif;
172 
180 };
181 
187 typedef err_t (*netif_init_fn)(struct netif * netif);
194 typedef err_t (*netif_input_fn)(struct pbuf * p, struct netif * inp);
195 
196 #if LWIP_IPV4
197 
205 typedef err_t (*netif_output_fn)(struct netif * netif, struct pbuf * p, const ip4_addr_t * ipaddr);
206 #endif /* LWIP_IPV4 */
207 
208 #if LWIP_IPV6
209 
217 typedef err_t (*netif_output_ip6_fn)(struct netif * netif, struct pbuf * p, const ip6_addr_t * ipaddr);
218 #endif /* LWIP_IPV6 */
219 
226 typedef err_t (*netif_linkoutput_fn)(struct netif * netif, struct pbuf * p);
228 typedef void (*netif_status_callback_fn)(struct netif * netif);
229 #if LWIP_IPV4 && LWIP_IGMP
230 
231 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif * netif, const ip4_addr_t * group, enum netif_mac_filter_action action);
232 #endif /* LWIP_IPV4 && LWIP_IGMP */
233 #if LWIP_IPV6 && LWIP_IPV6_MLD
234 
235 typedef err_t (*netif_mld_mac_filter_fn)(struct netif * netif, const ip6_addr_t * group, enum netif_mac_filter_action action);
236 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
237 
238 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
239  u8_t netif_alloc_client_data_id(void);
243 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
244 
247 #define netif_get_client_data(netif, id) (netif)->client_data[(id)]
248 #endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */
249 
253 struct netif {
255  struct netif *next;
256 
257 #if LWIP_IPV4
258 
259  ip_addr_t ip_addr;
260  ip_addr_t netmask;
261  ip_addr_t gw;
262 #endif /* LWIP_IPV4 */
263 #if LWIP_IPV6
264  ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
267  u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
268 #endif /* LWIP_IPV6 */
269 
272 #if LWIP_IPV4
273 
277  netif_output_fn output;
278 #endif /* LWIP_IPV4 */
279 
283 #if LWIP_IPV6
284 
288  netif_output_ip6_fn output_ip6;
289 #endif /* LWIP_IPV6 */
290 #if LWIP_NETIF_STATUS_CALLBACK
291 
293  netif_status_callback_fn status_callback;
294 #endif /* LWIP_NETIF_STATUS_CALLBACK */
295 #if LWIP_NETIF_LINK_CALLBACK
296 
298  netif_status_callback_fn link_callback;
299 #endif /* LWIP_NETIF_LINK_CALLBACK */
300 #if LWIP_NETIF_REMOVE_CALLBACK
301 
302  netif_status_callback_fn remove_callback;
303 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
304 
306  void *state;
307 #ifdef netif_get_client_data
308  void *client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];
309 #endif
310 #if LWIP_IPV6_AUTOCONFIG
311 
312  u8_t ip6_autoconfig_enabled;
313 #endif /* LWIP_IPV6_AUTOCONFIG */
314 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
315 
316  u8_t rs_count;
317  u16_t rs_interval;
318 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
319 #if LWIP_NETIF_HOSTNAME
320  /* the hostname for this netif, NULL is a valid value */
321  const char *hostname;
322 #endif /* LWIP_NETIF_HOSTNAME */
323 #if LWIP_CHECKSUM_CTRL_PER_NETIF
324  u16_t chksum_flags;
325 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
326 
327  u16_t mtu;
333  u8_t flags;
335  char name[2];
337  u8_t num;
338 #if MIB2_STATS
339 
340  u8_t link_type;
342  u32_t link_speed;
344  u32_t ts;
346  struct stats_mib2_netif_ctrs mib2_counters;
347 #endif /* MIB2_STATS */
348 #if LWIP_IPV4 && LWIP_IGMP
349 
351  netif_igmp_mac_filter_fn igmp_mac_filter;
352 #endif /* LWIP_IPV4 && LWIP_IGMP */
353 #if LWIP_IPV6 && LWIP_IPV6_MLD
354 
356  netif_mld_mac_filter_fn mld_mac_filter;
357 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
358 #if LWIP_NETIF_HWADDRHINT
359  u8_t *addr_hint;
360 #endif /* LWIP_NETIF_HWADDRHINT */
361 #if ENABLE_LOOPBACK
362  /* List of packets to be queued for ourselves. */
363  struct pbuf *loop_first;
364  struct pbuf *loop_last;
365 #if LWIP_LOOPBACK_MAX_PBUFS
366  u16_t loop_cnt_current;
367 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
368 #endif /* ENABLE_LOOPBACK */
369 
370  char d_ifname[6];
371 #if CONFIG_NSOCKET_DESCRIPTORS > 0
372  struct netif *flink;
373 #endif
374  struct ether_addr d_mac; /* Device MAC address */
375 
376  u16_t d_len;
377  u32_t d_flags;
378  uint32_t d_ipaddr; /* Host IPv4 address assigned to the network interface */
379  uint32_t d_draddr; /* Default router IP address */
380  uint32_t d_netmask; /* Network subnet mask */
381  /* Driver callbacks */
382  int (*d_ifup) (FAR struct netif * dev);
383  int (*d_ifdown) (FAR struct netif * dev);
384  int (*d_ifstate) (FAR struct netif * dev);
385  int (*d_txavail) (FAR struct netif * dev);
386  int (*d_txpoll) (FAR struct netif * dev);
387  /* Drivers may attached device-specific, private information */
388  void *d_private;
389 #ifdef CONFIG_NET_MULTIBUFFER
390  u8_t *d_buf;
391 #else
392  u8_t d_buf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
393 #endif
394 #if LWIP_DHCP
395  struct dhcp *dhcp;
396 #if LWIP_DHCPS
397  struct udp_pcb *dhcps_pcb;
398 #endif
399 #endif
400 };
401 
402 #if LWIP_CHECKSUM_CTRL_PER_NETIF
403 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
404  (netif)->chksum_flags = chksumflags; } while (0)
405 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
406 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
407 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
408 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
409 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
410 
411 #if CONFIG_NSOCKET_DESCRIPTORS > 0
412 #if CONFIG_NET_LWIP
413 extern struct netif *g_netdevices;
414 #endif
415 #endif
416 
418 extern struct netif *netif_list;
420 extern struct netif *netif_default;
421 
422 void netif_init(void);
423 
424 struct netif *netif_add(struct netif *netif,
425 #if LWIP_IPV4
426  const ip4_addr_t * ipaddr, const ip4_addr_t * netmask, const ip4_addr_t * gw,
427 #endif /* LWIP_IPV4 */
428  void *state, netif_init_fn init, netif_input_fn input);
429 #if LWIP_IPV4
430 void netif_set_addr(struct netif *netif, const ip4_addr_t * ipaddr, const ip4_addr_t * netmask, const ip4_addr_t * gw);
431 #endif /* LWIP_IPV4 */
432 void netif_remove(struct netif *netif);
433 
434 /* Returns a network interface given its name. The name is of the form
435  "et0", where the first two letters are the "name" field in the
436  netif structure, and the digit is in the num field in the same
437  structure. */
438 struct netif *netif_find(const char *name);
439 
440 void netif_set_default(struct netif *netif);
441 
442 #if LWIP_IPV4
443 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t * ipaddr);
444 void netif_set_netmask(struct netif *netif, const ip4_addr_t * netmask);
445 void netif_set_gw(struct netif *netif, const ip4_addr_t * gw);
447 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
448 
449 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
450 
451 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
452 
453 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
454 
455 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
456 
457 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
458 #endif /* LWIP_IPV4 */
459 
460 void netif_set_up(struct netif *netif);
461 void netif_set_down(struct netif *netif);
465 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
466 
467 #if LWIP_NETIF_STATUS_CALLBACK
468 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
469 #endif /* LWIP_NETIF_STATUS_CALLBACK */
470 #if LWIP_NETIF_REMOVE_CALLBACK
471 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
472 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
473 
474 void netif_set_link_up(struct netif *netif);
475 void netif_set_link_down(struct netif *netif);
477 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
478 
479 #if LWIP_NETIF_LINK_CALLBACK
480 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
481 #endif /* LWIP_NETIF_LINK_CALLBACK */
482 
483 #if LWIP_NETIF_HOSTNAME
484 
485 #define netif_set_hostname(netif, name) do { if ((netif) != NULL) { (netif)->hostname = name; } } while (0)
486 
487 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
488 #endif /* LWIP_NETIF_HOSTNAME */
489 
490 #if LWIP_IGMP
491 
492 #define netif_set_igmp_mac_filter(netif, function) do { if ((netif) != NULL) { (netif)->igmp_mac_filter = function; } } while (0)
493 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
494 #endif /* LWIP_IGMP */
495 
496 #if LWIP_IPV6 && LWIP_IPV6_MLD
497 
498 #define netif_set_mld_mac_filter(netif, function) do { if ((netif) != NULL) { (netif)->mld_mac_filter = function; } } while (0)
499 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
500 #define netif_mld_mac_filter(netif, addr, action) do { if ((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); } } while (0)
501 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
502 
503 #if ENABLE_LOOPBACK
504 err_t netif_loop_output(struct netif *netif, struct pbuf *p);
505 void netif_poll(struct netif *netif);
506 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
507 void netif_poll_all(void);
508 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
509 #endif /* ENABLE_LOOPBACK */
510 
511 err_t netif_input(struct pbuf *p, struct netif *inp);
512 
513 #if LWIP_IPV6
514 
515 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
516 
517 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
518 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t * addr6);
519 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);
520 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
521 void netif_ip6_addr_set_state(struct netif *netif, s8_t addr_idx, u8_t state);
522 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t * ip6addr);
523 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
524 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t * ip6addr, s8_t * chosen_idx);
525 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if (netif) { (netif)->ip6_autoconfig_enabled = (action); } } while (0)
526 #endif /* LWIP_IPV6 */
527 
528 #if LWIP_NETIF_HWADDRHINT
529 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
530 #else /* LWIP_NETIF_HWADDRHINT */
531 #define NETIF_SET_HWADDRHINT(netif, hint)
532 #endif /* LWIP_NETIF_HWADDRHINT */
533 
534 #ifdef __cplusplus
535 }
536 #endif
537 #endif /* LWIP_HDR_NETIF_H */
uint32_t d_netmask
Definition: netif.h:380
u8_t flags
Definition: netif.h:333
void * d_private
Definition: netif.h:388
int(* d_ifstate)(FAR struct netif *dev)
Definition: netif.h:384
void * client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX+LWIP_NUM_NETIF_CLIENT_DATA]
Definition: netif.h:308
u16_t d_len
Definition: netif.h:376
struct dhcp * dhcp
Definition: netif.h:395
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
u8_t netif_alloc_client_data_id(void)
void netif_set_default(struct netif *netif)
u8_t hwaddr_len
Definition: netif.h:329
#define MAX_NET_DEV_MTU
Definition: netif.h:70
char d_ifname[6]
Definition: netif.h:370
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:194
netif_input_fn input
Definition: netif.h:271
netif_mac_filter_action
Definition: netif.h:175
int(* d_ifup)(FAR struct netif *dev)
Definition: netif.h:382
u32_t d_flags
Definition: netif.h:377
struct ether_addr d_mac
Definition: netif.h:374
int(* d_ifdown)(FAR struct netif *dev)
Definition: netif.h:383
u8_t num
Definition: netif.h:337
void netif_remove(struct netif *netif)
int(* d_txavail)(FAR struct netif *dev)
Definition: netif.h:385
void netif_set_down(struct netif *netif)
void netif_set_link_down(struct netif *netif)
void netif_set_up(struct netif *netif)
Definition: netif.h:253
struct netif * netif_list
u16_t mtu
Definition: netif.h:327
void netif_init(void)
uint32_t d_draddr
Definition: netif.h:379
void(* netif_status_callback_fn)(struct netif *netif)
Definition: netif.h:228
err_t netif_input(struct pbuf *p, struct netif *inp)
char name[2]
Definition: netif.h:335
struct netif * next
Definition: netif.h:255
u8_t d_buf[MAX_NET_DEV_MTU+CONFIG_NET_GUARDSIZE]
Definition: netif.h:392
void netif_set_link_up(struct netif *netif)
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:187
int(* d_txpoll)(FAR struct netif *dev)
Definition: netif.h:386
struct netif * netif_default
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:331
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:94
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: netif.h:226
netif_linkoutput_fn linkoutput
Definition: netif.h:282
lwip_internal_netif_client_data_index
Definition: netif.h:138
struct netif * netif_find(const char *name)
void * state
Definition: netif.h:306
uint32_t d_ipaddr
Definition: netif.h:378