Tizen RT Libs&Environment  v1.1 D4
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 #include <net/lwip/opt.h>
66 #ifdef CONFIG_NET_ETH_MTU
67 #define MAX_NET_DEV_MTU CONFIG_NET_ETH_MTU
68 #else
69 #define MAX_NET_DEV_MTU 1500
70 #endif
71 
72 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
73 
74 #include <net/lwip/err.h>
75 
76 #include <net/lwip/ipv4/ip_addr.h>
77 
78 #include <net/lwip/def.h>
79 #include <net/lwip/pbuf.h>
80 #if LWIP_DHCP
81 struct dhcp;
82 #endif
83 #if LWIP_AUTOIP
84 struct autoip;
85 #endif
86 
87 /* Temporary Static IP Settings, will be removed once config parameter is finalized and used */
88 
89 /* Static IP ADDRESS */
90 #define IP_ADDR0 192
91 #define IP_ADDR1 168
92 #define IP_ADDR2 2
93 #define IP_ADDR3 10
94 
95 /* NETMASK */
96 #define NETMASK_ADDR0 255
97 #define NETMASK_ADDR1 255
98 #define NETMASK_ADDR2 255
99 #define NETMASK_ADDR3 0
100 
101 /* Gateway Address */
102 #define GW_ADDR0 192
103 #define GW_ADDR1 168
104 #define GW_ADDR2 2
105 #define GW_ADDR3 1
106 
107 #ifdef __cplusplus
108 #define EXTERN extern "C"
109 extern "C" {
110 #else
111 #define EXTERN extern
112 #endif
113 
114 /* Throughout this file, IP addresses are expected to be in
115  * the same byte order as in IP_PCB. */
116 
119 #define NETIF_MAX_HWADDR_LEN 6U
120 
127 #define NETIF_FLAG_UP 0x01U
128 
130 #define NETIF_FLAG_BROADCAST 0x02U
131 
133 #define NETIF_FLAG_POINTTOPOINT 0x04U
134 
136 #define NETIF_FLAG_DHCP 0x08U
137 
142 #define NETIF_FLAG_LINK_UP 0x10U
143 
146 #define NETIF_FLAG_ETHARP 0x20U
147 
150 #define NETIF_FLAG_ETHERNET 0x40U
151 
153 #define NETIF_FLAG_IGMP 0x80U
154 
160 typedef err_t (*netif_init_fn)(struct netif *netif);
167 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
176 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr);
183 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
185 typedef void (*netif_status_callback_fn)(struct netif *netif);
187 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, ip_addr_t *group, u8_t action);
188 
189 #if defined(CONFIG_NET_ETHERNET)
190 #define MAC_ADDRLEN 6
191 #define MAC_HDRLEN 14
192 #elif defined(CONFIG_WIRELESS)
193 #define MAC_ADDRLEN 6
194 #define MAC_HDRLEN 14
195 #else
196 #define MAC_ADDRLEN 0
197 #define MAC_HDRLEN 0
198 #endif
199 
203 struct netif {
205  struct netif *next;
206 
208  ip_addr_t ip_addr;
209  ip_addr_t netmask;
210  ip_addr_t gw;
211 
223 #if LWIP_NETIF_STATUS_CALLBACK
224 
226  netif_status_callback_fn status_callback;
227 #endif /* LWIP_NETIF_STATUS_CALLBACK */
228 #if LWIP_NETIF_LINK_CALLBACK
229 
231  netif_status_callback_fn link_callback;
232 #endif /* LWIP_NETIF_LINK_CALLBACK */
233 #if LWIP_NETIF_REMOVE_CALLBACK
234 
235  netif_status_callback_fn remove_callback;
236 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
237 
239  void *state;
240 #if LWIP_DHCP
241 
242  struct dhcp *dhcp;
243 #if LWIP_DHCPS
244 
245  struct udp_pcb *dhcps_pcb;
246 #endif /* LWIP_DHCPS */
247 #endif /* LWIP_DHCP */
248 #if LWIP_AUTOIP
249 
250  struct autoip *autoip;
251 #endif
252 #if LWIP_NETIF_HOSTNAME
253  /* the hostname for this netif, NULL is a valid value */
254  char *hostname;
255 #endif /* LWIP_NETIF_HOSTNAME */
256 
257  u16_t mtu;
263  u8_t flags;
265  char name[2];
267  u8_t num;
268 #if LWIP_SNMP
269 
270  u8_t link_type;
272  u32_t link_speed;
274  u32_t ts;
276  u32_t ifinoctets;
277  u32_t ifinucastpkts;
278  u32_t ifinnucastpkts;
279  u32_t ifindiscards;
280  u32_t ifoutoctets;
281  u32_t ifoutucastpkts;
282  u32_t ifoutnucastpkts;
283  u32_t ifoutdiscards;
284 #endif /* LWIP_SNMP */
285 #if LWIP_IGMP
286 
288  netif_igmp_mac_filter_fn igmp_mac_filter;
289 #endif /* LWIP_IGMP */
290 #if LWIP_NETIF_HWADDRHINT
291  u8_t *addr_hint;
292 #endif /* LWIP_NETIF_HWADDRHINT */
293 #if ENABLE_LOOPBACK
294  /* List of packets to be queued for ourselves. */
295  struct pbuf *loop_first;
296  struct pbuf *loop_last;
297 #if LWIP_LOOPBACK_MAX_PBUFS
298  u16_t loop_cnt_current;
299 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
300 #endif /* ENABLE_LOOPBACK */
301 
302  char d_ifname[6];
303 #if CONFIG_NSOCKET_DESCRIPTORS > 0
304  struct netif *flink;
305 #endif
306  struct ether_addr d_mac; /* Device MAC address */
307 
308  u16_t d_len;
309  u32_t d_flags;
310  uint32_t d_ipaddr; /* Host IPv4 address assigned to the network interface */
311  uint32_t d_draddr; /* Default router IP address */
312  uint32_t d_netmask; /* Network subnet mask */
313  /* Driver callbacks */
314  int (*d_ifup)(FAR struct netif *dev);
315  int (*d_ifdown)(FAR struct netif *dev);
316  int (*d_ifstate)(FAR struct netif *dev);
317  int (*d_txavail)(FAR struct netif *dev);
318  int (*d_txpoll)(FAR struct netif *dev);
319  /* Drivers may attached device-specific, private information */
320  void *d_private;
321 #ifdef CONFIG_NET_MULTIBUFFER
322  u8_t *d_buf;
323 #else
324  u8_t d_buf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
325 #endif
326 };
327 
328 #if LWIP_SNMP
329 #define NETIF_INIT_SNMP(netif, type, speed) \
330  /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
331  (netif)->link_type = (type); \
332  /* your link speed here (units: bits per second) */ \
333  (netif)->link_speed = (speed); \
334  (netif)->ts = 0; \
335  (netif)->ifinoctets = 0; \
336  (netif)->ifinucastpkts = 0; \
337  (netif)->ifinnucastpkts = 0; \
338  (netif)->ifindiscards = 0; \
339  (netif)->ifoutoctets = 0; \
340  (netif)->ifoutucastpkts = 0; \
341  (netif)->ifoutnucastpkts = 0; \
342  (netif)->ifoutdiscards = 0
343 #else /* LWIP_SNMP */
344 #define NETIF_INIT_SNMP(netif, type, speed)
345 #endif /* LWIP_SNMP */
346 
349 #if CONFIG_NSOCKET_DESCRIPTORS > 0
350 #ifdef CONFIG_NET_LWIP
351 EXTERN struct netif *g_netdevices;
352 #endif
353 #endif
354 
356 extern struct netif *netif_list;
358 extern struct netif *netif_default;
359 
363 void netif_init(void);
364 
365 struct netif *netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input);
366 void netif_register_with_initial_ip(struct netif *netif, netif_init_fn netif_init);
367 
385 void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw);
386 
388 void netif_remove(struct netif *netif);
390 
405 struct netif *netif_find(const char *name);
406 
408 
417 void netif_set_default(struct netif *netif);
418 
427 void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr);
428 
437 void netif_set_netmask(struct netif *netif, ip_addr_t *netmask);
438 
447 void netif_set_gw(struct netif *netif, ip_addr_t *gw);
448 
450 
459 void netif_set_up(struct netif *netif);
460 
469 void netif_set_down(struct netif *netif);
470 
472 
474 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
475 
476 #if LWIP_NETIF_STATUS_CALLBACK
477 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
478 #endif /* LWIP_NETIF_STATUS_CALLBACK */
479 #if LWIP_NETIF_REMOVE_CALLBACK
480 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
481 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
482 
483 void netif_set_link_up(struct netif *netif);
484 void netif_set_link_down(struct netif *netif);
486 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
487 
488 #if LWIP_NETIF_LINK_CALLBACK
489 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
490 #endif /* LWIP_NETIF_LINK_CALLBACK */
491 
492 #if LWIP_NETIF_HOSTNAME
493 #define netif_set_hostname(netif, name) \
494  do { \
495  if ((netif) != NULL) { \
496  (netif)->hostname = name; \
497  } \
498  } while (0)
499 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
500 #endif /* LWIP_NETIF_HOSTNAME */
501 
502 #if LWIP_IGMP
503 #define netif_set_igmp_mac_filter(netif, function) \
504  do { \
505  if ((netif) != NULL) { \
506  (netif)->igmp_mac_filter = function; \
507  } \
508  } while (0)
509 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
510 #endif /* LWIP_IGMP */
511 
512 #if ENABLE_LOOPBACK
513 err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *dest_ip);
514 void netif_poll(struct netif *netif);
515 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
516 void netif_poll_all(void);
517 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
518 #endif /* ENABLE_LOOPBACK */
519 
520 #if LWIP_NETIF_HWADDRHINT
521 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
522 #else /* LWIP_NETIF_HWADDRHINT */
523 #define NETIF_SET_HWADDRHINT(netif, hint)
524 #endif /* LWIP_NETIF_HWADDRHINT */
525 
526 #undef EXTERN
527 #ifdef __cplusplus
528 }
529 #endif
530 
531 #endif /* __LWIP_NETIF_H__ */
532 
err_t(* netif_igmp_mac_filter_fn)(struct netif *netif, ip_addr_t *group, u8_t action)
Definition: netif.h:187
u8_t flags
Definition: netif.h:263
uint32_t d_ipaddr
Definition: netif.h:310
void * d_private
Definition: netif.h:320
void * state
Definition: netif.h:239
uint32_t d_netmask
Definition: netif.h:312
uint32_t d_draddr
Definition: netif.h:311
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:261
netif_input_fn input
Definition: netif.h:214
struct netif * next
Definition: netif.h:205
u16_t mtu
Definition: netif.h:257
ip_addr_t gw
Definition: netif.h:210
#define MAX_NET_DEV_MTU
Definition: netif.h:69
u32_t d_flags
Definition: netif.h:309
char d_ifname[6]
Definition: netif.h:302
ip_addr_t ip_addr
Definition: netif.h:208
void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
Change IP address configuration for a network interface (including netmask and default gateway)...
char name[2]
Definition: netif.h:265
netif_linkoutput_fn linkoutput
Definition: netif.h:222
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:167
int(* d_ifstate)(FAR struct netif *dev)
Definition: netif.h:316
u8_t num
Definition: netif.h:267
void netif_set_down(struct netif *netif)
Bring an interface down, disabling any traffic processing.
void netif_set_up(struct netif *netif)
Bring an interface up, available for processing traffic.
Definition: netif.h:203
u8_t hwaddr_len
Definition: netif.h:259
struct netif * netif_list
struct dhcp * dhcp
Definition: netif.h:242
void(* netif_status_callback_fn)(struct netif *netif)
Definition: netif.h:185
u16_t d_len
Definition: netif.h:308
int(* d_txavail)(FAR struct netif *dev)
Definition: netif.h:317
ip_addr_t netmask
Definition: netif.h:209
int(* d_ifup)(FAR struct netif *dev)
Definition: netif.h:314
struct ether_addr d_mac
Definition: netif.h:306
err_t(* netif_output_fn)(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
Definition: netif.h:176
int(* d_txpoll)(FAR struct netif *dev)
Definition: netif.h:318
#define EXTERN
Definition: netif.h:111
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:160
struct netif * netif_default
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:119
netif_output_fn output
Definition: netif.h:218
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: netif.h:183
u8_t d_buf[MAX_NET_DEV_MTU+CONFIG_NET_GUARDSIZE]
Definition: netif.h:324
int(* d_ifdown)(FAR struct netif *dev)
Definition: netif.h:315
struct netif * netif_find(const char *name)
Find a network interface by searching for its name.