STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
netif.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef LWIP_HDR_NETIF_H
33 #define LWIP_HDR_NETIF_H
34 
35 #include "lwip/opt.h"
36 
37 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
38 
39 #include "lwip/err.h"
40 
41 #include "lwip/ip_addr.h"
42 
43 #include "lwip/def.h"
44 #include "lwip/pbuf.h"
45 #include "lwip/stats.h"
46 
47 #if LWIP_DHCP
48 struct dhcp;
49 #endif
50 #if LWIP_AUTOIP
51 struct autoip;
52 #endif
53 #if LWIP_IPV6_DHCP6
54 struct dhcp6;
55 #endif /* LWIP_IPV6_DHCP6 */
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 /* Throughout this file, IP addresses are expected to be in
62  * the same byte order as in IP_PCB. */
63 
67 #ifndef NETIF_MAX_HWADDR_LEN
68 #define NETIF_MAX_HWADDR_LEN 6U
69 #endif
70 
77 #define NETIF_FLAG_UP 0x01U
78 
80 #define NETIF_FLAG_BROADCAST 0x02U
81 
86 #define NETIF_FLAG_LINK_UP 0x04U
87 
90 #define NETIF_FLAG_ETHARP 0x08U
91 
94 #define NETIF_FLAG_ETHERNET 0x10U
95 
97 #define NETIF_FLAG_IGMP 0x20U
98 
100 #define NETIF_FLAG_MLD6 0x40U
101 
102 #if LWIP_CHECKSUM_CTRL_PER_NETIF
103 #define NETIF_CHECKSUM_GEN_IP 0x0001
104 #define NETIF_CHECKSUM_GEN_UDP 0x0002
105 #define NETIF_CHECKSUM_GEN_TCP 0x0004
106 #define NETIF_CHECKSUM_GEN_ICMP 0x0008
107 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010
108 #define NETIF_CHECKSUM_CHECK_IP 0x0100
109 #define NETIF_CHECKSUM_CHECK_UDP 0x0200
110 #define NETIF_CHECKSUM_CHECK_TCP 0x0400
111 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800
112 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
113 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
114 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000
115 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
116 
117 struct netif;
118 
124 typedef err_t (*netif_init_fn)(struct netif *netif);
131 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
132 
133 #if LWIP_IPV4
134 
142 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
143  const ip4_addr_t *ipaddr);
144 #endif /* LWIP_IPV4*/
145 
146 #if LWIP_IPV6
147 
155 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
156  const ip6_addr_t *ipaddr);
157 #endif /* LWIP_IPV6 */
158 
165 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
167 typedef void (*netif_status_callback_fn)(struct netif *netif);
168 #if LWIP_IPV4 && LWIP_IGMP
169 
170 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
171  const ip4_addr_t *group, u8_t action);
172 #endif /* LWIP_IPV4 && LWIP_IGMP */
173 #if LWIP_IPV6 && LWIP_IPV6_MLD
174 
175 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
176  const ip6_addr_t *group, u8_t action);
177 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
178 
182 struct netif {
184  struct netif *next;
185 
186 #if LWIP_IPV4
187 
188  ip_addr_t ip_addr;
189  ip_addr_t netmask;
190  ip_addr_t gw;
191 #endif /* LWIP_IPV4 */
192 #if LWIP_IPV6
193 
197  u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
198 #endif /* LWIP_IPV6 */
199 
202 #if LWIP_IPV4
203 
206  netif_output_fn output;
207 #endif /* LWIP_IPV4 */
208 
212 #if LWIP_IPV6
213 
216  netif_output_ip6_fn output_ip6;
217 #endif /* LWIP_IPV6 */
218 #if LWIP_NETIF_STATUS_CALLBACK
219 
221  netif_status_callback_fn status_callback;
222 #endif /* LWIP_NETIF_STATUS_CALLBACK */
223 #if LWIP_NETIF_LINK_CALLBACK
224 
226  netif_status_callback_fn link_callback;
227 #endif /* LWIP_NETIF_LINK_CALLBACK */
228 #if LWIP_NETIF_REMOVE_CALLBACK
229 
230  netif_status_callback_fn remove_callback;
231 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
232 
234  void *state;
235 #if LWIP_DHCP
236 
237  struct dhcp *dhcp;
238 #endif /* LWIP_DHCP */
239 #if LWIP_AUTOIP
240 
241  struct autoip *autoip;
242 #endif
243 #if LWIP_IPV6_AUTOCONFIG
244 
245  u8_t ip6_autoconfig_enabled;
246 #endif /* LWIP_IPV6_AUTOCONFIG */
247 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
248 
249  u8_t rs_count;
250 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
251 #if LWIP_IPV6_DHCP6
252 
253  struct dhcp6 *dhcp6;
254 #endif /* LWIP_IPV6_DHCP6 */
255 #if LWIP_NETIF_HOSTNAME
256  /* the hostname for this netif, NULL is a valid value */
257  const char* hostname;
258 #endif /* LWIP_NETIF_HOSTNAME */
259 #if LWIP_CHECKSUM_CTRL_PER_NETIF
260  u16_t chksum_flags;
261 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
262 
271  char name[2];
274 #if MIB2_STATS
275 
276  u8_t link_type;
278  u32_t link_speed;
280  u32_t ts;
282  struct stats_mib2_netif_ctrs mib2_counters;
283 #endif /* MIB2_STATS */
284 #if LWIP_IPV4 && LWIP_IGMP
285 
287  netif_igmp_mac_filter_fn igmp_mac_filter;
288 #endif /* LWIP_IPV4 && LWIP_IGMP */
289 #if LWIP_IPV6 && LWIP_IPV6_MLD
290 
292  netif_mld_mac_filter_fn mld_mac_filter;
293 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
294 #if LWIP_NETIF_HWADDRHINT
295  u8_t *addr_hint;
296 #endif /* LWIP_NETIF_HWADDRHINT */
297 #if ENABLE_LOOPBACK
298  /* List of packets to be queued for ourselves. */
299  struct pbuf *loop_first;
300  struct pbuf *loop_last;
301 #if LWIP_LOOPBACK_MAX_PBUFS
302  u16_t loop_cnt_current;
303 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
304 #endif /* ENABLE_LOOPBACK */
305 };
306 
307 #if LWIP_CHECKSUM_CTRL_PER_NETIF
308 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
309  (netif)->chksum_flags = chksumflags; } while(0)
310 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
311 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
312 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
313 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
314 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
315 
317 extern struct netif *netif_list;
319 extern struct netif *netif_default;
320 
321 void netif_init(void);
322 
323 struct netif *netif_add(struct netif *netif,
324 #if LWIP_IPV4
325  const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
326 #endif /* LWIP_IPV4 */
327  void *state, netif_init_fn init, netif_input_fn input);
328 #if LWIP_IPV4
329 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
330  const ip4_addr_t *gw);
331 #endif /* LWIP_IPV4 */
332 void netif_remove(struct netif * netif);
333 
334 /* Returns a network interface given its name. The name is of the form
335  "et0", where the first two letters are the "name" field in the
336  netif structure, and the digit is in the num field in the same
337  structure. */
338 struct netif *netif_find(const char *name);
339 
340 void netif_set_default(struct netif *netif);
341 
342 #if LWIP_IPV4
343 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
344 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
345 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
346 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
347 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
348 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
349 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
350 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
351 #endif /* LWIP_IPV4 */
352 
353 void netif_set_up(struct netif *netif);
354 void netif_set_down(struct netif *netif);
356 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
357 
358 #if LWIP_NETIF_STATUS_CALLBACK
359 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
360 #endif /* LWIP_NETIF_STATUS_CALLBACK */
361 #if LWIP_NETIF_REMOVE_CALLBACK
362 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
363 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
364 
365 void netif_set_link_up(struct netif *netif);
366 void netif_set_link_down(struct netif *netif);
368 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
369 
370 #if LWIP_NETIF_LINK_CALLBACK
371 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
372 #endif /* LWIP_NETIF_LINK_CALLBACK */
373 
374 #if LWIP_NETIF_HOSTNAME
375 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
376 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
377 #endif /* LWIP_NETIF_HOSTNAME */
378 
379 #if LWIP_IGMP
380 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
381 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
382 #endif /* LWIP_IGMP */
383 
384 #if LWIP_IPV6 && LWIP_IPV6_MLD
385 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
386 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
387 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
388 
389 #if ENABLE_LOOPBACK
390 err_t netif_loop_output(struct netif *netif, struct pbuf *p);
391 void netif_poll(struct netif *netif);
392 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
393 void netif_poll_all(void);
394 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
395 #endif /* ENABLE_LOOPBACK */
396 
397 #if LWIP_IPV6
398 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
399 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
400 #define netif_ip6_addr_set(netif, i, addr6) do { ip6_addr_set(ip_2_ip6(&((netif)->ip6_addr[i])), addr6); IP_SET_TYPE_VAL((netif)->ip6_addr[i], IPADDR_TYPE_V6); } while(0)
401 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
402 #define netif_ip6_addr_set_state(netif, i, state) ((netif)->ip6_addr_state[i] = (state))
403 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr);
404 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
405 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx);
406 #endif /* LWIP_IPV6 */
407 
408 #if LWIP_NETIF_HWADDRHINT
409 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
410 #else /* LWIP_NETIF_HWADDRHINT */
411 #define NETIF_SET_HWADDRHINT(netif, hint)
412 #endif /* LWIP_NETIF_HWADDRHINT */
413 
414 #ifdef __cplusplus
415 }
416 #endif
417 
418 #endif /* LWIP_HDR_NETIF_H */
419 
420 
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:131
u8_t flags
Definition: netif.h:269
void(* netif_status_callback_fn)(struct netif *netif)
Definition: netif.h:167
void netif_init(void)
Definition: netif.c:139
void * state
Definition: netif.h:234
void netif_set_down(struct netif *netif)
Definition: netif.c:587
signed char s8_t
Definition: cc.h:39
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:267
struct netif * netif_list
Definition: netif.c:84
netif_input_fn input
Definition: netif.h:201
struct netif * next
Definition: netif.h:184
#define LWIP_IPV4
Definition: opt.h:549
u16_t mtu
Definition: netif.h:263
void netif_set_default(struct netif *netif)
Definition: netif.c:511
char name[2]
Definition: netif.h:271
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:68
netif_linkoutput_fn linkoutput
Definition: netif.h:211
void netif_set_up(struct netif *netif)
Definition: netif.c:530
void netif_set_link_up(struct netif *netif)
Definition: netif.c:632
unsigned long u32_t
Definition: cc.h:42
u8_t num
Definition: netif.h:273
Definition: pbuf.h:108
struct netif * netif_find(const char *name)
Definition: netif.c:389
struct netif * netif_default
Definition: netif.c:85
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
u8_t hwaddr_len
Definition: netif.h:265
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:124
#define LWIP_IPV6_NUM_ADDRESSES
Definition: opt.h:2451
void netif_remove(struct netif *netif)
Definition: netif.c:319
void netif_set_link_down(struct netif *netif)
Definition: netif.c:660
unsigned char u8_t
Definition: cc.h:38
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:184
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: netif.h:165
unsigned short u16_t
Definition: cc.h:40