ESP8266
netif.h
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_NETIF_H__
33 #define __LWIP_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 #if LWIP_DHCP
46 struct dhcp;
47 #endif
48 #if LWIP_AUTOIP
49 struct autoip;
50 #endif
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /* Throughout this file, IP addresses are expected to be in
57  * the same byte order as in IP_PCB. */
58 
61 #define NETIF_MAX_HWADDR_LEN 6U
62 
69 #define NETIF_FLAG_UP 0x01U
70 
72 #define NETIF_FLAG_BROADCAST 0x02U
73 
75 #define NETIF_FLAG_POINTTOPOINT 0x04U
76 
78 #define NETIF_FLAG_DHCP 0x08U
79 
84 #define NETIF_FLAG_LINK_UP 0x10U
85 
88 #define NETIF_FLAG_ETHARP 0x20U
89 
92 #define NETIF_FLAG_ETHERNET 0x40U
93 
95 #define NETIF_FLAG_IGMP 0x80U
96 
102 typedef err_t (*netif_init_fn)(struct netif *netif);
109 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
118 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
119  ip_addr_t *ipaddr);
126 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
128 typedef void (*netif_status_callback_fn)(struct netif *netif);
130 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
131  ip_addr_t *group, u8_t action);
132 
136 struct netif {
138  struct netif *next;
139 
141  ip_addr_t ip_addr;
142  ip_addr_t netmask;
143  ip_addr_t gw;
144 
147  netif_input_fn input;
151  netif_output_fn output;
155  netif_linkoutput_fn linkoutput;
156 #if LWIP_NETIF_STATUS_CALLBACK
157 
159  netif_status_callback_fn status_callback;
160 #endif /* LWIP_NETIF_STATUS_CALLBACK */
161 #if LWIP_NETIF_LINK_CALLBACK
162 
164  netif_status_callback_fn link_callback;
165 #endif /* LWIP_NETIF_LINK_CALLBACK */
166 
168  void *state;
169 #if LWIP_DHCP
170 
171  struct dhcp *dhcp;
172 #endif /* LWIP_DHCP */
173 #if LWIP_AUTOIP
174 
175  struct autoip *autoip;
176 #endif
177 #if LWIP_NETIF_HOSTNAME
178  /* the hostname for this netif, NULL is a valid value */
179  char* hostname;
180 #endif /* LWIP_NETIF_HOSTNAME */
181 
182  u16_t mtu;
186  u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
188  u8_t flags;
190  char name[2];
192  u8_t num;
193 #if LWIP_SNMP
194 
195  u8_t link_type;
197  u32_t link_speed;
199  u32_t ts;
201  u32_t ifinoctets;
202  u32_t ifinucastpkts;
203  u32_t ifinnucastpkts;
204  u32_t ifindiscards;
205  u32_t ifoutoctets;
206  u32_t ifoutucastpkts;
207  u32_t ifoutnucastpkts;
208  u32_t ifoutdiscards;
209 #endif /* LWIP_SNMP */
210 #if LWIP_IGMP
211 
213  netif_igmp_mac_filter_fn igmp_mac_filter;
214 #endif /* LWIP_IGMP */
215 #if LWIP_NETIF_HWADDRHINT
216  u8_t *addr_hint;
217 #endif /* LWIP_NETIF_HWADDRHINT */
218 #if ENABLE_LOOPBACK
219  /* List of packets to be queued for ourselves. 指向发送给自己的数据包的pbuf*/
220  struct pbuf *loop_first;//第一个 struct pbuf *loop_last;//最后一个 #if LWIP_LOOPBACK_MAX_PBUFS u16_t loop_cnt_current; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ #endif /* ENABLE_LOOPBACK */ }; #if LWIP_SNMP #define NETIF_INIT_SNMP(netif, type, speed) \ /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \ (netif)->link_type = (type); \ /* your link speed here (units: bits per second) */ \ (netif)->link_speed = (speed); \ (netif)->ts = 0; \ (netif)->ifinoctets = 0; \ (netif)->ifinucastpkts = 0; \ (netif)->ifinnucastpkts = 0; \ (netif)->ifindiscards = 0; \ (netif)->ifoutoctets = 0; \ (netif)->ifoutucastpkts = 0; \ (netif)->ifoutnucastpkts = 0; \ (netif)->ifoutdiscards = 0 #else /* LWIP_SNMP */ #define NETIF_INIT_SNMP(netif, type, speed) #endif /* LWIP_SNMP */ /** The list of network interfaces. */ extern struct netif *netif_list; /** The default network interface. */ extern struct netif *netif_default; void netif_init(void)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)ICACHE_FLASH_ATTR; void netif_remove(struct netif * netif)ICACHE_FLASH_ATTR; /* Returns a network interface given its name. The name is of the form "et0", where the first two letters are the "name" field in the netif structure, and the digit is in the num field in the same structure. */ struct netif *netif_find(char *name)ICACHE_FLASH_ATTR; void netif_set_default(struct netif *netif)ICACHE_FLASH_ATTR; void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; void netif_set_netmask(struct netif *netif, ip_addr_t *netmask)ICACHE_FLASH_ATTR; void netif_set_gw(struct netif *netif, ip_addr_t *gw)ICACHE_FLASH_ATTR; void netif_set_up(struct netif *netif)ICACHE_FLASH_ATTR; void netif_set_down(struct netif *netif)ICACHE_FLASH_ATTR; /** Ask if an interface is up */ #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) #if LWIP_NETIF_STATUS_CALLBACK void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)ICACHE_FLASH_ATTR; #endif /* LWIP_NETIF_STATUS_CALLBACK */ void netif_set_link_up(struct netif *netif)ICACHE_FLASH_ATTR; void netif_set_link_down(struct netif *netif)ICACHE_FLASH_ATTR; /** Ask if a link is up */ #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) #if LWIP_NETIF_LINK_CALLBACK void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)ICACHE_FLASH_ATTR; #endif /* LWIP_NETIF_LINK_CALLBACK */ #if LWIP_NETIF_HOSTNAME #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) #endif /* LWIP_NETIF_HOSTNAME */ #if LWIP_IGMP #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) #endif /* LWIP_IGMP */ #if ENABLE_LOOPBACK err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *dest_ip)ICACHE_FLASH_ATTR; void netif_poll(struct netif *netif)ICACHE_FLASH_ATTR; #if !LWIP_NETIF_LOOPBACK_MULTITHREADING void netif_poll_all(void)ICACHE_FLASH_ATTR; #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ #endif /* ENABLE_LOOPBACK */ #ifdef __cplusplus } #endif #endif /* __LWIP_NETIF_H__ */
221  struct pbuf *loop_last;//最后一个#if LWIP_LOOPBACK_MAX_PBUFS u16_t loop_cnt_current; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ #endif /* ENABLE_LOOPBACK */ }; #if LWIP_SNMP #define NETIF_INIT_SNMP(netif, type, speed) \ /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \ (netif)->link_type = (type); \ /* your link speed here (units: bits per second) */ \ (netif)->link_speed = (speed); \ (netif)->ts = 0; \ (netif)->ifinoctets = 0; \ (netif)->ifinucastpkts = 0; \ (netif)->ifinnucastpkts = 0; \ (netif)->ifindiscards = 0; \ (netif)->ifoutoctets = 0; \ (netif)->ifoutucastpkts = 0; \ (netif)->ifoutnucastpkts = 0; \ (netif)->ifoutdiscards = 0 #else /* LWIP_SNMP */ #define NETIF_INIT_SNMP(netif, type, speed) #endif /* LWIP_SNMP */ /** The list of network interfaces. */ extern struct netif *netif_list; /** The default network interface. */ extern struct netif *netif_default; void netif_init(void)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)ICACHE_FLASH_ATTR; void netif_remove(struct netif * netif)ICACHE_FLASH_ATTR; /* Returns a network interface given its name. The name is of the form "et0", where the first two letters are the "name" field in the netif structure, and the digit is in the num field in the same structure. */ struct netif *netif_find(char *name)ICACHE_FLASH_ATTR; void netif_set_default(struct netif *netif)ICACHE_FLASH_ATTR; void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; void netif_set_netmask(struct netif *netif, ip_addr_t *netmask)ICACHE_FLASH_ATTR; void netif_set_gw(struct netif *netif, ip_addr_t *gw)ICACHE_FLASH_ATTR; void netif_set_up(struct netif *netif)ICACHE_FLASH_ATTR; void netif_set_down(struct netif *netif)ICACHE_FLASH_ATTR; /** Ask if an interface is up */ #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) #if LWIP_NETIF_STATUS_CALLBACK void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)ICACHE_FLASH_ATTR; #endif /* LWIP_NETIF_STATUS_CALLBACK */ void netif_set_link_up(struct netif *netif)ICACHE_FLASH_ATTR; void netif_set_link_down(struct netif *netif)ICACHE_FLASH_ATTR; /** Ask if a link is up */ #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) #if LWIP_NETIF_LINK_CALLBACK void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)ICACHE_FLASH_ATTR; #endif /* LWIP_NETIF_LINK_CALLBACK */ #if LWIP_NETIF_HOSTNAME #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) #endif /* LWIP_NETIF_HOSTNAME */ #if LWIP_IGMP #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) #endif /* LWIP_IGMP */ #if ENABLE_LOOPBACK err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *dest_ip)ICACHE_FLASH_ATTR; void netif_poll(struct netif *netif)ICACHE_FLASH_ATTR; #if !LWIP_NETIF_LOOPBACK_MULTITHREADING void netif_poll_all(void)ICACHE_FLASH_ATTR; #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ #endif /* ENABLE_LOOPBACK */ #ifdef __cplusplus } #endif #endif /* __LWIP_NETIF_H__ */
222 #if LWIP_LOOPBACK_MAX_PBUFS
223  u16_t loop_cnt_current;
224 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
225 #endif /* ENABLE_LOOPBACK */
226 };
227 
228 #if LWIP_SNMP
229 #define NETIF_INIT_SNMP(netif, type, speed) \
230  /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
231  (netif)->link_type = (type); \
232  /* your link speed here (units: bits per second) */ \
233  (netif)->link_speed = (speed); \
234  (netif)->ts = 0; \
235  (netif)->ifinoctets = 0; \
236  (netif)->ifinucastpkts = 0; \
237  (netif)->ifinnucastpkts = 0; \
238  (netif)->ifindiscards = 0; \
239  (netif)->ifoutoctets = 0; \
240  (netif)->ifoutucastpkts = 0; \
241  (netif)->ifoutnucastpkts = 0; \
242  (netif)->ifoutdiscards = 0
243 #else /* LWIP_SNMP */
244 #define NETIF_INIT_SNMP(netif, type, speed)
245 #endif /* LWIP_SNMP */
246 
247 
249 extern struct netif *netif_list;
251 extern struct netif *netif_default;
252 
253 void netif_init(void)ICACHE_FLASH_ATTR;
254 
255 struct netif *netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
256  ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)ICACHE_FLASH_ATTR;
257 
258 void
259 netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
260  ip_addr_t *gw)ICACHE_FLASH_ATTR;
261 void netif_remove(struct netif * netif)ICACHE_FLASH_ATTR;
262 
263 /* Returns a network interface given its name. The name is of the form
264  "et0", where the first two letters are the "name" field in the
265  netif structure, and the digit is in the num field in the same
266  structure. */
267 struct netif *netif_find(char *name)ICACHE_FLASH_ATTR;
268 
269 void netif_set_default(struct netif *netif)ICACHE_FLASH_ATTR;
270 
271 void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR;
272 void netif_set_netmask(struct netif *netif, ip_addr_t *netmask)ICACHE_FLASH_ATTR;
273 void netif_set_gw(struct netif *netif, ip_addr_t *gw)ICACHE_FLASH_ATTR;
274 
275 void netif_set_up(struct netif *netif)ICACHE_FLASH_ATTR;
276 void netif_set_down(struct netif *netif)ICACHE_FLASH_ATTR;
278 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
279 
280 #if LWIP_NETIF_STATUS_CALLBACK
281 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)ICACHE_FLASH_ATTR;
282 #endif /* LWIP_NETIF_STATUS_CALLBACK */
283 
284 void netif_set_link_up(struct netif *netif)ICACHE_FLASH_ATTR;
285 void netif_set_link_down(struct netif *netif)ICACHE_FLASH_ATTR;
287 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
288 
289 #if LWIP_NETIF_LINK_CALLBACK
290 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)ICACHE_FLASH_ATTR;
291 #endif /* LWIP_NETIF_LINK_CALLBACK */
292 
293 #if LWIP_NETIF_HOSTNAME
294 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
295 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
296 #endif /* LWIP_NETIF_HOSTNAME */
297 
298 #if LWIP_IGMP
299 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
300 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
301 #endif /* LWIP_IGMP */
302 
303 #if ENABLE_LOOPBACK
304 err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *dest_ip)ICACHE_FLASH_ATTR;
305 void netif_poll(struct netif *netif)ICACHE_FLASH_ATTR;
306 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
307 void netif_poll_all(void)ICACHE_FLASH_ATTR;
308 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
309 #endif /* ENABLE_LOOPBACK */
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif /* __LWIP_NETIF_H__ */
u8_t hwaddr[6U]
Definition: netif.h:186
netif_output_fn output
Definition: netif.h:151
u8_t num
Definition: netif.h:192
u8_t hwaddr_len
Definition: netif.h:184
ip_addr_t gw
Definition: netif.h:143
struct netif * next
Definition: netif.h:138
Definition: pbuf.h:76
u8_t flags
Definition: netif.h:188
Definition: netif.h:136
ip_addr_t ip_addr
Definition: netif.h:141
u16_t mtu
Definition: netif.h:182
void * state
Definition: netif.h:168
netif_input_fn input
Definition: netif.h:147
char name[2]
Definition: netif.h:190
ip_addr_t netmask
Definition: netif.h:142
netif_linkoutput_fn linkoutput
Definition: netif.h:155